From b7e983070ca61c065e14756141b2769ac005cb32 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 15 Apr 2016 11:57:47 +0100 Subject: [PATCH] Add product class --- Product.cs | 41 +++++++++++++++++++++++++++++++++++++++++ product-list.csproj | 1 + 2 files changed, 42 insertions(+) create mode 100644 Product.cs diff --git a/Product.cs b/Product.cs new file mode 100644 index 0000000..1743303 --- /dev/null +++ b/Product.cs @@ -0,0 +1,41 @@ +using System; + + +namespace productlist +{ + public class Product + { + public string name; + public int version; + public string description; + + public Product(string name, int version, string description) { + this.name = name; + this.version = version; + this.description = description; + } + public static Product fromPrompt() { + string pName = UI.getAnswer ("Product Name", UI.validateString); + int pVersion = Int32.Parse(UI.getAnswer ("Version", UI.validateInt)); + string pDescription = UI.getAnswer ("Description", UI.validateString); + Product p = new Product (pName, pVersion, pDescription); + Console.WriteLine(String.Format("{0} created successfully!", p.ToString())); + return p; + } + + public override string ToString() { + return String.Format ("Product {0}", this.name); + } + + public void display() { + string output = String.Format(@" +{0} +-------------------------- +Name: {1} +Version: {2} +Description: {3} + ", this.ToString(), this.name, this.version, this.description); + Console.WriteLine (output); + } + } +} diff --git a/product-list.csproj b/product-list.csproj index 1070eec..b255b64 100644 --- a/product-list.csproj +++ b/product-list.csproj @@ -38,6 +38,7 @@ +