Advertisement
d_brezoev

oopbattery

Jan 29th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 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. namespace MobilePhoneDevice
  8. {
  9.     class Battery
  10.     {
  11.         //const double DefaultHoursIdle = 4.0;
  12.         //const double DefaultHoursTalk = 0.5;
  13.         private string model;
  14.         private double? hoursIdle = 4.0;  // !
  15.         private double? hoursTalk = 0.5;// !
  16.         public BatteryType BatteryType { get; set; }
  17.  
  18.         //property for model
  19.         public string Model
  20.         {
  21.             get
  22.             {
  23.                 return this.model;
  24.             }
  25.              set // ????
  26.             {
  27.                 this.model = value;
  28.             }
  29.         }
  30.           //property for hours idle
  31.         public double? HoursIdle
  32.         {
  33.             get { return this.hoursIdle; }
  34.              set // ????
  35.             {
  36.                 if (value==null)
  37.                 {
  38.                     //value = DefaultHoursIdle;
  39.                     value = hoursIdle;
  40.                 }
  41.                 this.hoursIdle = value;
  42.                 if (hoursIdle < 0)
  43.                 {
  44.                     throw new ArgumentException();
  45.                 }          
  46.             }
  47.         }
  48.         public double? HoursTalk
  49.         {
  50.             get { return this.hoursTalk; }
  51.             set // ????
  52.             {
  53.                 if (value == null)
  54.                 {
  55.                     //value = DefaultHoursTalk;
  56.                     value = hoursTalk;
  57.                 }
  58.                 this.hoursTalk = value;
  59.                 if (hoursTalk < 0)
  60.                 {
  61.                     throw new ArgumentException();
  62.                 }
  63.             }
  64.         }
  65.         //public Battery()
  66.         //{
  67.         //}
  68.  
  69.         //constructor
  70.         public Battery(string model)
  71.             : this(model, null, null, BatteryType.Liion)
  72.         {
  73.  
  74.         }
  75.  
  76.         //constructor
  77.         //public Battery(string model, double hoursTalk):this(model,null,hoursTalk,BatteryType.Liion)
  78.         //{
  79.         //}
  80.         //constructor
  81.         public Battery(string model, double? hoursIdle, double? hoursTalk, BatteryType batteryType)
  82.         {
  83.             this.Model = model;
  84.             this.HoursIdle = hoursIdle;
  85.             this.HoursTalk = hoursTalk;
  86.             this.BatteryType = batteryType;
  87.         }
  88.         static void Main()
  89.         {
  90.  
  91.             Battery battery = new Battery("varta");
  92.             Console.WriteLine(battery.model);
  93.             Console.WriteLine(battery.HoursIdle);
  94.             Console.WriteLine(battery.hoursTalk);
  95.             Console.WriteLine("--");
  96.             Console.WriteLine();
  97.             Battery ba = new Battery("toshiba", 40, 49, BatteryType.NiCd);
  98.             Console.WriteLine(ba.Model);
  99.             Console.WriteLine(ba.HoursTalk);
  100.             Console.WriteLine(ba.HoursIdle);
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement