1. Open the UMLTemplate.docx you downloaded previously and save it under the Documents folder.
2. The projects that you need ot complete are listed below. Read step by step instructions carefully!
- Complete the UML portion of the document for this exercise, including the method heading for each method.
- Create a row to identify which methods are the mutator methods and which methods are the accessor methods.
- Create a row to include the preconditions and postconditions for each method.
- There is no need to write the java test statements or implement the class.
- Page 367 (6th Edition: page 359): Ch. 5: Exercise Problem #7: MotorBoat
- Page 372 Ch. 5 Programming Project #3 (6th Edition, pae 362, #5): GradeDistribution
- Page 479 Ch. 6 Programming Project #7 (6th Edition, page 468: Ch. 6 Programming Project #10): Temperature
- Make sure to update the table of contents at the end.
MotorBoat
Consider a class MotorBoat that represents motorboats. A motorboat has attributes for
- The capacity of the fuel tank
- The amount of fuel in the tank
- The maximum speed of the boat
- The current speed of the boat
- The efficiency of the boat's motor
- The distance traveled
The class has method to
- Change the speed of the boat
- Operate the boat for an amount of time at the current speed
- Refuel the boat with some amount of fuel
- Return the amount of fuel in the tank
- Return the distance traveled so far
If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is e x s2 x t. The distance traveled in that time is s x t.
- Write a method heading for each method
- Write preconditions and postconditions for each method.
- Write some Java statements that test the class.
- Implement the class.
GradeDistribution
Create a class that represents a grade distribution for a given course. Write methods to perform the following tasks:
- Set the number of each of the letter grades A, B, C, D, and F.
- Read the number of each of the letter grades A, B, C, D, and F.
- Return the total number of grades.
- Return the percentage of each letter grade as a whole number between 0 and 100, inclusive.
- Draw a bar graph of the grade distribution.
The graph will have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row in proportionate to the percentage of grades in each category. Let one asterisk represent 2 percent, so 50 asterisks correspond to 100 percent. Mark the horizontal axis at 10 percent increments from 0 to 100 percent, and label each line with its letter grade.
For example, if the grades are 1 A, 4 Bs, 6 Cs, 2 Ds, and 1 F, the total number of grades is 14, the percentage of As is 7, the percentage of Bs is 29, the percentage of Cs is 43, the percentage of Ds is 14, and the percentage of Fs is 7. The A row would contain 4 asterisks (7 percent of 50 rounded to the nearest integer), the B row is 14, the C row 21, the D row 7, and the F row 4. The graph would look like this: see image.
Temperature
Write a Temperature class that reprsents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F' for Fahrenheit. The class should have
- Four constructors: one for the number of degrees, one for the scale, one for both the degrees and the scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified if no scale is given.
- Two accessor methods: one to return the temperature in degrees Celsius, the other to return it in degrees Fahrenheit. Use the formulas from Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree.
- Three set methods: one to set the number of degrees, one to set the scale, and one to set both.
- Three comparison methods: one to test whether two temperatures are equal, one to test whether one temperature is greater than another, and one to test whether one temperature is less than another.
Write a driver program that tests all the methods. Be sure to invoke each of the constructors, to include at least one true and one false case for each comparison method, and to test at least the following three temperature pairs for equality: 0.0 degrees C and 32.0 degrees F, -40.0 degrees C and -40.0 degrees F, and 100.0 degrees C and 212.0 degrees F.