Use C# to Create a class called Invoice that a hardware store might use to repre
ID: 3586017 • Letter: U
Question
Use C# to 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 the following pieces of information as private instance fields: A part number (type string) A part name (type string) A part description (type string) A part manufacturer's name (type string) An invoice number (type string) An invoice date(type string) A quantity of the item being purchased (type int) A price per item (decimal). For the int variable, provide a property named Quantity with a get and set accessor. For the decimal variable, provide a property named PricePerItem with a get and set accessor. For each string variable, provide an indexer with a get and set accessor. Provide a method named 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 class named InvoiceTest that demonstrates class Invoice’s the following capabilities: Create an instance by calling its default constructor, Assign the value of each instance variable via the indexers and properties, Call the method GetInvoiceAmount, Get the new value of each variable via its property or indexer.
Explanation / Answer
InvoiceTest.cs
using System;
public class InvoiceTest
{
public static void Main(string[] args)
{
string number; //declares the number variable
string description; //declares the description variable
int quantity; //declares the quantity variable
decimal price; //declares the price variable
Console.Write("Enter the part number: ");
number = Console.ReadLine();
Console.Write("Enter description of part: ");
description = Console.ReadLine();
Console.Write("Enter quantity being purchased: ");
quantity = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter price per item: $");
price = Convert.ToDecimal(Console.ReadLine());
Invoice invoice1 = new Invoice(number, description, quantity, price); //creates new invoice
Console.WriteLine(); //writes blank line
Console.WriteLine("Part Number: {0}", invoice1.PartNumber); //writes part number
Console.WriteLine("Part Description: {0}", invoice1.PartDescription); //writes part description
Console.WriteLine("Quantity: {0}", invoice1.QuantityPurchased); //writes quantity
Console.WriteLine("Cost Per Item: {0:C}", invoice1.PricePerItem); //writes price per item
Console.WriteLine("Total Cost: {0:C}", invoice1.TotalCost); //writes total cost of the invoice
}
}
================================================================================
Invoice.cs
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.