Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class named Car with these properties: - A car has a specific fuel efficiency (in miles/gallon) - A car has a certain amount
Write a class named Car with these properties: - A car has a specific fuel efficiency (in miles/gallon) - A car has a certain amount of fuel in its tank (gallons) - A car has a certain number of passengers - Define a constructor that takes two arguments: the efficiency and initial fuel level. - The constructor should also initialize passengers to 0 - Supply these 5 methods: - drive - simulates driving for a certain distance and reduces the fuel level accordingly - getGasLevel - returns the current amount of gallons in the fuel tank - addGas - adds gas to the fuel tank - setPassengers - sets the number of passengers the car can carry - getPassengers - returns the number of passengers the car can carry - Assume that drive is never given a distance that would run the tank empty Write a CarTester.java program that tests all the methods above. Here is a sample (incomplete) test: Car myHybrid = new Car(50,20);//50 miles per gallon, 20 gallons in the tank myHybrid.addGas (20);// Adds 20 gallons of gas to the tank double gasLeft = myHybrid.getGasLevel () ; // Gets gas remaining in tank
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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