Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please include all source code in the answer thank you! Using LINQ Queries Speci

ID: 3571871 • Letter: P

Question

Please include all source code in the answer thank you!

Using LINQ Queries Specification:

Create an Inventory class which has the following fields private string itemNo; private string description; private int qtyOnHand; private decimal unitPrice; Add constructor, property and ToString() method into this class. Create a console application and test the following LINQ queries on an array of Inventory objects and display the results.

1. To sort Inventory objects by description.

2. To select description and unitPrice and sort by unitPrice.

3. To select description and total (qtyOnHand * unitPrice), sort by total. (Hint: Use let to create total.)

4. To display inventory objects that with unitPrice between $30 and $90, order by unitPrice in descending order.

5. To display inventory objects that convert the all description data to upper case, sort by description.

Please include all source code in the answer thank you!

Use the following test data to add into your collection qtyon Hand unit Price itemNumber description A123 Jig saw 12.00 15 11.00 B23 20 Wrench C112 10 8.00 Hammer 8 Power saw B135 79.00 C238 Screwdriver 30 9.50 A890 Lawn mower 6 95.00 C290 Electric sander 55.00 12 C100 30.50 Sledge Hammer 9

Explanation / Answer

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

public class Inventory
{
public string itemNo;
public string description;
public int qtyOnHand;
public double unitPrice;
public Inventory() { }
public Inventory(string pitemno, string pdescription, int pqtyOnHand, double punitPrice)
{
itemNo = pitemno;
description = pdescription;
qtyOnHand = pqtyOnHand;
unitPrice = punitPrice;
}

}

  

public class Test
{
   public static void Main()
   {

List<Inventory> inventory = new List<Inventory>
{
new Inventory ("A123","Jig saw", 15,12.00),
new Inventory ("B23", "Wrench", 20,11.00),
new Inventory ("C112","Hammer",10,8.00),
new Inventory ("B135","Power saw", 8,79.00),
new Inventory ("C238","Screwdriver",30,9.50),
new Inventory ("A890","lawn mower",6,95.00),
new Inventory ("C290","electric sender",12,55.00),
new Inventory ("C100","Sledge Hammer", 9,35.50)

};
   Console.WriteLine("1. To sort Inventory objects by description");
var list1 = inventory.OrderBy(d => d.description);   
foreach(var i in list1)
Console.WriteLine(i.itemNo +" "+i.qtyOnHand+" "+" "+i.description+" "+i.unitPrice);

          
      Console.WriteLine("2. To select description and unitPrice and sort by unitPrice.");
var list2 = inventory.Select(d => new
{
d.description,
d.unitPrice,
}).OrderBy(d => d.unitPrice);
  
foreach(var i in list2)
Console.WriteLine(i.description+" "+i.unitPrice);
    Console.WriteLine("3. To select description and total (qtyOnHand * unitPrice), sort by total. (Hint: Use let to create total.)");
var list3 = inventory.Select(d => new
{
Description= d.description,
Total= d.unitPrice * (double) d.qtyOnHand
})
.OrderBy(d => d.Total);
foreach(var i in list3)
Console.WriteLine(i.Description+" "+i.Total);
    Console.WriteLine("4. To display inventory objects that with unitPrice between $30 and $90, order by unitPrice in descending order.");
var list4 = inventory.Where(d => d.unitPrice>=30 && d.unitPrice<=90).OrderBy(d => d.unitPrice);
foreach(var i in list4)
Console.WriteLine(i.itemNo +" "+i.qtyOnHand+" "+" "+i.description+" "+i.unitPrice);
Console.WriteLine("5. To display inventory objects that convert the all description data to upper case, sort by description.");
var list5 = inventory.Select(d => new
{
d.itemNo,
d.qtyOnHand,
description = d.description.ToUpper(),
d.unitPrice

})
.OrderBy(d => d.description);
foreach(var i in list5)
Console.WriteLine(i.itemNo +" "+i.qtyOnHand+" " +i.description +" "+i.unitPrice);
}
}

output: