Question

In: Computer Science

1. Define a class called Odometer that will be used to track fuel and mileage for...

1. Define a class called Odometer that will be used to track fuel and mileage for an automobile. The class should have instance variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer’s total, and an accessor method that returns the number of gallons of gasoline that the vehicle has consumed since the odometer was last reset.

Use your class with a test program that creates several trips with different fuel efficiencies. You should decide which variables should be public, if any.

2. Write a grading program for a class with the following grading policies:

  1. There are three quizzes, each graded on the basis of 10 points.

  2. There is one miterm exm, graded on the basis of 100 points.

  3. There is one finl exm, graded on the basis of 100 points.

The fnal exm counts for 40% of the grade. The miterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade. (Do not forget to convert the quiz scores to percentages before they are averaged in.)

Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program should read in the student’s scores and output the student’s record, which consists of three quiz scores and two exm scores, as well as the student’s overall numeric score for the entire course and final letter grade.

Define and use a class for the student record. The class should have instance variables for the quizzes, midterm, final, overall numeric score for the course, and final letter grade. The overall numeric score is a number in the range 0 to 100, which represents the weighted average of the student’s work. The class should have methods to compute the overall numeric grade and the final letter grade. These last methods should be void methods that set the appropriate instance variables. Your class should have a reasonable set of accessor and mutator methods, an equals method, and a toString method, whether or not your program uses them. You may add other methods if you wish.

3. Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degrees if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two accessor methods to return the temperature—one to return the degrees Celsius, the other to return the degrees Fahrenheit—use the following formulas to write the two methods, and round to the nearest tenth of a degree:

DegreesC=5(degreesF−32)/9DegreesF=(9(degreesC)/5+32);

DegreesC=5(degreesF−32)/9DegreesF=(9(degreesC)/5+32);

(2) three mutator methods: one to set the value, one to set the scale (F or C), and one to set both; (3) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas); and (4) a suitable toString method. Then write a driver program (or programs) that tests all the methods. Be sure to use each of the constructors, to include at least one true and one false case for each of the comparison methods, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, –40.0 degrees C = –40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.

Solutions

Expert Solution

//Odometer
package pkg3;


public class Odometer {
private double oldmiles ,tmilesdriven, tmilage, gallons;
  
public Odometer(double miles,double average){
oldmiles = miles;
tmilesdriven = miles;
tmilage = average;
  
}
  
public double addmiles (double newmiles){
tmilesdriven = 0;
tmilesdriven = newmiles;
return setaverage(tmilesdriven);
}
  
public double reset(){
  
tmilesdriven = 0;
return addmiles(tmilesdriven);
}
  
public double setaverage(double newtrip){
  
gallons = (newtrip / tmilage);
return gallons;
}
  
public String toString(){
  
return "NUMBER OF GALLONS USED ON " + tmilesdriven + " miles trip = " + gallons + "\nTOTAL MILES AFTER TRIP: " + (oldmiles+tmilesdriven);
}
  
}

//MAIN class

package pkg3;


public class Main {

  
public static void main(String[] args) {
Odometer o1 = new Odometer(53.7, 32.1);
Odometer o2 = new Odometer(42.9, 15.4);
Odometer o3 = new Odometer(220, 27);
Odometer o4 = new Odometer(672.78, 36);
Odometer o5 = new Odometer(430.9, 27);
  
o1.addmiles(61.7);
o2.addmiles(404.45);
o3.addmiles(3);
o4.addmiles(224);
o5.addmiles(78);
  
System.out.println(o1);
System.out.println(o2);
System.out.println(o3);
System.out.println(o4);
System.out.println(o5);
  
}
}


Related Solutions

***Define a class called Pizza that has member variables to track the type of pizza (either...
***Define a class called Pizza that has member variables to track the type of pizza (either deep dish, hand tossed, or pan) along with the size (either small, medium, or large) and the number of pepperoni or cheese toppings. You can use constants to represent the type and size. Include mutator and accessor functions for your class. Create a void function, outputDescription( ) , that outputs a textual description of the pizza object. Also include a function, computePrice( ) ,...
The following data give the odometer mileage (rounded to the nearest thousand miles) for all 20...
The following data give the odometer mileage (rounded to the nearest thousand miles) for all 20 cars that are for sale at a dealership. 61 88 58 83 71 40 27 38 52 43 27 40 90 43 95 35 28 47 88 76 a. Calculate the values of the three quartiles and the interquartile range. Q1 = Q2 = Q3 = IQR = b. Find the approximate value of the 19th percentile. c. Calculate the percentile rank of 71....
Write a class called Animal that contains a static variable called count to keep track of...
Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Using Python 3, Write a class called GolfScore that keeps track of the score for a...
Using Python 3, Write a class called GolfScore that keeps track of the score for a person playing a round of golf. We will limit the round to 9 holes, just to make testing easier. As a reminder, the holes on the golf course are numbered 1 – 9. Create a class level variable named NUM_OF_HOLES set to 9. Methods to be written: The constructor – sets the score for all holes to -1 addScore (hole, score) – this method...
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
Collect Customer Data - Part 2 Collect Mileage information: Prompt: "Starting Odometer Reading:\n" Variable: odoStart =...
Collect Customer Data - Part 2 Collect Mileage information: Prompt: "Starting Odometer Reading:\n" Variable: odoStart = ? Prompt: "Ending Odometer Reading:\n" Variable: odoEnd = ? Add code to PRINT odoStart and odoEnd variables as well as the totalMiles to check your work. The following data will be used as input in the test: Prompt the user to input the starting odometer reading (expect type int from the user) Prompt the user to input the ending odometer reading (expect type int...
Define a class called Goals that has the following requirements in c++: a function called set...
Define a class called Goals that has the following requirements in c++: a function called set that takes 3 int parameters that are goals for "fame", "happiness" and "money". The function returns true and saves the values if they add up to exactly 60, and returns false otherwise (you may assume the parameters are not negative) a functions satisfies that takes 3 int parameters and returns true if each parameter is at least as large as the saved goal, false...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month,...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month, day and year.  You can do simple things like checking if it is your birthday, advancing to the next day, checking if a given date is valid and checking if it is a leap year. Class Fields/Instance Variables Provide appropriate names and data types for each of the private instance variables: the month, day and year (int) two final integers that represent YOUR birthday (month...
A consumer agency claims that the average fuel mileage of Sedan A exceeds that of Sedan...
A consumer agency claims that the average fuel mileage of Sedan A exceeds that of Sedan B. To test this claim, a random sample of 17 Sedan A vehicles were tested and the sample mean fuel mileage was found to be 28.25 miles per gallon with a known population standard deviation of 1.30 miles per gallon. A random sample of 14 Sedan B vehicles also were tested and the sample mean fuel mileage was found to be 27.25 miles per...
Define a class called Counter whose internal "count" variable is a basic integer counter. This class...
Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include an accessor method that returns the current count value (getCount()). There should be no input /...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT