Add product class
This commit is contained in:
parent
682634ce1d
commit
b7e983070c
2 changed files with 42 additions and 0 deletions
41
Product.cs
Normal file
41
Product.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,6 +38,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Product.cs" />
|
||||||
<Compile Include="UI.cs" />
|
<Compile Include="UI.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
|
Reference in a new issue