Here is the Morning class's sample code for methods. It is a little different from the evening class. I did not comment it nearly as thoroughly
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Methods
{
class Program
{
static void Main(string[] args)
{
Program prog = new Program();
prog.Display();
prog.PauseIt();
}//end of Main
private void PauseIt()
{
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}//end of PauseIt
private void Display()
{
Console.WriteLine("Enter the beginning mileage");
double beginningMileage = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the ending mileage");
double endingMileage = double.Parse(Console.ReadLine());
double miles = TotalMiles(beginningMileage, endingMileage);
Console.WriteLine("\nYour total miles is {0}",miles);
Console.WriteLine("Enter the number of Gallons");
double gallons=double.Parse(Console.ReadLine());
double milesPerGal = MilesPerGallon(miles, gallons);
Console.WriteLine("Your miles per gallon is {0}", milesPerGal);
}//end Display
private double TotalMiles(double startMiles, double endMiles )
{
return endMiles - startMiles;
}//Total Miles
private double MilesPerGallon(double totalMiles, double gals)
{
double mpg = totalMiles / gals;
return mpg;
}//end MilesPerGallon
}//end of program class
}//end of namespace
No comments:
Post a Comment