Question
AutomobileTester.java /** A class to test the Automobile class. */ public class AutomobileTester { /** Tests the methods of the Automobile class. @param args not
AutomobileTester.java
/**
A class to test the Automobile class.
*/
public class AutomobileTester
{
/**
Tests the methods of the Automobile class.
@param args not used
*/
public static void main(String[] args)
{
Automobile myHybrid = new Automobile(15);
myHybrid.addGas(20);
myHybrid.drive(150);
System.out.printf("%.2f\n", myHybrid.getGasInTank());
System.out.println("Expected:");
System.out.println("10.00");
//More driving and fueling
System.out.println("After more driving and fueling:");
myHybrid.addGas(50);
myHybrid.drive(69);
myHybrid.drive(49);
System.out.printf("%.2f\n", myHybrid.getGasInTank());
System.out.println("Expected:");
System.out.println("52.13");
}
}
Automobile.java
/**
A automobile has a fuel level and an efficiency
P3.7.
Modify the given class Automobile so that it has the following properties. An
automobile has a certain fuel efficiency (measured in km/liters) and a certain
amount of fuel in the gas tank. The efficiency is initialized in the
constructor method via the parameter, and the initial fuel level is 0. Supply a method called drive
that simulates driving the automobile for a certain distance, reducing the
amount of gasoline in the fuel tank. Also supply methods getGasInTank,
returning the current amount of gasoline in the fuel tank, and addGas,
to add gasoline to the fuel tank.
Look at the tester code (AutomobileTester.java) for help in understanding these methods
Difficulty: Easy
*/
public class Automobile
{
private double efficiency ; // kilometers per liter
private double fuel ; // amount of gas in the tank
/**
Initialize inastance variables zero fuel and the given efficiency kmPerLiter
@param kmPerLiter
*/
public Automobile(double kmPerLiter)
{
//-----------Start below here. To do: approximate lines of code = 2
// set the instance variable fuel to zero;
//2. set efficiency to the parameter value
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Drives the automobile the given distance
@param distance
*/
public void drive(double distance)
{
//-----------Start below here. To do: approximate lines of code = 2
// 1. calculate the gas used in going that distance
// i.e. divide distance by efficiency, update fuel accordingly
//2. update the fuel instance variable (fule should decrease)
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Puts fuel in the automobile.
@param amount the amount of gas added
*/
public void addGas(double amount)
{
//-----------Start below here. To do: approximate lines of code = 1
// update the fuel variable
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Gets the current fuel level of the automobile.
@return the current fuel level
*/
public double getGasInTank()
{
//-----------Start below here. To do: approximate lines of code = 1
// return the current fuel level
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}
P.S: Please include screenshot of the output, make sure all is working well
Modify the given class Automobile so that it has the following properties. A car has a certain fuel efficiency (measured in km/liters and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive (distance) that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank. Also supply methods getGasInTank, returning the current amount of gasoline in the fuel tank, and addGas, to add gasoline to the fuel tank. Sample usage: Automobile myHybrid myHybrid.addGas (20) ; // add to tank 20 liters myHybrid.drive (100); // Drive 100 kilometers double gasLeft new Automobile (15); // 15 km per liter myHybrid.getGasInTank () ; // Get gas remaining in tank You may assume that the drive method is never called with a distance that consumes more than the available gas. A AutomobileTester class is supplied that tests all methods. Difficulty: Easy See the following files: * AutomobileTester.java * Automobile.java (has todo) Approximate total lines of code reguired: 6 Modify the given class Automobile so that it has the following properties. A car has a certain fuel efficiency (measured in km/liters and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive (distance) that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank. Also supply methods getGasInTank, returning the current amount of gasoline in the fuel tank, and addGas, to add gasoline to the fuel tank. Sample usage: Automobile myHybrid myHybrid.addGas (20) ; // add to tank 20 liters myHybrid.drive (100); // Drive 100 kilometers double gasLeft new Automobile (15); // 15 km per liter myHybrid.getGasInTank () ; // Get gas remaining in tank You may assume that the drive method is never called with a distance that consumes more than the available gas. A AutomobileTester class is supplied that tests all methods. Difficulty: Easy See the following files: * AutomobileTester.java * Automobile.java (has todo) Approximate total lines of code reguired: 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
AutomobileTesterjava A class to test the Automobile class public class AutomobileTester Tests the methodsof the Automobileclass param args not used pu...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started