Question

C# Car Instrument Simulation (Updated Question) Car Instrument Simulator Design a set of classes that work...

C# Car Instrument Simulation (Updated Question)

Car Instrument Simulator 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 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 liters.

o To report the car’s current amount of fuel, in liters.

o To be able to increment the amount of fuel by 1 liter. This simulates putting fuel in the car. (The car can hold as maximum of 60 liters.)

o To be able to decrement the amount of fuel by 1 liter, if the amount of fuel is greater than 0 liters. This simulates burning fuel as the car runs.

• The Odometer Class: This class will simulate the car’s odometer. Its responsibilities are as follows:

o To know the car’s current kilometer.

o To report the car’s current kilometer.

o To be able to increment the kilometer by 1 kilometer. The maximum kilometer the odometer can store is 999 kilometers. When this amount is exceeded, the odometer resets the current kilometer to 0.

o To be able to work with a FuelGauge object. It should decrease the FuelGauge object’s current amount of fuel by 12 liters for every 100 kilometers traveled. (The car’s fuel economy is 12 liters per 100 kilometers).

Sample Output:

Add fuel:

Enter amount of fuel to add: 60

Drive:

Enter distance to drive: 400

Km: 1 Fuel: 59.88

Km: 2 Fuel: 59.76

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C# code

using System;

class FuelGauge
{
private double fuelAmount;
//Property
public double FuelAmount
{
get
{
return fuelAmount;
}
set
{
if(value<=60)
fuelAmount = value;
}
}
/**
* report the car’s current amount of fuel, in liters.
*/
public double currentAmount()
{
return fuelAmount;
}
/**
* To be able to increment the amount of fuel by 1 liter. This simulates
* putting fuel in the car. (The car can hold as maximum of 60 liters.)
*/
public void incementFuel()
{
if (fuelAmount < 60)
fuelAmount++;
}
/**
* o be able to decrement the amount of fuel by 1 liter, if the amount of fuel is greater than 0 liters.
* This simulates burning fuel as the car runs.
*/
public void decrementAmount()
{
if (fuelAmount > 0)
fuelAmount--;
}


}
class Odometer
{
private double km;
//Property
public double KM
{
get
{
return km;
}
set
{
if(value<=999)
km = value;
}
}
/**
* To be able to increment the kilometer by 1 kilometer. The maximum kilometer the odometer can store is 999 kilometers. When this
* amount is exceeded, the odometer resets the current kilometer to 0.
*/
public void incrementKilometer()
{
if (km < 999)
km++;
else
km = 0;
}
/**
* To be able to work with a FuelGauge object.
* It should decrease the FuelGauge object’s current
* amount of fuel by 12 liters for every 100 kilometers traveled.
* (The car’s fuel economy is 12 liters per 100 kilometers).
*/
public void drive(FuelGauge fuel)
{
double amount = (12.0 / 100.0);
for(int i=0;i<km;i++)
{
fuel.FuelAmount = fuel.FuelAmount - amount;
Console.WriteLine("Km: {0} Fuel: {1:0.00}",(i+1), fuel.FuelAmount);
}
}

}
class Program
{
static void Main(string[] args)
{
FuelGauge fuel = new FuelGauge();

Odometer odometer = new Odometer();   
  
Console.Write("Enter amount of fuel to add: ");
fuel.FuelAmount = double.Parse(Console.ReadLine());
Console.Write("Enter amount to drive: ");
odometer.KM = double.Parse(Console.ReadLine());
odometer.drive(fuel);
//Pause
Console.ReadLine();
}
}

//Output

//If you need any help regarding this solution....... please leave a comment........ thanks

Add a comment
Know the answer?
Add Answer to:
C# Car Instrument Simulation (Updated Question) Car Instrument Simulator Design a set of classes that work...
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
  • 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...

  • 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:...

  • 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....

  • Parking Ticket Simulator C++ HELP PLEASE

    For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should designare:• The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are:o To know the car’s make, model, color, license number, and the number of minutes that the car has been parked• The ParkingMeter Class: This class should simulate a parking meter. The class’s only responsibility is:o To know the number...

  • 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...

  • 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...

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