Advertisement
soxa

GSM

Feb 3rd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. /*Define a class that holds information about a mobile phone device: model, manufacturer, price, owner, battery characteristics (model, hours idle and hours talk) and display characteristics (size and number of colors). Define 3 separate classes (class GSM holding instances of the classes Battery and Display).*/
  2.  
  3. namespace GSM
  4. {
  5.     using System;
  6.     using System.Text;
  7.     using System.Collections.Generic;
  8.     //model, manufacturer, price, owner
  9.     public class GSM
  10.     {
  11.         private readonly string model = null; //Declare only once
  12.         private readonly string manufacturer = null;
  13.         private int price = 0;
  14.         private string owner = null;
  15.         private Battery batery;
  16.         private Display display;
  17.  
  18.         //private Display displayCharacters = new Display();
  19.  
  20.         public string Model
  21.         {
  22.             get { return this.model; }
  23.         }
  24.         public string Manufacturer
  25.         {
  26.             get { return this.manufacturer; }
  27.         }
  28.         public int Price
  29.         {
  30.             get { return this.price; }
  31.             set
  32.             {
  33.                 if (value < 0)
  34.                 {
  35.                     throw new ArgumentException("Invalid price : price can't be negative");
  36.                 }
  37.                 this.price = value;
  38.             }
  39.         } // check for price
  40.         public string Owner
  41.         {
  42.             get { return this.owner; }
  43.             set { this.owner = value; }
  44.         }
  45.  
  46.         public GSM(string model, string manufacturer, int price, string owner)
  47.         {
  48.             this.model = model;
  49.             this.manufacturer = manufacturer;
  50.             this.price = price;
  51.             this.owner = owner;
  52.             this.batery = new Battery();
  53.             this.display = new Display();
  54.         }
  55.  
  56.         static void Main()
  57.         {
  58.             GSM firstGsm = new GSM("E51", "Manja", 700, "Pencho");
  59.             firstGsm.batery.Model = "Li/Ion";
  60.             firstGsm.batery.HoursIdle = 7;
  61.             firstGsm.batery.HoursTalk = 7;
  62.             firstGsm.display.Color = "16 milion";
  63.             firstGsm.display.Size = "3 inch";
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement