Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

1. Define mass and mediated communication

Answered: 1 week ago