Create a C console application for this questionCreate a cla

Create a C# console application for this question.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 setaccessors 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 getaccessor to retrieve and display the data stored in the instance variables. Use the GetInvoiceAmount method to calculate the invoice amount. Display the invoice amount.

Solution

InvoiceTest.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise3
{
    class InvoiceTest
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(\"Enter description of the product: \");
            string description = Console.ReadLine();

            Console.WriteLine(\"Enter partNumber: \");
            string partNumber = Console.ReadLine();

            Console.WriteLine(\"Enter price for this product: \");
            decimal price = decimal.Parse(Console.ReadLine());

            Console.WriteLine(\"Enter quantity: \");
            int quantity = int.Parse(Console.ReadLine());

            Invoice myItem = new Invoice(partNumber, description, quantity, price);

            Console.WriteLine(\"Initial cost of this product is: {0}\", myItem.PricePerItem);
            Console.WriteLine(\"Enter new cost for this product: \");
            myItem.PricePerItem = decimal.Parse(Console.ReadLine());
            Console.WriteLine(\"New price for this item is: {0}\", myItem.PricePerItem);
            Console.WriteLine(\"The cost amount for {0} with quantity {1} is: {2}\", myItem.PartDescription, myItem.Quantity, myItem.GetInvoiceAmount());
        }
    }
}

Invoice.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exercise3
{
    public class Invoice
    {
        private string partNumber;

        public string PartNumber
        {
            get { return partNumber; }
            set { partNumber = value; }
        }

        private string partDescription;

        public string PartDescription
        {
            get { return partDescription; }
            set { partDescription = value; }
        }

        private decimal pricePerItem;
        public decimal PricePerItem
        {
            get
            {
                return pricePerItem;
            }
            set
            {
                if (value >= 0)
                {
                    pricePerItem = value;
                }

            }
        }

        private int quantity;

        public int Quantity
        {
            get { return quantity; }
            set
            {
                if (value >= 0)
                {
                    quantity = value;
                }
            }
        }

        public Invoice(string partNumber, string partDescription, int quantity, decimal pricePerItem)
        {
            PartNumber = partNumber;
            PartDescription = partDescription;
            PricePerItem = pricePerItem;
            Quantity = quantity;
        }

        public Invoice()
        {
        }

        public decimal GetInvoiceAmount()
        {
            decimal amount = Quantity * PricePerItem;
            return amount;
        }
    }
}

Create a C# console application for this question.Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the
Create a C# console application for this question.Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the
Create a C# console application for this question.Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site