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
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Modern Database Management
Starting Out With Visual Basic (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- Assignment2 Public Class name: wealth Write whole code inside main methodarrow_forwardPython In this assignment, a game called treasure hunt will be written object oriented.There are 3 types of treasures in the game. Diamond, Emerald and Gold. Diamond is 100 points, Emerald 70 points and Gold is 50 points.There are thieves in the game that will prevent you from hunting for treasure. Encountering a thief they steal some of your treasure. You will randomly generate which thief will steal from which treasure and how much.At the beginning of the game, the player has no treasure. X, Y, Z and H will be randomly identified at the start of the game. Define X Diamonds, a random number between X -> 100-200.Let a random number be defined between Y Emerald Y -> 100-200.Define a random number between Z Gold Z -> 100-200.You will define H thieves. Let it be defined between H -> 5-20. It will collect these randomly selected treasures to the player.For example:1- Diamond2-Emerald3-Diamond4-Gold5-Thief (k = treasure to steal, n = how many pieces he can steal)6-Gold.... In…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
- Description: The game is a single player scenario, in which the player’s army needs to defeat the enemy’s (AI’s) army. There are 4 possible troops for an army: Archers, Spearman, Cavaliers, Footman. Each troop has some attributes and some actions. And to avoid excessive programming and calculation, we want to treat these troops as squadrons. The player always starts with 10 squadrons of their choices: they can choose any combinations of the 4 possible troop types. Each squadron should have 100 members of that troop type. Each turn, the player is allowed to choose one of their squadrons and perform an action which is allowed by that troop type. Player and the AI take turns to make actions. The game continues until either the player or the AI has no troops left. Troop Types and Descriptions: Archers: should be able to attack from range with no casualties, meaning the attack action should not cause any damage to themselves. They should be pretty fragile to anything themselves. They…arrow_forward5. class definition for GameEnemy Next, we want to start making enemies for our upcoming video game, so we will define a class called GameEnemy. Every GameEnemy will have a name, an x location, a y location, and a number of hit points (which must be a non- negative integer ). The_init__ method for GameEnemy will take all of these parameters (in that order) and store them on the object. GameEnemy also needs a method called healthbar, which will allow us to show that enemy's health bar in the game. It returns the enemy's name followed by a number of asterisks to show how many hit points it has left. The exact format is shown below. Sample runs should look like: >>> enemy = GameEnemy ("TODD", 100, 200, 5) >>> enemy.healthbar() TODD: ****** >>> enemy-% ence 100 >>> enemy-y 200 If vou havo qu octionaarrow_forwardRainfall Type Create a RainFall class that keeps the total rainfall in an array of doubles for each of the 12 months. Methods in the programme should return the following values: • the total annual rainfall; • the average monthly rainfall • the wettest month of the year • the month with the least amount of rain Demonstrate the class in its entirety. Validation of Input: Accepting negative amounts for monthly rainfall data is not permitted.arrow_forward
- In this exercise, we are going to revist our Car and ElectricCar class from lesson 3. In lesson 3, you were given the Car class and needed to complete the ElectricCar class. You can use your code from that exercise to get started here. The focus of this exercise is the CarTester class. In this class, you will prompt the user for a car model and if the car is not electric, you will also prompt the user for the miles per gallon. For each car, you will add it to a single ArrayList. You will continue asking the user until they exit, then you will loop through your ArrayList and print the results. Remember, for a method call to compile, it needs to be defined in the reference type (the Car class in this exercise), but the actual method that executes will be based on the instantiated class. In this exercise, we want electric cars to run the Override methods. Sample Output Please enter a car model name(exit to quit): Tesla Is this car electric? (y or n) y Please enter a car model name(exit to…arrow_forwardIn this exercise, we are going to revist our Car and ElectricCar class from lesson 3. In lesson 3, you were given the Car class and needed to complete the ElectricCar class. You can use your code from that exercise to get started here. The focus of this exercise is the CarTester class. In this class, you will prompt the user for a car model and if the car is not electric, you will also prompt the user for the miles per gallon. For each car, you will add it to a single ArrayList. You will continue asking the user until they exit, then you will loop through your ArrayList and print the results. Remember, for a method call to compile, it needs to be defined in the reference type (the Car class in this exercise), but the actual method that executes will be based on the instantiated class. In this exercise, we want electric cars to run the Override methods. Sample Output Please enter a car model name(exit to quit): Tesla Is this car electric? (y or n) y Please enter a car model name(exit to…arrow_forwardAssignment - LocationsFor this assignment, we will be creating our location class and then a few locations to subclass from it. Most of these classes will be rather short so you can put them all in locations.py if you would likeCreate the Location classCreate the Town classCreate the Palace and Lumbermill classes Location ClassThe Location class establishes the basic properties of a location: manager - holds the character that manages the locationforeColor - holds the fore color of the locationbackColor - holds the back color of the locationEnter() - default method for entering a location. By default, the manager should greet you and all text displayed should use the foreColor and backColor of the location.Exit() - default method for leaving a location. By default, the manager should say bye to you and all text displayed should use the foreColor and backColor of the location.Upkeep() - default method that is called when time is advanced Town ClassThe Town class will inherit from the…arrow_forward
- Create a RightTriangle class given the following design: RightTriangle variables: base, height methods: 2 constructors, 1 that set default values and another that accepts to parameters. setBase - changes the base. Requires one parameter for base. setHeight - changes the height. Requires one parameter for height. getBase - returns the triangle base. getHeight - returns the triangle height. area - returns the area of the triangle (1/2bh) given the current base and heightarrow_forwardA(n)_ is a special kind of class that never uses any non-virtual methods. Please provide your comment in the spaces provided.arrow_forwardYou need a method to avoid accidental corruption of class fields.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT