Help Creating a class, ToString override, methods
Hello all, im doing this problem which will allow a store to return a invoice, I have two classes and I guess I am at the very end and need help fixing some things so I can finally have the program execute:
Class1: "Invoice":
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InvoiceApp
{
class Invoice
{
private string invNumber;
private string invDescription;
private int invPrice;
private int invPurchased;
private double invTotalCost;
public Invoice()
{
}
public Invoice(string number)
{
invNumber = number;
}
public Invoice(string number, string description)
{
invNumber = number;
invDescription = description;
}
public Invoice(string number, string description,
int price, int purchased)
{
invNumber = number;
invDescription = description;
invPrice = price;
invPurchased = purchased;
}
public string InvNumber
{
get
{
return invNumber;
}
set
{
invNumber = value;
}
}
public string InvDescription
{
get
{
return invDescription;
}
set
{
invDescription = value;
}
}
public int InvPrice
{
get
{
return invPrice;
}
set
{
invPrice = value;
}
}
public int InvPurchased
{
get
{
return invPurchased;
}
set
{
invPurchased = value;
}
}
public double InvTotalCost
{
get
{
return invPurchased * invPrice;
}
set
{
invTotalCost = value;
}
}
public override string ToString()
{
return "Item Description: " + invDescription.ToString(); +
"\nTotal Cost: " + invTotalCost.ToString("C");
}
} //class ends
} //namespace ends
Class2: "InvoiceApp" :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InvoiceApp
{
class InvoiceApp
{
static void Main(string[] args)
{
Invoice someQuantity = new
someQuantity.InvPurchased = someQuantity.InvPurchased * ;
Console.Write(someQuantity);
Console.Write(someDescription);
Console.ReadKey();
} //Main Ends
} //class ends
} //namespace ends
Line 104-109 Im trying to get to the point where I return what the Item Description and total cost in "Class1, Invoice"
Lines 12-22 in Class2: "InvoiceApp" Im trying to use constructors and objects to help me print to the output screen
Thank you very much again all of you!
techlawsam
Junior Poster in Training
56 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
techlawsam
Junior Poster in Training
56 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Do it this way:
class Program
{
static void Main(string[] args)
{
Invoice someQuantity = new Invoice("1", "some description", 100, 120);
Console.Write(someQuantity);
Console.ReadKey();
}
}
class Invoice
{
public Invoice()
{
}
public Invoice(string number)
{
this.InvNumber = number;
}
public Invoice(string number, string description)
{
this.InvNumber = number;
this.InvDescription = description;
}
public Invoice(string number, string description,
int price, int purchased)
{
this.InvNumber = number;
this.InvDescription = description;
this.InvPrice = price;
this.InvPurchased = purchased;
}
public string InvNumber { get; set; }
public string InvDescription{ get; set; }
public int InvPrice{ get; set; }
public int InvPurchased{ get; set; }
public double InvTotalCost
{
get { return InvPurchased * InvPrice; }
}
public override string ToString()
{
return String.Format("Item Description: {0}\nTotal Cost: {1} ", InvDescription, InvTotalCost.ToString("C"));
}
}
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474