Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _4._1
- {
- //author: Benjamin Daniel Morgan
- //date: 11/01/18
- class MealCosts
- {
- double dayCost, weekCost; // define all class variables (attributes)
- double foodCost, drinkCost;
- int daysPerweek; //number of days attending college
- static void Main(string[] args) // main program starts here
- {
- MealCosts myMeals = new MealCosts(); // create a new myMeals object
- myMeals.introduction();
- myMeals.getAmounts();
- myMeals.inputData(); // call object's inputData method
- myMeals.calcTotalCosts(); // call object's calcTotalCosts method
- myMeals.outputCosts(); // call object's outputCosts method
- }
- void introduction()
- {
- string name;
- Console.WriteLine("Please Enter Your Name: ");
- name = Console.ReadLine();
- }
- void getAmounts()
- {
- string input;
- int amountOfMeals, amountOfDrinks;
- Console.WriteLine("How many meals do you have in a day?");
- input = Console.ReadLine();
- amountOfMeals = Convert.ToInt32(input);
- Console.WriteLine("How many drinks do you have in a day?");
- input = Console.ReadLine();
- amountOfDrinks = Convert.ToInt32(input);
- }
- public void inputData() // method to input data from keyboard
- {
- string input; // local input variable
- Console.Write("Enter the price of a meal: £");
- input = Console.ReadLine();
- foodCost = Convert.ToDouble(input);
- Console.Write("Enter the Price of a Drink: £");
- input = Console.ReadLine();
- drinkCost = Convert.ToDouble(input);
- Console.Write("Enter the number of days per week at college: ");
- input = Console.ReadLine();
- daysPerweek = Convert.ToInt32(input);
- }
- void calcTotalCosts()
- {
- dayCost = foodCost + (amountOfDrinks * drinkCost);
- weekCost = dayCost * daysPerweek;
- }
- void outputCosts()
- {
- Console.WriteLine(name + "\nYour Final Costing Results");
- Console.WriteLine("============================");
- Console.WriteLine("Total cost for one day = £" + dayCost.ToString("0.00"));
- Console.WriteLine("Total cost for one week = £" + weekCost.ToString("0.00"));
- }
- } // end of MealCosts Class
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement