NEEDED IN BASIC C# Create a class called Invoice that a hardware store might use
ID: 3668505 • Letter: N
Question
NEEDED IN BASIC C#
Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables: a part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (decimal). Your class should have a constructor that initializes the four values. Provide a property with get and set accessors for every instance variable. For the Quantity and PricePerItem properties, if the value passed to the set accessor is negative, the value of the instance variable should be left unchanged. In addition, provide a method GetInvoiceAmount that calculates the invoice amount (i.e. multiplies the quantity by the price per item), then returns the amount as a decimal value. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities. In this test application, ask the user to enter part number, part description, quantity and price per item. Use the get accessor to retrieve and display the data stored in the instance variables. Use the GetInvoiceAmount method to calculate the invoice amount. Display the invoice amount.
Explanation / Answer
Answer:
Here i have just taken 1 Product Example i.e Tooth Paste.
You can add or create as many object as you want and display the same.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InvoiceSampleProg
{
class Program
{
static void Main(string[] args)
{
TotalInvoiceAmount Invoice = new TotalInvoiceAmount(“1001",”Tooth paste 100 gm”,8, 75.0);
Console.WriteLine(“Part description: {0} Part Number: {1} PricePerItem per item: ${2} TQuantitytity: {3} Total PricePerItem: ${4}”
, Invoice.PartDescriptionesc.ToString(), Invoice.PartNumberum.ToString(), Invoice.PricePerItemPerItem.ToString()
, Invoice.TQuantity.ToString(), Invoice.GetInvoiceAmount());
Console.ReadLine();
}
}
class TotalInvoiceAmount
{
public TotalInvoiceAmount(string PartNumber, string PartDescription,int TQuantitytity, decimal PricePerItem)
{
this.PartNumber = PartNumber;
this.PartDescription = PartDescription;
this.TQuantitytity = TQuantitytity;
this.PricePerItem = PricePerItem;
}
private string PartNumber;
private string PartDescription;
private int TQuantitytity;
private decimal PricePerItem;
public decimal GetInvoiceAmount()
{
return (PricePerItem * TQuantitytity);
}
public int TQuantity
{
get { return TQuantitytity; }
set { TQuantitytity = value; }
}
public decimal PricePerItem
{
get { return PricePerItem; }
set { PricePerItem = value; }
}
public string PartNumberum
{
get { return PartNumber; }
set { PartNumber = value; }
}
public string PartDescription
{
get { return PartDescription; }
set { PartDescription = value; }
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.