Question
NEEDED IN C# please!! Use the class below to create an array of Invoice objects. Use the sample data shown in Fig. 9.8. Class Invoice
NEEDED IN C# please!!
Use the class below to create an array of Invoice objects. Use the sample data shown in Fig. 9.8. Class Invoice includes four properties, a PartNumber (type int), a PartDescription (type string), a Quantity of the item being purchased (type int) and a Price (type decimal). Perform the following queries on the array of Invoice objects and display the results: a) Use LINQ to sort the Invoice objects by PartDescription. b) Use LINQ to sort the Invoice objects by Price. c) Use LINQ to select the PartDescription and Quantity and sort the results by Quantity. d) Use LINQ to select from each Invoice the PartDescription and the value of the Invoice (i.e., Quantity * Price). Name the calculated column InvoiceTotal. Order the results by Invoice value. [Hint: Use let to store the result of Quantity * Price in a new range variable total]. e) Using the results of the LINQ query in part d, select the InvoiceTotals in the range $200 to $500.
Class Invoice:
// Invoice.cs
// Invoice for a hardware company
using System;
public class Invoice
{
string partNum;
string partDescription;
int quantity;
decimal unitPrice;
public Invoice(string pNum, string pDesciption, int q, decimal uPrice)
{
PartNum = pNum;
PartDescription = pDesciption;
Quantity = q;
UnitPrice = uPrice;
}
public string PartNum
{
get
{
return partNum;
} // end get
set
{
partNum = value;
} // end set
} // end
public string PartDescription
{
get
{
return partDescription;
} // end get
set
{
partDescription = value;
} // end set
} // end
public int Quantity
{
get
{
return quantity;
} // end get
set
{
if (value >= 0)
quantity = value;
} // end set
} // end
public decimal UnitPrice
{
get
{
return unitPrice;
} // end get
set
{
if (value >= 0M)
unitPrice = value;
} // end set
} // end
public decimal GetInvoiceAmount()
{
decimal amt = Quantity * UnitPrice;
return amt;
}
public override string ToString()
{
return string.Format("{0,-10}{1,-20}{2,-10}{3,10:C}", PartNum,
PartDescription, Quantity, UnitPrice);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started