C# Create an application named order demo that declares and uses Order objects. The order class performs order processing of a single item that sells for 19.95 each. The class has four variable fields that hold an order number, customer name, quantity ordered, and total price. Include public get and set accessors for each field except total price field; that field is calculated as quantity ordered times unit price (19.95) whenever quantity is set, so it needs only a get accessor. Also create the following for the class: An Equals () method that determines two Orders are equal if they have the same order number, A GetHashCode () method that returns the order number, A ToString () method that returns a string containing all order information. The OrderDemo application declares a few Order objects and sets their values. Make sure to create at least two orders with the same order number. Display the string from the ToString() for each order. Write a method that compares two orders at a t

The OrderDemo application is a C# program that focuses on order processing using the Order object. The Order class is responsible for handling the processing of a single item that is sold for $19.95 each. It contains four variable fields: order number, customer name, quantity ordered, and total price.

To access and modify the fields, public get and set accessors are included for each field, except for the total price field. The total price is calculated by multiplying the quantity ordered with the unit price of $19.95. Therefore, the total price field only needs a get accessor.

Additionally, the Order class should include the following methods:

1. Equals() method: This method determines if two orders are equal by comparing their order numbers.

2. GetHashCode() method: This method returns the order number.

3. ToString() method: This method returns a string containing all the information about the order.

In the OrderDemo application, several Order objects are declared, and their values are set. It is important to create at least two orders with the same order number to demonstrate the equals functionality. The ToString() method is called for each order to display the order information.

Furthermore, it is required to write a method that compares two orders at a time. This method will allow for the comparison of two orders based on their order numbers or any other specific criteria.

To implement this functionality, the code for the OrderDemo application can be structured as follows:

“`c#
using System;
using System.Collections.Generic;

class Order
{
public int OrderNumber { get; set; }
public string CustomerName { get; set; }
public int QuantityOrdered { get; set; }
public double TotalPrice => QuantityOrdered * 19.95;

public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;

Order otherOrder = (Order)obj;
return OrderNumber == otherOrder.OrderNumber;
}

public override int GetHashCode()
{
return OrderNumber;
}

public override string ToString()
{
return $”Order Number: {OrderNumber}nCustomer Name: {CustomerName}nQuantity Ordered: {QuantityOrdered}nTotal Price: {TotalPrice}”;
}
}

class OrderDemo
{
static void Main()
{
Order order1 = new Order { OrderNumber = 1, CustomerName = “John Smith”, QuantityOrdered = 5 };
Order order2 = new Order { OrderNumber = 2, CustomerName = “Jane Doe”, QuantityOrdered = 3 };
Order order3 = new Order { OrderNumber = 1, CustomerName = “Michael Johnson”, QuantityOrdered = 2 };

List orders = new List { order1, order2, order3 };

foreach (Order order in orders)
{
Console.WriteLine(order.ToString());
Console.WriteLine();
}

CompareOrders(order1, order2);
}

static void CompareOrders(Order order1, Order order2)
{
if (order1.Equals(order2))
{
Console.WriteLine(“The orders have the same order number.”);
}
else
{
Console.WriteLine(“The orders have different order numbers.”);
}
}
}
“`

In this implementation, the Order class has the required fields and corresponding accessors. The Equals() method compares two orders based on their order numbers. The GetHashCode() method returns the order number, and the ToString() method formats the order information into a string representation.

In the Main() method of the OrderDemo class, several Order objects are created and added to a List. The ToString() method is called for each order to display its information. Finally, the CompareOrders() method is used to compare two orders and display whether they have the same order number or not.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer