Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- /*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. Define several constructors for the defined classes that take different sets of arguments
- * (the full information for the class or part of it). Assume that model and manufacturer are mandatory
- * (the others are optional). All unknown data fill with null.*/
- /*3. Add an enumeration BatteryType (Li-Ion, NiMH, NiCd, …) and use it as a new field for the batteries.*/
- /*4. Add a method in the GSM class for displaying all information about it. Try to override ToString().*/
- namespace MobilePhoneInformation
- {
- class BaseClass
- {
- static void Main()
- {
- GSM newGSM = new GSM("Galaxy note 2", "Samsung", 1030, "Pesho Peshov");
- Console.WriteLine(newGSM.ToString());
- //newGSM.Model = "Galaxy note 2";
- //newGSM.Manufacturer = "Samsung";
- //newGSM.Price = 1030;
- //newGSM.Owner = "Pesho Peshov";
- Battery newBattery = new Battery("Li-Ion 3100 mAh", 980, 35, BatteryType.LiIon);
- //newBattery.Print();
- //newGSM.Battery.Model = "Li-Ion 3100 mAh battery";
- //newGSM.Battery.HoursIdle = 980;
- //newGSM.Battery.HoursTalk = 35;
- //Display newDisplay = new Display(5.55, 16000000);
- //newDisplay.Print();
- //newGSM.Display.Size = 5.55;
- //newGSM.Display.NumberOfColors = 16000000;
- //newGSM.Print();
- //newGSM.Battery.Print();
- ////newGSM.Display.Print();
- }
- }
- class GSM
- {
- private string model;
- private string manufacturer;
- private double? price;
- private string owner;
- public GSM(string model)
- {
- this.Model = model;
- }
- public GSM(string model, string manufacturer) : this(model)
- {
- this.Manufacturer = manufacturer;
- }
- public GSM(string model, string manufacturer, double price)
- : this(model, manufacturer)
- {
- this.Price = price;
- }
- public GSM(string model, string manufacturer, double price, string owner)
- : this(model, manufacturer, price)
- {
- this.Owner = owner;
- }
- public string Model
- {
- get { return model; }
- set { model = value; }
- }
- public string Manufacturer
- {
- get { return manufacturer; }
- set { manufacturer = value; }
- }
- public double? Price
- {
- get { return price; }
- set { price = value; }
- }
- public string Owner
- {
- get { return owner; }
- set { owner = value; }
- }
- Battery newBattery = new Battery("Li-Ion 3100 mAh", 980, 35, BatteryType.LiIon);
- Display newDisplay = new Display(5.55, 16000000);
- public void Print()
- {
- Console.WriteLine("===================");
- Console.WriteLine("GSM characteristics");
- Console.WriteLine("===================");
- Console.WriteLine("Model: {0}", this.Model);
- Console.WriteLine("-------------------");
- Console.WriteLine("Manufacturer: {0}", this.Manufacturer);
- Console.WriteLine("-------------------");
- Console.WriteLine("Price: {0} lv.", this.Price);
- Console.WriteLine("-------------------");
- Console.WriteLine("Owner: {0}", this.Owner);
- Console.WriteLine("===================");
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine("Model: " + this.Model);
- sb.AppendLine("Manufacturer: " + this.Manufacturer);
- sb.AppendLine("Price: " + this.Price + "lv");
- sb.AppendLine("Owner: " + this.Owner);
- sb.AppendLine("Battery model: " + newBattery.Model);
- sb.AppendLine("Battery type: " + newBattery.Type);
- sb.AppendLine("Hours idle: " + newBattery.HoursIdle);
- sb.AppendLine("Hours talk: " + newBattery.HoursTalk);
- sb.AppendLine("Display size: " + newDisplay.Size);
- sb.AppendLine("Display colors: " + newDisplay.NumberOfColors);
- return sb.ToString();
- }
- }
- class Battery
- {
- private string model;
- private double hoursIdle;
- private double hoursTalk;
- private BatteryType type;
- public Battery(string model)
- {
- this.Model = model;
- }
- public Battery(string model, double hoursIdle, double hoursTalk)
- : this(model)
- {
- this.HoursIdle = hoursIdle;
- this.HoursTalk = hoursTalk;
- }
- public Battery(string model, double hoursIdle, double hoursTalk, BatteryType type)
- : this(model, hoursIdle, hoursTalk)
- {
- this.Type = type;
- }
- public string Model
- {
- get { return model; }
- set { model = value; }
- }
- public double HoursIdle
- {
- get { return hoursIdle; }
- set { hoursIdle = value; }
- }
- public double HoursTalk
- {
- get { return hoursTalk; }
- set { hoursTalk = value; }
- }
- public BatteryType Type
- {
- get { return type; }
- set { type = value; }
- }
- public void Print()
- {
- Console.WriteLine("=======================");
- Console.WriteLine("Battery characteristics");
- Console.WriteLine("=======================");
- Console.WriteLine("Model: {0}", this.Model);
- Console.WriteLine("-----------------------");
- Console.WriteLine("Hours idle: {0} h", this.HoursIdle);
- Console.WriteLine("-----------------------");
- Console.WriteLine("Hours talk: {0} h", this.HoursTalk);
- Console.WriteLine("-----------------------");
- Console.WriteLine("Battery type: {0}", this.Type);
- Console.WriteLine("========================");
- }
- }
- class Display
- {
- private double size;
- private int numberOfColors;
- public Display(double size)
- {
- this.Size = size;
- }
- public Display(double size, int numberOfColors)
- : this(size)
- {
- this.NumberOfColors = numberOfColors;
- }
- public double Size
- {
- get { return size; }
- set { size = value; }
- }
- public int NumberOfColors
- {
- get { return numberOfColors; }
- set { numberOfColors = value; }
- }
- public void Print()
- {
- Console.WriteLine("=======================");
- Console.WriteLine("Display characteristics");
- Console.WriteLine("=======================");
- Console.WriteLine("Size: {0}", this.Size);
- Console.WriteLine("-----------------------");
- Console.WriteLine("Number of colors: {0}", this.NumberOfColors);
- Console.WriteLine("========================");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement