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 Fuel Gauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows:
- 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 1 gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons.)
- To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons. This simulates burning fuel as the car runs.
- The Odometer Class: This class will simulate the car’s odometer. Its responsibilities are as follows:
- To know the car’s current mileage.
- To report the car’s current mileage.
- To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store is 999,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0.
- To be able to work with a FuelGauge object. It should decrease the FuelGauge object’s current amount of fuel by 1 gallon for every 24 miles traveled. (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 the car’s current mileage and amount of fuel.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
C++ How to Program (10th Edition)
Java How To Program (Early Objects)
- Parking Ticket SimulatorFor this assignment you will design a set of classes that work together to simulate apolice officer issuing a parking ticket. The classes you should design are:• The Parkedcar Class: This class should simulate a parked car. The class's respon-sibilities are:To know the car's make, model, color, license number, and the number of min-utes that the car has been parkedThe BarkingMeter Class: This class should simulate a parking meter. The class'sonly responsibility is:- To know the number of minutes of parking time that has been purchased• The ParkingTicket Class: This class should simulate a parking ticket. The class'sresponsibilities areTo report the make, model, color, and license number of the illegally parked carTo report the amount of the fine, which is $2S for the first hour or part of anhour that the car is illegally parked, plus $10 for every additional hour or part ofan hour that the car is illegally parkedTo report the name and badge number of the police…arrow_forwardAssignment 10: Chapter 10 Complete Programming Challenge 10 at the end of chapter 10 10. Ship, CruiseShip, and CargoShip Classes Design a Ship class that the following members: A field for the name of the ship (a string) - A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. A toString method that displays the ship's name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). A constructor and appropriate accessors and mutators. A toString method that overrides the toString method in the base class. The CruiseShip class's toString method should display only the ship's name and the maximum number of passengers. Design a CargoShip class that extends the Ship class. The CargoShip class should have the following members: A field for the cargo capacity in tonnage (an int). A constructor and…arrow_forwardExercise 6 - Loaded Coin Simulation Make a new class in the Lab2 project called LoadedCoinSim that simulates the toss of a loaded coin. A coin is loaded when it is constructed such that it is more likely to land on one value than another. Assume the probability the coin will land head is HEAD_PROB, and declare that as a constant in your program. Initially, use a value of 0.75, which means 75% chance the coin will show heads. Given this probability, simulate ten coin tosses and displaying the result. At the end, display the number of times the coin showed heads. The output should appear like this: Toss 1: HEADS Toss 2: HEADS Toss 3: HEADS Toss 4: TAILS Toss 5: HEADS Toss 6: HEADS Toss 7: HEADS Toss 8: HEADS Toss 9: TAILS Toss 10: HEADS Number of heads = 8arrow_forward
- Assignment2 Public Class name: wealth Write whole code inside main methodarrow_forwardJava Assignment Outcomes: Student will demonstrate the ability to utilize inheritance in a Java program. Student will demonstrate the ability to apply the IS A and HAS A relationships. Program Specifications: Start by watching Video Segment 16 from Dr. Colin Archibald's video series (found in the module overview). Key in the program shown in the video and make sure it works. Then, add the following: Animals have a Weight. Animals have a Height. Dog is an Animal. Dogs have a Name. Dogs have a Breed. Dogs have a DOB. Cat is an Animal Cats have a Name. Cats have 9 lives, so you need to keep track of the remaining lives once a cat dies. Bird is an Animal Birds have a wing span Birds have a canFly which is true or false (some birds cannot fly) Create a test class that creates one of each type of animal and displays the animal’s toString method. Submission Requirements: You must follow the rules from the prior assignments. UMLs and Design Tools are not required for this one. YOU MAY…arrow_forwardCode the StudentAccount class according to the class diagramMethods explanation:pay(double): doubleThis method is called when a student pays an amount towards outstanding fees. The balance isreduced by the amount received. The updated balance is returned by the method.addFees(double): doubleThis method is called to increase the balance by the amount received as a parameter. The updatedbalance is returned by the method.refund(): voidThis method is called when any monies owned to the student is paid out. This method can onlyrefund a student if the balance is negative. It displays the amount to be refunded and set thebalance to zero. (Use Math.abs(double) in your output message). If there is no refund, display anappropriate message.Test your StudentAccount class by creating objects and calling the methods addFees(), pay() andrefund(). Use toString() to display the object’s data after each method calledarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT