You are on page 1of 4

Official (Closed) - Non Sensitive

PS11-12 Hoh Jungi

1 PT1-ReTest
2
3
4 Screen-Capture(s)
5

6
7
8
9 Filename: Program.cs
10
11 using System;
12 using System.Collections.Generic;

LastSaved 20230119T1206 page 1 of 4 (Leave this footer alone!)


Official (Closed) - Non Sensitive
PS11-12 Hoh Jungi

1 using System.Linq;
2 using System.Text;
3 using System.Threading.Tasks;
4
5 namespace PT1ReTest_Hoh_Jungi
6 {
7 class Shop
8 {
9 private string strName;
10 protected int intQuantity;
11 protected float fltPrice;
12 private static int intTotalQuantity;
13
14 public Shop(string name, int quantity, float price)
15 {
16 strName = name;
17 intQuantity = quantity;
18 fltPrice = price;
19 intTotalQuantity += intQuantity;
20 }
21
22 public string Name
23 {
24 get { return strName; }
25 }
26
27 public static int TotalQuantity
28 {
29 get { return intTotalQuantity; }
30 }
31
32 public virtual float GetCost()
33 {
34 return intQuantity * fltPrice;
35 }
36 }
37
38 class Order:Shop
39 {
40 private int intDiscount;
41
42 public Order(int d, string n, int q, float p):base(n, q, p)
43 {
44 intDiscount = d;
45 }
46 public override float GetCost()
47 {
48 return base.GetCost()*(100f-intDiscount)/100f;
49 }
50 public string CheckBudget(float budget)
51 {
52 if (budget < GetCost())
53 {
54 return "Exceeded";
55 }
56 else
57 {
58 return "OK";
59 }
60 }
61 }
62 internal class Program
63 {

LastSaved 20230119T1206 page 2 of 4 (Leave this footer alone!)


Official (Closed) - Non Sensitive
PS11-12 Hoh Jungi

1 static void Main(string[] args)


2 {
3 Console.Write("Enter your budget per order: $");
4 float Budget = float.Parse(Console.ReadLine());
5
6 Order obj1, obj2;
7
8 Console.WriteLine("==============================");
9
10 Console.WriteLine("ORDER #1");
11 Console.Write("Enter shop name: ");
12 string Shop = Console.ReadLine();
13 Console.Write("Enter order quantity: ");
14 int Quantity = int.Parse(Console.ReadLine());
15 Console.Write("Enter order unit price: $");
16 float Price = float.Parse(Console.ReadLine());
17 Console.Write("Enter order discount (0-100%): ");
18 int Disocunt = int.Parse(Console.ReadLine());
19
20 obj1 = new Order(Disocunt, Shop, Quantity, Price);
21
22 Console.WriteLine("------------------------------");
23
24 Console.WriteLine("Name of shop: {0}", obj1.Name);
25 Console.WriteLine("Total payable: ${0}", obj1.GetCost());
26 Console.Write("Budget check (Y/N)? ");
27 string b = Console.ReadLine();
28
29 if (b == "Y")
30 {
31 Console.WriteLine("Budget status: {0}", obj1.CheckBudget(Budget));
32 }
33 else if (b == "N")
34 {
35 }
36
37 Console.WriteLine("==============================");
38
39 Console.WriteLine("ORDER #2");
40 Console.Write("Enter shop name: ");
41 Shop = Console.ReadLine();
42 Console.Write("Enter order quantity: ");
43 Quantity = int.Parse(Console.ReadLine());
44 Console.Write("Enter order unit price: $");
45 Price = float.Parse(Console.ReadLine());
46 Console.Write("Enter order discount (0-100%): ");
47 Disocunt = int.Parse(Console.ReadLine());
48
49 obj2 = new Order(Disocunt, Shop, Quantity, Price);
50
51 Console.WriteLine("------------------------------");
52
53 Console.WriteLine("Name of shop: {0}", obj2.Name);
54 Console.WriteLine("Total payable: ${0}", obj2.GetCost());
55 Console.Write("Budget check (Y/N)? ");
56 string bb = Console.ReadLine();
57
58 if (bb == "Y")
59 {
60 Console.WriteLine("Budget status: {0}", obj2.CheckBudget(Budget));
61 }
62 else if (bb == "N")
63 {

LastSaved 20230119T1206 page 3 of 4 (Leave this footer alone!)


Official (Closed) - Non Sensitive
PS11-12 Hoh Jungi

1 }
2
3 Console.WriteLine("==============================");
4 Console.WriteLine("Total order quantity: {0}", Order.TotalQuantity);
5
6 Console.ReadKey();
7 }
8 }
9 }
10
11

LastSaved 20230119T1206 page 4 of 4 (Leave this footer alone!)

You might also like