Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4._1
  4. {
  5. //author: Benjamin Daniel Morgan
  6. //date: 11/01/18
  7.  
  8. class MealCosts
  9. {
  10. double dayCost, weekCost; // define all class variables (attributes)
  11. double foodCost, drinkCost;
  12. int daysPerweek; //number of days attending college
  13.  
  14.  
  15. static void Main(string[] args) // main program starts here
  16. {
  17. MealCosts myMeals = new MealCosts(); // create a new myMeals object
  18. myMeals.introduction();
  19. myMeals.getAmounts();
  20. myMeals.inputData(); // call object's inputData method
  21. myMeals.calcTotalCosts(); // call object's calcTotalCosts method
  22. myMeals.outputCosts(); // call object's outputCosts method
  23. }
  24. void introduction()
  25. {
  26. string name;
  27.  
  28. Console.WriteLine("Please Enter Your Name: ");
  29. name = Console.ReadLine();
  30. }
  31. void getAmounts()
  32. {
  33. string input;
  34. int amountOfMeals, amountOfDrinks;
  35.  
  36. Console.WriteLine("How many meals do you have in a day?");
  37.  
  38. input = Console.ReadLine();
  39. amountOfMeals = Convert.ToInt32(input);
  40.  
  41. Console.WriteLine("How many drinks do you have in a day?");
  42.  
  43. input = Console.ReadLine();
  44. amountOfDrinks = Convert.ToInt32(input);
  45.  
  46. }
  47. public void inputData() // method to input data from keyboard
  48. {
  49. string input; // local input variable
  50.  
  51. Console.Write("Enter the price of a meal: £");
  52.  
  53. input = Console.ReadLine();
  54. foodCost = Convert.ToDouble(input);
  55.  
  56. Console.Write("Enter the Price of a Drink: £");
  57.  
  58. input = Console.ReadLine();
  59. drinkCost = Convert.ToDouble(input);
  60.  
  61. Console.Write("Enter the number of days per week at college: ");
  62.  
  63. input = Console.ReadLine();
  64. daysPerweek = Convert.ToInt32(input);
  65. }
  66. void calcTotalCosts()
  67. {
  68. dayCost = foodCost + (amountOfDrinks * drinkCost);
  69. weekCost = dayCost * daysPerweek;
  70. }
  71. void outputCosts()
  72. {
  73. Console.WriteLine(name + "\nYour Final Costing Results");
  74. Console.WriteLine("============================");
  75. Console.WriteLine("Total cost for one day = £" + dayCost.ToString("0.00"));
  76. Console.WriteLine("Total cost for one week = £" + weekCost.ToString("0.00"));
  77. }
  78. } // end of MealCosts Class
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement