Advertisement
d_brezoev

oop

Jan 29th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 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.         private string model;
  12.         private double hoursIdle = 4d;  // !
  13.         private double hoursTalk = 0.5d; // !
  14.         public BatteryType BatteryType { get; set; }
  15.  
  16.         //property for model
  17.         public string Model
  18.         {
  19.             get
  20.             {
  21.                 return this.model;
  22.             }
  23.             private set // ????
  24.             {
  25.                 this.model = value;
  26.             }
  27.         }
  28.  
  29.         //property for hours idle
  30.         public double HoursIdle
  31.         {
  32.             get { return this.hoursIdle; }
  33.             private set // ????
  34.             {
  35.                 this.hoursIdle = value;
  36.                 if (value < 0.0)
  37.                 {
  38.                     throw new ArgumentException();
  39.                 }
  40.             }
  41.         }
  42.  
  43.         //property for hours talk
  44.         public double HoursTalk
  45.         {
  46.             get { return this.hoursTalk; }
  47.             private set // ????
  48.             {
  49.                 this.hoursTalk = value;
  50.             }
  51.         }
  52.  
  53.         //no default contructor
  54.         //public Battery()
  55.         //{
  56.         //}
  57.  
  58.         //constructor
  59.         public Battery(string model):this(model, 4,0.5,BatteryType.Liion)
  60.         {          
  61.         }
  62.        
  63.         //constructor
  64.         public Battery(string model, double hoursTalk):this(model,4.0,hoursTalk,BatteryType.Liion)
  65.         {
  66.         }
  67.         //constructor
  68.         public Battery(string model, double hoursIdle, double hoursTalk,BatteryType batteryType)
  69.         {
  70.             this.model = model;
  71.             this.hoursIdle = hoursIdle;
  72.             if (hoursIdle<0)
  73.             {
  74.                 throw new ArgumentException();
  75.             }
  76.             this.hoursTalk = hoursTalk;
  77.             if (hoursTalk<0)
  78.             {
  79.                 throw new ArgumentException();
  80.             }
  81.             this.BatteryType = batteryType;
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement