Question
You are working for Shop@Home, a newly started e-commerce platform. They want to
handle users of the platform and orders made via console.
You are tasked to develop an application which can do the same according to the
conditions and constraints given.
Create class User with below attribute(s)
string - name
int - age
string - address
Create a class Order with below attribute(s)
string - name
datetime - orderdate
int - quantity (greater than 0)
int - price (should be greater than 0)
string - address
Make the attributes private, and generate necessary properties. Create a constructor
which takes name, orderdate, quantity, price and address parameters in the above
sequence. The constructor should set the value of attributes to parameter values inside
the constructor.
With a given set of users and orders as lists, write a program that will perform the following
tasks for the management of Shop@Home:
1. Take in new Orders. The details will be entered in the order of name, orderdate, quantity,
price and address, each in a new line. Orderdate should not be a future date, if itis print
“Order date should not be a future date", Quantity should be atleast 1, if itis less than one,
print "There should be atleast | item", Price should be greater than zero, else print "Price is
invalid", Upon successtul placement of order, print "New order has been placed successfully".
2. Display the 5 most expensive orders in descending order of price. Output should be of
the format " - On , item(s) worth to ", i.e,
“John - On 10/05/2019, 3 item(s) worth 15000 to Missouri".
3. Display all orders made by users to a different address than their home address, in order
of orderdate, Output should be of the format " ordered item(s) on
to instead of ", i.e., “John ordered 3 item(s) on
10/05/2019 to Missouri instead of Connecticut".Solution :
using System;
using System.Collections.Generic;
using System.Ling;
using System.Text;
using System. Threading. Tasks;
namespace Solution
{
cless Program
{
static void Main(stringf] args)
List userlist = new List();
User user! = new User("Aragom", 34, "Rivendell";
User user2 = new User("Legolas”, 29, "Mirkwood");
User user3 = new User( "Gimli, 31, "Helms Deep");
User user4 = new User("Boromir", 33, "Gondor");
User userS = new User("Gandal™, 69, "Lonely Mountain”);
userlist. Add(user1);
userlist:Add(user3);
userlist.Add(user4);
userlist. Add(user5);
List orderlist = new List 0)
f
Console. WriteLine("Order date should not be a future date");
Console ReadKey);
break;
i
int quantity = Convert.Tolnt32(Console.ReadLine());
y (quantity < 1)
Console. WriteLine("There should be atleast I item");
Console ReadKey():
break;
}
int price = Convert.ToInt32(Console.ReadLine();
if price < 1)
ft
Console. Writel ine("Price is invalid");
Console ReadKey();
break;
i
string address = Console,ReadLine();
Order order = new Order(name, orderdate, quantity, price, address);
orderlist.Add(order);
Console. WriteLine("New order has been placed successfully");
Console ReadKey();
break;
case 2:
List sortedlist! = orderlist, OrderByDescending(o—>o.Price).ToList();
‘foreach (Order 0 in sortedlist!.Take(5))
Console. WriteLine("{0} - On {1}, £2) item(s) worth {3} to {4}", o.Name,
0.Orderdate, 0.Quantity, o.Price, o.Address);
Console ReadKey();
break;
case 3:
List sortedlist2 — orderlist. OrderBy(o->o.Orderdate).ToList();
‘foreach (Order 0 in sortedlist2)
t
User user = userlist. Find(e => x.Name.Coniains(o.Name));
iffo.Address |= user.Address)
Console. WriteLine("{0} ordered {1} item(s) on {2} to {3} instead of {4}", o.Name,
o.Quantity, o.Orderdate, o.Address, user. Address);
Console ReadKey();
break;
i
Hendregion}
#/ Create class User as specified, Create constructor and use public properties.
region solution2
class User
é
private string name;
private int age;
private string address;
public string Name { get -> name; sel => name = value; }
public int Age { get => age; set => age = value; }
public string Address { gei => address; set => address = value; }
public User(string name, int age, string address)
i
Hendregion
#1 Create class Order as specified. Create constructor and use public properties,
frregion solution3
class Order
{
private string name;
private DateTime orderdate;
private int quantity;
private int price;
private string address;
public Order(string name, DateTime orderdate, int quantity, int price, string address)
this.quantity = quantity;
this price = price;
i
public string Name { get —> name; set => name = value; }
public DateTime Orderdate { get —> orderdate; set => orderdate ~ value; }
public int Quantity { get —> quantity; set —> quantity — value; }
public int Price { get => price; set => price = value; }
public string Address { get => address; set => address = value; }
tendregionOPA -DotNet-MS SQL- Highest ordered Product in terms of
Quantity
A retall shop has an automated order management system for Its customers. The shop maintains
the details of the customers, the products it sells and the orders placed by different customers
for the products separately.
Write an SQL query to display the customer,Product and order details (As shown in below
output data) , who ordered for the product which got ordered highest (in terms of quantity )
across all the orders in the order table
Customer ID, Customer Name,Product_Code, Product_Name , Quantity.
The output records are in the ascending order of quantity in the output records.
For more details refer to the below given table schema and sample data and Output
Schema:
You are provided 3 tables: CUSTOMER, PRODUCT AND ORDERS.
CUSTOMER
Name | Type Description
D INTEG || This is the first column. It is the primary
ER | key.
STRIN | This is the second column and is of length
NAME
G 30.
CONTACT. | STRIN
- This is the third column and is of length 10.
NO G
PRODUCT
Name Type Description
PRODUCT_C | STRIN | This is the first column. It is the primary key and
ODE G | has length of 10.
PRODUCT.N | STRIN po
AME g___ Thisis the second column and is of length 20.INTEG
UNIT_PRICE ER This is the third column .
Name |} Type Description
ORDER| | STRIN | This is the first column. It is the primary key and has
D G __| length of 10.
QUANTIT | STRIN ce «,
This is the second column and is of length 20.
Y G
ORDER_D
7 DATE This is the third column.
ATE
cD INTEG This is the fourth column. It is a foreign key with
= ER references to ID of the CUSTOMER table.
PID STRIN This is the fifth column. It is a foreign key with
G references to PRODUCT_CODE of the PRODUCT table.
‘Sample Data Tables
CUSTOMERS
ID NAME CONTACT_NO
1 Matt 943511234
2 John 6654342312
3 Ji = 8876129813
PRODUCT
PRODUCT_CODE PRODUCT_NAME UNIT_PRICE
piot 20
poz 10
p10 40
pi04 Water Color 100INTEG
UNIT_PRICE ER This is the third column .
Name |} Type Description
ORDER| | STRIN | This is the first column. It is the primary key and has
D G __| length of 10.
QUANTIT | STRIN ce «,
This is the second column and is of length 20.
Y G
ORDER_D
7 DATE This is the third column.
ATE
cD INTEG This is the fourth column. It is a foreign key with
= ER references to ID of the CUSTOMER table.
PID STRIN This is the fifth column. It is a foreign key with
G references to PRODUCT_CODE of the PRODUCT table.
‘Sample Data Tables
CUSTOMERS
ID NAME CONTACT_NO
1 Matt 943511234
2 John 6654342312
3 Ji = 8876129813
PRODUCT
PRODUCT_CODE PRODUCT_NAME UNIT_PRICE
piot 20
poz 10
p10 40
pi04 Water Color 100ORDER _ID QUANTITY ORDER DATE CID PID
1011 30 2018-01-09 1 p02
1012 300 2018-02-09 1 pt0z
1013 200 2018-02-09 3 pi02
11 100 2018-02-09 2 p103
1016 20 2018-02-15 2 p104
le
1 Matt p102 Eraser 30
1 Matt p102 Eraser 300
3 jill p102 Eraser 200
Explanation
Product with ID : p102 ordered for 530 In quantity across all the orders of all
products, hence which Is the highest ordered product in Quantity.
Lets find out, who odered this highest ordered product
Matt(ID : 1) has ordered for product with product_code p102 for quantity 30
and 300 respectively, which was ordered highest across all the orders.
Jill (Id: 3) has ordered for product with product_code p102 for Quantity 200
Hence the records pertaining to Matt and jill displayed in the output
Solution:
SELECT ID, NAME ,PRODUCT_CODE,PRODUCT_NAME , A.Quantity FROM (SELECT
DISTINCT(C_ID),P_ID,Quantity FROM ORDERS WHERE P_ID=
(SELECT TOP 1 P_ID FROM ORDERS GROUP BY P_ID ORDER BY
SUM(QUANTITY) desc) )A,
PRODUCT,CUSTOMER WHERE A.P_ID=PRODUCT_CODE and
A.C_ID=CUSTOMER.ID order by A.Quantity;