Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _2.LaptopShop
- {
- class Laptop
- {
- private string model;
- private int price;
- private string manufacturer;
- private string processor;
- private int ram;
- private string graphics;
- private string hdd;
- private string screen;
- private Battery battery;
- public Laptop(string model, int price)
- {
- this.Model = model;
- this.Price = price;
- }
- public Laptop(string model, int price, string manufacturer = null, string processor = null, int ram = 0, string hdd = null, string graphicsCard = null, string screen = null, string type = null, int batteryLife = 0)
- : this(model, price)
- {
- this.Manufacturer = manufacturer;
- this.Processor = processor;
- this.Ram = ram;
- this.Hdd = hdd;
- this.Graphics = graphics;
- this.Battery = battery;
- this.Screen = screen;
- this.battery = new Battery(type, batteryLife);
- }
- public string Model
- {
- get { return this.model; }
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentNullException("The model field can not be empty!");
- }
- this.model = value;
- }
- }
- public int Price
- {
- get { return this.price; }
- set
- {
- if (value < 0)
- {
- throw new IndexOutOfRangeException("The price can not be negative!");
- }
- this.price = value;
- }
- }
- public string Manufacturer
- {
- get { return this.manufacturer; }
- set
- {
- this.manufacturer = value;
- }
- }
- public string Processor
- {
- get { return this.processor; }
- set
- {
- this.processor = value;
- }
- }
- public int Ram
- {
- get { return this.ram; }
- set
- {
- this.ram = value;
- }
- }
- public string Graphics
- {
- get { return this.graphics; }
- set
- {
- this.graphics = value;
- }
- }
- public string Hdd
- {
- get { return this.hdd; }
- set
- {
- this.hdd = value;
- }
- }
- public string Screen
- {
- get { return this.screen; }
- set
- { this.screen = value; }
- }
- public Battery Battery
- {
- get { return this.battery; }
- set { this.battery = value; }
- }
- public override string ToString()
- {
- StringBuilder laptopStringBuild = new StringBuilder();
- laptopStringBuild.AppendLine("model: " + this.Model);
- if (this.Manufacturer != null)
- {
- laptopStringBuild.AppendLine("manufacturer: " + this.Manufacturer);
- }
- if (this.Processor != null)
- {
- laptopStringBuild.AppendLine("processor: " + this.Processor);
- }
- if (this.Ram != 0)
- {
- laptopStringBuild.AppendLine("RAM: " + this.Ram);
- }
- if (this.Hdd != null)
- {
- laptopStringBuild.AppendLine("HDD: " + this.Hdd);
- }
- if (this.Screen != null)
- {
- laptopStringBuild.AppendLine("screen: " + this.Screen);
- }
- if (this.Battery != null)
- {
- laptopStringBuild.AppendLine(this.Battery.ToString());
- }
- laptopStringBuild.AppendLine("price: " + this.Price);
- return laptopStringBuild.ToString();
- }
- }
- class Battery
- {
- private string type;
- private double batteryLife;
- public Battery(string type)
- {
- this.Type = type;
- }
- public Battery(string type, int batteryLife)
- : this(type)
- {
- this.BatteryLife = batteryLife;
- }
- public string Type
- {
- get { return this.Type; }
- set
- {
- if (value == "")
- {
- throw new ArgumentException("Invalid type!");
- }
- this.type = value;
- }
- }
- public double BatteryLife
- {
- get { return this.BatteryLife; }
- set
- {
- if (batteryLife < 0)
- {
- throw new ArgumentException("Battery life can not be negative!");
- }
- this.batteryLife = value;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Laptop sample = new Laptop("Yoga", 34, "lenovo", "intel", 16, "ekran", "nvidia", "15", "bateriq", 999);
- Console.WriteLine(sample.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement