Advertisement
svetoslavbozov

OOP.1.1 MobilePhoneConstructors

Feb 20th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class MyGSM
  8. {
  9.     static void Main()
  10.     {
  11.         // some test what happens
  12.         GSM mygsm = new GSM("k850", "sony ericsson");
  13.         Console.Write("Phone manufacturer: {0}\nPhone model: {1}\nPhopne price: {2}\nPhone owner: {3}",mygsm.Manufacturer, mygsm.Model,mygsm.Price, mygsm.Owner);
  14.  
  15.         Console.WriteLine();
  16.         //some other test
  17.         //add gsm properties directly
  18.         mygsm.Owner = "me";
  19.         mygsm.Price = 0; //no negative value check implemented int this property!
  20.         mygsm.Display.Size = 1000;
  21.         mygsm.Display.Colors = 2;
  22.         mygsm.Battery.HoursIdle = 1;
  23.         mygsm.Battery.HoursTalk = 1;
  24.         mygsm.Battery.Model = "who cares";
  25.  
  26.         //....
  27.         //add new batery and than add it to the gsm
  28.         Battery mybaterry = new Battery();
  29.         mybaterry.Model = "blabla";
  30.         mybaterry.HoursIdle = 1;
  31.         mybaterry.HoursTalk = 0;
  32.  
  33.         mygsm.Battery = mybaterry;
  34.        
  35.         //and no more tests...I`m lazy
  36.     }    
  37. }
  38.  
  39. public class GSM
  40. {
  41.     Display gsmDisplay = new Display();
  42.     Battery gsmBattery = new Battery();
  43.  
  44.     private string model;
  45.     private string manufacturer;
  46.     private int? price = null;
  47.     private string owner = null;
  48.     private Display display = new Display();
  49.     private Battery battery = new Battery();
  50.  
  51.     public Display Display
  52.     {
  53.         get { return this.display; }
  54.         set { this.display = value; }
  55.     }
  56.     public Battery Battery
  57.     {
  58.         get { return this.battery; }
  59.         set { this.battery = value; }
  60.     }
  61.  
  62.     public string Model
  63.     {
  64.         get { return this.model; }
  65.         set { this.model = value; }
  66.     }
  67.     public string Manufacturer
  68.     {
  69.         get { return this.manufacturer; }
  70.         set { this.manufacturer = value; }
  71.     }
  72.     public int? Price
  73.     {
  74.         get { return this.price; }
  75.         set { this.price = value; }
  76.     }
  77.     public string Owner
  78.     {
  79.         get { return this.owner; }
  80.         set { this.owner = value; }
  81.     }
  82.     public GSM(string model, string manufacturer)
  83.     {
  84.         this.Model = model;
  85.         this.Manufacturer = manufacturer;
  86.     }
  87.     public GSM(string model, string manufacturer, int price) : this(model, manufacturer)
  88.     {
  89.         this.Price = price;
  90.     }
  91.     public GSM(string model, string manufacturer, int price, Display gsmDisplay, Battery gsmBattery)
  92.         : this(model, manufacturer, price)
  93.     {
  94.         this.gsmDisplay = gsmDisplay;
  95.         this.gsmBattery = gsmBattery;
  96.     }
  97.     public GSM(string model, string manufacturer, int price, Display gsmDisplay, Battery gsmBattery, string owner)
  98.         : this(model, manufacturer, price, gsmDisplay, gsmBattery)
  99.     {
  100.         this.Owner = owner;
  101.     }
  102. }
  103.  
  104. public class Display
  105. {
  106.     private int? size = null;
  107.     private int? colors = null;
  108.  
  109.     public int? Size
  110.     {
  111.         get { return this.size; }
  112.         set { this.size = value; }
  113.     }
  114.     public int? Colors
  115.     {
  116.         get { return this.colors; }
  117.         set { this.colors = value; }
  118.     }
  119.     public Display()
  120.     {
  121.     }
  122.     public Display(int size)
  123.     {
  124.         this.Size = size;
  125.     }
  126.     public Display(int size, int colors)
  127.         : this(size)
  128.     {
  129.         this.Colors = colors;
  130.     }
  131. }
  132.  
  133. public class Battery
  134. {
  135.     private string model = null;
  136.     private int? hoursIdle = null;
  137.     private int? hoursTalk = null;
  138.  
  139.     public string Model
  140.     {
  141.         get { return this.model; }
  142.         set { this.model = value; }
  143.     }
  144.     public int? HoursIdle
  145.     {
  146.         get { return this.hoursIdle; }
  147.         set { this.hoursIdle = value; }
  148.     }
  149.     public int? HoursTalk
  150.     {
  151.         get { return this.hoursTalk; }
  152.         set { this.hoursTalk = value; }
  153.     }
  154.  
  155.     public Battery()
  156.     {
  157.     }
  158.     public Battery(string model)
  159.     {
  160.         this.Model = model;
  161.     }
  162.     public Battery(string model, int hoursIdle) : this(model)
  163.     {
  164.         this.HoursIdle = hoursIdle;
  165.     }
  166.     public Battery(string model, int hoursIdle, int hoursTalk) : this(model, hoursIdle)
  167.     {
  168.         this.HoursTalk = hoursTalk;
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement