Advertisement
vlad0

Define Object Ex. 01

Feb 19th, 2013
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _01.GSM_All_In_One
  7. {
  8.     class Battery
  9.     {
  10.  
  11.         public string Model { get; set; }
  12.         public double? Idle { get; set; }
  13.         public double? Talk { get; set; }
  14.  
  15.  
  16.        
  17.         //Print all Battery information
  18.         public void Print()
  19.         {
  20.             Console.WriteLine("Battery Properties");
  21.             Console.WriteLine("===================");
  22.             Console.WriteLine("Model: {0}", this.Model);
  23.             Console.WriteLine("Idle hours: {0}:{1,2} hours", (int)this.Idle, (this.Idle - (int)this.Idle)*60);
  24.             Console.WriteLine("Talk hours: {0}:{1,2} hours", (int)this.Talk, (this.Talk - (int)this.Talk)*60);
  25.             Console.WriteLine("===================");
  26.         }
  27.  
  28.     }
  29.     class Display
  30.     {
  31.         public double? Size { get; set; }
  32.         public double? Colors { get; set; }
  33.  
  34.         //print all Display information
  35.         public void Print()
  36.         {
  37.             Console.WriteLine("Display Properties");
  38.             Console.WriteLine("===================");
  39.             Console.WriteLine("Size: {0}''", this.Size);
  40.             Console.WriteLine("Colors: {0} millions", this.Colors);
  41.             Console.WriteLine("===================");
  42.         }
  43.  
  44.     }
  45.     class GSM
  46.     {
  47.         public string Model { get; set; }
  48.         public string Manafacturer { get; set; }
  49.         public decimal Price { get; set; }
  50.         public string Owner { get; set; }
  51.  
  52.  
  53.         public Battery Battery = new Battery();
  54.  
  55.         public Display Display = new Display();
  56.  
  57.         //Print all GSM information
  58.         public void Print()
  59.         {
  60.             Console.WriteLine("GSM Properties");
  61.             Console.WriteLine("===================");
  62.             Console.WriteLine("Model: {0}", this.Model);
  63.             Console.WriteLine("Manafacturer: {0}", this.Manafacturer);
  64.             Console.WriteLine("Owner: {0}", this.Owner);
  65.             Console.WriteLine("Price: {0} EUR", this.Price);
  66.             Console.WriteLine("===================");
  67.            
  68.         }
  69.     }
  70.    
  71.     class Program
  72.     {
  73.         static void Main(string[] args)
  74.         {
  75.             GSM myGSM = new GSM(); //by default all the value are null
  76.             myGSM.Model = "3310";
  77.             myGSM.Manafacturer = "Nokia";
  78.             myGSM.Owner = "Kiril Petrov"; //fake name :)
  79.             myGSM.Price = 345.21m;
  80.            
  81.             myGSM.Battery.Model = "Belkin";
  82.             myGSM.Battery.Idle = 6.5; //hours in idle mode of type double
  83.             myGSM.Battery.Talk = 1.5; //hours in talk mode of type double
  84.  
  85.             myGSM.Display.Size = 7.4; //size in inches
  86.             myGSM.Display.Colors = 16.5; //colors in millions
  87.  
  88.             myGSM.Print(); //print GSM properties
  89.             myGSM.Battery.Print(); //print Battery properties
  90.             myGSM.Display.Print(); //print Display properties
  91.  
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement