Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. namespace ClassBasics
  3. {
  4.     // Your code goes here
  5.     public class Product
  6.     {
  7.         string name;
  8.         decimal price;
  9.         string group;
  10.  
  11.         public Product(string name, ProductGroup group, decimal price)
  12.         {
  13.             Price = price;
  14.             Name = name;
  15.             this.Group = group;
  16.         }
  17.  
  18.         public string Group
  19.         {
  20.             get
  21.             {
  22.                 return group;
  23.             }
  24.             set
  25.             {
  26.                 group = value;
  27.             }
  28.         }
  29.  
  30.         public Product(string name, ProductGroup group)
  31.         {
  32.             this.Name = name;
  33.             this.Group = group;
  34.         }
  35.  
  36.         public decimal Price
  37.         {
  38.             get
  39.             {
  40.                 return price;
  41.             }
  42.             set
  43.             {
  44.                 price = value;
  45.             }
  46.         }
  47.  
  48.         private string Name
  49.         {
  50.             get
  51.             {
  52.                 return name;
  53.             }
  54.             set
  55.             {
  56.                 name = value;
  57.             }
  58.         }
  59.  
  60.  
  61.  
  62.         public string Summary
  63.         {
  64.             get
  65.             {
  66.                 return Group + ": " + this.Name + " " + this.Price;
  67.             }
  68.         }
  69.     }
  70.  
  71.     public class ProductGroup
  72.     {
  73.         string name;
  74.  
  75.         public string Name
  76.         {
  77.             get
  78.             {
  79.                 return name;
  80.             }
  81.             set
  82.             {
  83.                 name = value;
  84.             }
  85.         }
  86.  
  87.         public ProductGroup(string name)
  88.         {
  89.             this.Name = nimi;
  90.         }
  91.     }
  92.  
  93.     class Program
  94.     {
  95.         static void Main()
  96.         {
  97.  
  98.             Product[] purchases = new Product[2];
  99.             ProductGroup homeApplianceGroup = new ProductGroup("Home appliances");
  100.             purchases[0] = new Product("Coffee maker", homeApplianceGroup, 49.90M);
  101.             purchases[1] = new Product("Microwave", homeApplianceGroup);
  102.             purchases[1].Price = 99.90M;
  103.             decimal sum = 0;
  104.             foreach (Product t in purchases)
  105.             {
  106.                 sum += t.Price;
  107.                 Console.WriteLine(t.Summary);
  108.             }
  109.             Console.WriteLine("Totals {0:f2}", sum);
  110.             Console.ReadLine();
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement