Suppose that you are given the following Driver class, which includes a main met
ID: 3600679 • Letter: S
Question
Suppose that you are given the following Driver class, which includes a main method: public class Driver public static void main(Stringt args) double distance = 400.48; double fuel -21.4 AutoTrip myTrip = new AutoTrip(distance, fuel); system.out.print("My car traveled myTrip.getDistance)miles ") System.out.println("on "myTrip.getFuel)+" gallons of gasoline.")i double mileage = myTrip.getMPG( ); // get miles per gallon System.out.printin("My mileage was"mileage "."); Now suppose that executing main produces the following output: My car traveled 400.48 miles on 21.4 gallons of gasoline. My mileage was 18.714018691588787 Implement the AutoTrip class so that it produces the indicated output. public class Auto Trip (Explanation / Answer
Hi,
1. Pet Class:
public class Pet {
private String name;
private double weight;
Pet()
{
}
Pet(String name1, double weight1)
{
name=name1;
weight=weight1;
}
// Getters and setters for the class
public double getWeight() {
return weight;
}
public String getName() {
return name;
}
public void setWeight( double newWeight) {
weight= newWeight;
}
public void setName(String newName) {
name = newName;
}
}
2. AutoTrip class:
public class AutoTrip {
private double fuel;
private double distance;
AutoTrip()
{
}
AutoTrip(double fuel1, double distance1)
{
fuel=fuel1;
distance=distance1;
}
// Getters and setters for the class
public double getFuel() {
return fuel;
}
public double getDistance() {
return distance;
}
public void setFuel( double newFuel) {
fuel=newFuel;
}
public void setName(double newDist) {
distance=newDist;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.