fork download
  1. using System;
  2.  
  3. namespace FoodItems
  4. {
  5. class Product
  6. {
  7. private string name;
  8. private double cost, tax, quant;
  9. private bool food;
  10.  
  11. public Product(string itemName, double itemCost, bool foodItem)
  12. {
  13. name = itemName;
  14. cost = itemCost;
  15. food = foodItem;
  16. }
  17.  
  18. public double CalculateProduct(double quantity)
  19. {
  20. quant = quantity;
  21.  
  22. if (food) {
  23. tax = 0.12;
  24. }
  25. else {
  26. tax = 0.25;
  27. }
  28.  
  29. double finalprice = cost * quant;
  30. finalprice = finalprice + (finalprice * tax);
  31. finalprice = Math.Round (finalprice, 2);
  32.  
  33. return finalprice;
  34. }
  35. }
  36.  
  37. class GroceryStore
  38. {
  39. public static void Main (string[] args)
  40. {
  41. bool productFood;
  42.  
  43. Console.Write ("Enter the product name: ");
  44. string productName = Console.ReadLine ();
  45.  
  46. Console.Write ("Net unit price: ");
  47. string userInput = Console.ReadLine ();
  48. double productPrice = Convert.ToDouble (userInput);
  49.  
  50. Console.Write ("Food item (y/n): ");
  51. string boolRead = Console.ReadLine ();
  52.  
  53. if (boolRead == "y")
  54. {
  55. productFood = true;
  56. }
  57. else {
  58. productFood = false;
  59. }
  60.  
  61. Console.Write ("Quantity: ");
  62. userInput = Console.ReadLine();
  63. double quantity = Convert.ToDouble (userInput);
  64.  
  65. Product Apple = new Product (productName, productPrice, productFood);
  66. double price = Apple.CalculateProduct (quantity);
  67.  
  68. Console.WriteLine ("Price: {0}", price);
  69. Console.Read ();
  70. }
  71. }
  72. }
  73.  
Success #stdin #stdout 0.04s 33952KB
stdin
Standard input is empty
stdout
Enter the product name: Net unit price: Food item (y/n): Quantity: Price: 0