Created
November 19, 2015 19:32
-
-
Save Jore2/9d557632973e5b270d46 to your computer and use it in GitHub Desktop.
03.ComputerCatalog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace _03.ComputerCatalog | |
{ | |
class Component | |
{ | |
private string name; | |
private decimal price; | |
public string Name | |
{ | |
get | |
{ | |
return this.name; | |
} | |
set | |
{ | |
if (string.IsNullOrEmpty(value)) | |
{ | |
throw new ArgumentNullException("Name canot be empty."); | |
} | |
else | |
{ | |
this.name = value; | |
} | |
} | |
} | |
public decimal Price | |
{ | |
get | |
{ | |
return this.price; | |
} | |
set | |
{ | |
if (value<0) | |
{ | |
throw new ArgumentException("Price canot be negative."); | |
} | |
else | |
{ | |
this.price = value; | |
} | |
} | |
} | |
public string Details { get; set; } | |
public Component(string name,string details,decimal price) | |
{ | |
this.Name = name; | |
this.Details = details; | |
this.Price = price; | |
} | |
public Component(string name,decimal price):this(name,"",price) | |
{ | |
} | |
public Component(Component c):this(c.Name,c.Details,c.Price) | |
{ | |
} | |
public Component():this("","",0) | |
{ | |
} | |
public override string ToString() | |
{ | |
return string.Format("Component Name:{0}.\nComponent Price:{1}lv.\nComponent Details:{2}.", this.Name, this.Price, this.Details); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace _03.ComputerCatalog | |
{ | |
class Computer | |
{ | |
private string name; | |
private List<Component> component; | |
public string Name | |
{ | |
get | |
{ | |
return this.name; | |
} | |
set | |
{ | |
if (string.IsNullOrEmpty(value)) | |
{ | |
throw new ArgumentNullException(); | |
} | |
else | |
{ | |
this.name = value; | |
} | |
} | |
} | |
public List<Component> Component | |
{ | |
get | |
{ | |
return this.component; | |
} | |
set | |
{ | |
this.component = new List<Component>(value); | |
} | |
} | |
public Computer(string name,List<Component> components) | |
{ | |
this.Name = name; | |
this.Component = new List<Component>(components); | |
} | |
public Computer(string name):this(name,new List<Component>()) | |
{ | |
} | |
public void AddComponent(Component c) | |
{ | |
this.Component.Add(c); | |
} | |
public void DisplayComputer() | |
{ | |
decimal totalPrice = 0; | |
Console.WriteLine("Name of the Computer: {0}",this.Name); | |
for (int i = 0; i < this.Component.Count; i++) | |
{ | |
Console.WriteLine(Component[i]); | |
totalPrice += Component[i].Price; | |
Console.WriteLine(); | |
} | |
Console.WriteLine("Total price of the computer is: {0}lv.",totalPrice); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment