It is a C# Please make sure the this part is included in the code. the user shou
ID: 3722036 • Letter: I
Question
It is a C#
Please make sure the this part is included in the code. the user should be able to enter what is below.
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.
===================================================================================================
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApplication {
class Invoice { //creating the class Invoice
//private variables
private int_quantity;
private decimal_price;
private string PartNumber{ get;set;}
private string PartDescr { get;set;}
//constructor
public Invoice(String partNumber,String partDescr, int quant, decimal price){
PartNumber=partNumber;
PartDescr=partDescr;
Quant=quant;
Price=p;
}//end of constructor
` public int Quant{
get{ return _quant;}
set{
if(value >0)
_quant = value;
else
_quant = 1;
}
}
public decimal Price{
get { return _price;}
set {
if(value > 0)
_price = value;
else
_price = 1;
}
}
public string PartNumber{
get{ return partNumber;}
set{ partNumber = value;}
}
public string PartDescr{
get { return partDescr;}
set { partDescr = value;}
}
public decimal GetInvoiceAmount(){
return Quant*Price;
}// Method for Calculating the Invoice Amount
} // End of class Invoice
//Now by testing the variables and calling the main function/method
class Program
{
public static void Main(string[] args)
{
string partNumber, partDescr;
int quant;
decimal price;
Console.WriteLine("Please enter part number);//Taking user input of the part Number
partNumber = Console.ReadLine();
Console.WriteLine("Please enter part description);//Taking user input of the part description
partDescr = Console.ReadLine();
Console.WriteLine("Please enter quantity);//Taking user input of the Quantity
quant = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter price);//Taking user input of the price
price = Convert.ToDecimal(Console.ReadLine());
Invoice invoice = new Invoice(partNumber, partDescr, quant, price); /* Creating the object of the class Invoice*/
Console.WriteLine("Your Order: ");
Console.WriteLine("Part Number: {0}", invoice.PartNumber);
Console.WriteLine("Part Description: {0}", invoice.PartDescr);
Console.WriteLine("Quantity: {0}", invoice.Quant);
Console.WriteLine("Price: {0}", invoice.Price);
Console.WriteLine("Total: {0:c}", invoice.GetInvoiceAmount());
Console.ReadLine();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.