Question

For this assignment, you will design tow classes that work together to simulate a car's fuel...

For this assignment, you will design tow classes that work together to simulate a car's fuel gauge and odometer. The classes you will design are the following:

1. The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are:

To know the car's current amount of fuel, in gallons.
To report the car's current amount of fuel, in gallons.
To be able to increment the amount of fuel by one gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons).
To be able decrement the amount of fuel by one gallon, if the amount of fuel is greater than zero gallons. This simulates burning fuel when the car's engine is running.
2. The Odometer Class: This class will simulate the car's odometer. Its responsibilities are:

To know the car's current mileage.
To report the car's current mileage.
To be able to increment the current mileage by one mile. the maximum mileage on the odometer is 99,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0.
To be able to work with the a FuelGauge object. It should decrease the FuelGauage object's current amount of fuel by one gallon for every 24 miles the car has traveled. (This addresses the car's fuel economy is 24 miles per gallon).
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and then run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print out the car's mileage and amount of fuel.

Sample Output:

.

.

.

Mileage: 310
Fuel level: 3 gallons
------------------------------
Mileage: 311
Fuel level: 3 gallons
------------------------------
Mileage: 312
Fuel level: 2 gallons
------------------------------
Mileage: 313
Fuel level: 2 gallons
------------------------------
Mileage: 314
Fuel level: 2 gallons
------------------------------
Mileage: 315
Fuel level: 2 gallons
------------------------------
Mileage: 316
Fuel level: 2 gallons
------------------------------
Mileage: 317
Fuel level: 2 gallons
------------------------------
Mileage: 318
Fuel level: 2 gallons
------------------------------
Mileage: 319
Fuel level: 2 gallons
------------------------------
Mileage: 320
Fuel level: 2 gallons
------------------------------
Mileage: 321
Fuel level: 2 gallons
------------------------------
Mileage: 322
Fuel level: 2 gallons
------------------------------
Mileage: 323
Fuel level: 2 gallons
------------------------------
Mileage: 324
Fuel level: 2 gallons
------------------------------
Mileage: 325
Fuel level: 2 gallons
------------------------------
Mileage: 326
Fuel level: 2 gallons
------------------------------
Mileage: 327
Fuel level: 2 gallons
------------------------------
Mileage: 328
Fuel level: 2 gallons
------------------------------
Mileage: 329
Fuel level: 2 gallons
------------------------------
Mileage: 330
Fuel level: 2 gallons
------------------------------
Mileage: 331
Fuel level: 2 gallons
------------------------------
Mileage: 332
Fuel level: 2 gallons
------------------------------
Mileage: 333
Fuel level: 2 gallons
------------------------------
Mileage: 334
Fuel level: 2 gallons
------------------------------
Mileage: 335
Fuel level: 2 gallons
------------------------------
Mileage: 336
Fuel level: 1 gallons
------------------------------
Mileage: 337
Fuel level: 1 gallons
------------------------------
Mileage: 338
Fuel level: 1 gallons
------------------------------
Mileage: 339
Fuel level: 1 gallons
------------------------------
Mileage: 340
Fuel level: 1 gallons
------------------------------
Mileage: 341
Fuel level: 1 gallons
------------------------------
Mileage: 342
Fuel level: 1 gallons
------------------------------
Mileage: 343
Fuel level: 1 gallons
------------------------------
Mileage: 344
Fuel level: 1 gallons
------------------------------
Mileage: 345
Fuel level: 1 gallons
------------------------------
Mileage: 346
Fuel level: 1 gallons
------------------------------
Mileage: 347
Fuel level: 1 gallons
------------------------------
Mileage: 348
Fuel level: 1 gallons
------------------------------
Mileage: 349
Fuel level: 1 gallons
------------------------------
Mileage: 350
Fuel level: 1 gallons
------------------------------
Mileage: 351
Fuel level: 1 gallons
------------------------------
Mileage: 352
Fuel level: 1 gallons
------------------------------
Mileage: 353
Fuel level: 1 gallons
------------------------------
Mileage: 354
Fuel level: 1 gallons
------------------------------
Mileage: 355
Fuel level: 1 gallons
------------------------------
Mileage: 356
Fuel level: 1 gallons
------------------------------
Mileage: 357
Fuel level: 1 gallons
------------------------------
Mileage: 358
Fuel level: 1 gallons
------------------------------
Mileage: 359
Fuel level: 1 gallons
------------------------------
Mileage: 360
Fuel level: 0 gallons
------------------------------
Press any key to continue . . .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

class FuelGauge {
   int putFuel()
   {
       int currentFuel = 4;
       currentFuel = currentFuel + 1 ;
       if(currentFuel <= 15)
       {
           //System.out.println("car's current amount of fuel :" + currentFuel + " gallons");
           return currentFuel;
       }
       else
       {
           System.out.println("Maximum Fuel");
           return 0;
       }
      
   }
   int reduceFuel(int currentBurnFuel)
   {
       if(currentBurnFuel < 0)
       {
           System.out.println("No Fuel");
           return 0;
       }
       else
       {
           int burn = currentBurnFuel;
           burn = burn - 1;
           return burn;
       }
   }  
}
public class Odometer extends FuelGauge
{
   int incrementMileage(int mileage)
   {
       int currentMileage = 300;
       currentMileage = currentMileage + mileage ;
       if(currentMileage <= 99999 && currentMileage > 0)
       {
           //System.out.println("car's current Mileage is :" + currentMileage);
           return currentMileage;
       }
       else
       {
           currentMileage = 0;
           //System.out.println("car's current Mileage is :" + currentMileage);
           return currentMileage;
       }
      
   }
   public static void main(String args[])
   {
       int CurrentFuel = 5;
       FuelGauge fg = new FuelGauge();
       Odometer od = new Odometer();
       int FuelLevel = od.reduceFuel(CurrentFuel);
       for (int j=0; j<=50; j++) // instead of 50 maintain it 99999
       {
           System.out.println("Mileage: "+od.incrementMileage(j));
           if((j%24)==0)
           {
               System.out.println("Fuel Leval: "+FuelLevel+" gallons");
           }
           else
           {
               System.out.println("Fuel Leval: "+FuelLevel+" gallons");
           }
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
For this assignment, you will design tow classes that work together to simulate a car's fuel...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 4 Due Mar 22 by 11:59pmPoints 100 Submitting a file upload A4 OOP 2 "Car...

    Assignment 4 Due Mar 22 by 11:59pmPoints 100 Submitting a file upload A4 OOP 2 "Car Instrument Simulator" Access A4 from pdf assignment file & Turn in the following files: a4main.java FuelGauge.java Odometer.java program compile and run screenshots design document (including UML) A4 10. Car Instrument Simulator For this assignment, you will design a set of classes that work together to simulate a car's fuel gauge and odometer. The classes you will design are the following: · The Pue|Gauge Class:...

  • Car Instrument Simulator

    Car Instrument SimulatorFor this assignment, you will design a set of classes that work together to simulate a car’s fuel gauge andodometer. The classes you will design are the following: The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows:o To know the car's current amount of fuel, in gallons.o To report the car s current amount of fuel, in gallons.o To be able to increment the amount of fuel by I gallon. This simulates...

  • The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you w...

    The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are: • The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are – To know the car’s current amount of fuel, in gallons. – To report the car’s current amount of fuel, in gallons. – To...

  • Design a set of classes that work together to simulate the Stock Transaction System. You should...

    Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows:    -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...

  • In JAVA In this assignment you will use a class Car to represent a car that travels to various de...

    In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...

  • need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...

    need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...

  • using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...

    using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checking a parked car issuing a parking ticket if there is a parking violation. Here are the classes that need to collaborate: • The ParkedCar class: This class should simulate a parked car. The car has a make, model, color, license number. •The ParkingMeter class: This class should simulate a parking meter. The class has three parameters: − A 5-digit...

  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • By Python 3 please 2. (a) Implement a class Student. For the purpose of this exercise,...

    By Python 3 please 2. (a) Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods get Name, addQuiz(score), getTotalScore(), and getAverageScore(). To compute the latter, you also need to store the number of quizzes that the student took. (b) Modify the Student class to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify grades as...

  • python code DC Final Project Implement a class Car with the following properties. A car has...

    python code DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT