Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ClassBasics
- {
- // Your code goes here
- public class Product
- {
- string name;
- decimal price;
- string group;
- public Product(string name, ProductGroup group, decimal price)
- {
- Price = price;
- Name = name;
- this.Group = group;
- }
- public string Group
- {
- get
- {
- return group;
- }
- set
- {
- group = value;
- }
- }
- public Product(string name, ProductGroup group)
- {
- this.Name = name;
- this.Group = group;
- }
- public decimal Price
- {
- get
- {
- return price;
- }
- set
- {
- price = value;
- }
- }
- private string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public string Summary
- {
- get
- {
- return Group + ": " + this.Name + " " + this.Price;
- }
- }
- }
- public class ProductGroup
- {
- string name;
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public ProductGroup(string name)
- {
- this.Name = nimi;
- }
- }
- class Program
- {
- static void Main()
- {
- Product[] purchases = new Product[2];
- ProductGroup homeApplianceGroup = new ProductGroup("Home appliances");
- purchases[0] = new Product("Coffee maker", homeApplianceGroup, 49.90M);
- purchases[1] = new Product("Microwave", homeApplianceGroup);
- purchases[1].Price = 99.90M;
- decimal sum = 0;
- foreach (Product t in purchases)
- {
- sum += t.Price;
- Console.WriteLine(t.Summary);
- }
- Console.WriteLine("Totals {0:f2}", sum);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement