Computers and Technology, 02.03.2020 21:27, snikergrace
Create a Trip class. Include as data members destination, distance traveled, total cost of gasoline, and number of gallons consumed. Include appropriate constructors and properties. Add additional methods that calculates miles per gallon and the cost per mile. Override the ToString ( ) method. Create a second class to test your Trip class
This is what I have so far... I'm not sure if I'm using the appropriate constructors and properties per the instructions. Thanks.
class Program
{
static void Main(string[] args)
{
double totalMiles, totalGallons, pricePerGallon;
string destination
getInput(out destination, out totalMiles, out totalGallons, out pricePerGallon);
// Calculate results
double milesPerGal, costPerMile, totalTripCost;
milesPerGal = calculateMpg(totalMiles, totalGallons);
totalTripCost = calculateTrip(pricePerGallon, totalGallons);
costPerMile = calculateCost(totalTripCost, totalMiles);
// Print results
printOutput(milesPerGal, costPerMile);
Console. ReadLine();
}
//calculate miles per gallon, cost per mile, and total gas cost
static double calculateMpg(double totalMiles, double totalGallons)
{
double milesPerGal;
milesPerGal = totalMiles / totalGallons;
return milesPerGal;
}
static double calculateCost(double totalTripCost, double totalMiles)
{
double costPerMile;
costPerMile = totalTripCost / totalMiles;
return costPerMile;
}
static double calculateTrip(double pricePerGallon, double totalGallons)
{
double costPerMile;
costPerMile = pricePerGallon * totalGallons;
return costPerMile;
}
//accept input from user
static void getInput(out string dest, out double miles, out double gallons, out double unitPrice)
{
Console. Write("Enter destination: ");
destination = (Console. ReadLine());
Console. Write("Enter total miles traveled: ");
miles = double. Parse(Console. ReadLine());
Console. Write("Enter number of gallons of gas consumed: ");
gallons = Convert. ToDouble(Console. ReadLine());
Console. Write("Enter the gas price per gallon: ");
unitPrice = double. Parse(Console. ReadLine());
}
//print the calculated values
static void printOutput(double mpg, double cpm)
{
Console. WriteLine();
Console. WriteLine("Miles per Gallon: {0:F2}", mpg);
Console. WriteLine("Cost per mile: {0:C}", cpm);
Console. Read();
}
}
}
Answers: 3
Computers and Technology, 23.06.2019 23:00, minosmora01
How do you know if the website is secure if you make a purchase
Answers: 2
Computers and Technology, 24.06.2019 09:00, king514
Technician a says that a new replacement part is always good. technician b says that sometimes recent repair work will be the cause of a complaint. who is correct? a. both technicians a and b b. technician a c. technician b d. neither technician a nor b
Answers: 3
Computers and Technology, 24.06.2019 10:00, zlittleton2008
Which feature of a blog to restore and retrieve older post
Answers: 3
Create a Trip class. Include as data members destination, distance traveled, total cost of gasoline,...
Social Studies, 06.07.2019 06:10