subject

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();
}
}
}

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 04:00, ittmanny6138
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
Answers: 3
image
Computers and Technology, 23.06.2019 14:30, Vanesssajohn2962
Norder to receive financial aid at his vocational school, mario must fill out the fafsa. the fafsa is a form that must be completed to determine . in order to complete a fafsa, you must submit . the fafsa can students obtain
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, taiyana74
Ramona enjoys her job because she is able to kids in an after school program. the work value ramona feels strongest about is a. leadership b. risk c. independence d. work with people select the best answer from the choices provided a b c d
Answers: 1
image
Computers and Technology, 24.06.2019 00:50, sequoyaburke
Which player type acts on other players? a. killer b. achiever c. explorer d. socializer
Answers: 1
You know the right answer?
Create a Trip class. Include as data members destination, distance traveled, total cost of gasoline,...

Questions in other subjects: