You are on page 1of 7

MOHAMMAD ALI JINNAH UNIVERSITY

OBJECT OREINTED PROGRAMMING


(OOP)
Graded Assignment – 5

Name: Azhar Ahmed


ID: SP18-MCSW-0003
Course: MCS
Question # 01:
Consider a scenario of a software implemented in super store where there are multiple type of items. Customer visits the store and can
place an order with the combination of different items, can generate bill, review order, modify order (add/delete items) and have
attributes name, id, gender, age etc. while the item may have item_id, name and price per item attributes, an order may have a list
containing items and their quantities purchased by customer, whereas the admin/owner may have store name, list of all customers and
be able to send updates to customer when there are sales/discounts available, can add / delete items, can change prices of items, give
discounts e.g. 20% off etc. (Note: discount mean subtracting x% from original price of all item)
The flow of program should be like:
- When customer interacts with the system, it will ask the customer for basic info like name, gender, age
- Then display a list/table containing name price and available quantity of an item, asking the user to enter desire item id and quantity
(user can select multiple items so maintain a list, later on this list will be used to generate bill)
- Finally user can review and confirm the product and bill will be displayed to him/her
Draw a UML class diagram for the scenario, also write code for it along with proper main method.
NOTE: perform all operations in main method that a customer and admin can perform.

UML CLASS DIAGRAM

Items

- item_id : String
- name : String
- price : int

+ Items ( String : item_id, String :


name, int : price, Store s )

Customers

- Customers_id : String
- name : String
Super Store - gender : String
- age : int
- discount : int
- name + Customers ( String : customers_id,
- total_amount String : name, String : gender, int :
- Item : ArrayList<Items> age)
- Customer : ArrayList<Customers>
- Order : ArrayList<Orders>

+ AddItems : Items Orders


+ AddCustomers : Customers
+ OrderList : Orders - cust : Customers
+ Calculate_bill: Orders - Item : ArrayList<Items>
+ GenerateInvoice: name, Orders

+ Orders ( Customers : cust,


ArrayList<Items> item)
CODE
Main.java
import java.util.ArrayList;
import java.util.Scanner;

public class Main


{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String answer = null;
int user_answer;

System.out.printf("\n");
System.out.printf("\n");
System.out.printf("\n");

SuperStore store;

String input_superstore_name;
String input_discount;

Items Item;

String input_item_id;
String input_item_name;
String input_item_price;

Customers Custom;

String input_cust_id;
String input_cust_name;
String input_cust_gender;
String input_cust_age;

ArrayList<Items> OrderItem = new ArrayList<Items>();

do {
System.out.printf("Store Name : ");
input_superstore_name = input.next();
System.out.printf("Discount Percentage : ");
input_discount = input.next();

System.out.printf("\n");
System.out.printf("\n");
System.out.printf("\n");

store = new SuperStore(input_superstore_name, Integer.parseInt(input_discount));

do {
System.out.printf(" --** Welcome to : " + store.getName() + "**-- \n");
System.out.printf(" -Select your desired operation from the Menu- \n");
System.out.printf("------------------------------------------------- \n");
System.out.printf("[1]:- Items Management.\n");
System.out.printf("[2]:- Order Booking.\n");
System.out.printf("[3]:- Exit.\n\n");

System.out.printf("Select any choice number : ");


user_answer = input.nextInt();

switch (user_answer) {
case 1: {
System.out.printf("Item List : \n");

do {
System.out.printf("ID : ");
input_item_id = input.next();

System.out.printf("Name : ");
input_item_name = input.next();

System.out.printf("Price : ");
input_item_price = input.next();

Item = new Items(input_item_id, input_item_name, Integer.parseInt(input_item_price),


store);

store.AddItems(Item);

System.out.println("Would you like to add more item ? [Y/N]");


answer = input.next();
}
while (answer.toLowerCase().equals("y"));

break;
}
case 2: {

do {

System.out.printf("Please Enter Customer Information : \n ");

System.out.printf("ID : ");
input_cust_id = input.next();

System.out.printf("Name : ");
input_cust_name = input.next();

System.out.printf("Gender : ");
input_cust_gender = input.next();

System.out.printf("Age : ");
input_cust_age = input.next();

Custom = new Customers(input_cust_id, input_cust_name, input_cust_gender,


Integer.parseInt(input_cust_age));

System.out.printf("Items List \n");

for (Items i : store.Item) {


System.out.printf(i.getItem_id() + " : " + i.getName() + " : " + i.getPrice() +
"\n");
}

do {
System.out.printf("Please Select Item : ");
input_item_id = input.next();

for (Items item : store.Item) {


if (item.getItem_id().equals(input_item_id)) {
OrderItem.add(item);

}
}
System.out.println("Would you like to select more item ? [Y/N]");
answer = input.next();
}
while (answer.toLowerCase().equals("y"));

Orders Order = new Orders(Custom, OrderItem);

store.Calculate_bill(Order);
store.OrderList(Order);

store.GenerateInvoice(store.getName(), Order);

System.out.println("Would you like to take more order ? [Y/N]");


answer = input.next();
}
while (answer.toLowerCase().equals("y"));

}
case 3: {
break;
}

System.out.println("Would you back to main menu [Y/N]");


answer = input.next();

}
while (answer.toLowerCase().equals("y"));

System.out.println("Would you create more store [Y/N]");


answer = input.next();
}
while (answer.toLowerCase().equals("y"));

}
}
SuperStore.java
import java.util.Scanner;
import java.util.ArrayList;

public class SuperStore


{
private int discount;
private String name;
ArrayList<Items> Item = new ArrayList<Items>();
ArrayList<Customers> Customer = new ArrayList<Customers>();
ArrayList<Orders> Order = new ArrayList<Orders>();
private int total_amount = 0;

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public SuperStore() {
}

public SuperStore(String name, int discount) {


this.name = name;
this.discount = discount;
}

public int getDiscount() {


return discount;
}

public void setDiscount(int discount) {


this.discount = discount;
}

public ArrayList<Items> getItem() {


return Item;
}

public void setItem(ArrayList<Items> item) {


Item = item;
}

public ArrayList<Customers> getCustomer() {


return Customer;
}

public void setCustomer(ArrayList<Customers> customer) {


Customer = customer;
}

public ArrayList<Orders> getOrder() {


return Order;
}

public void setOrder(ArrayList<Orders> order) {


Order = order;
}

public void AddItems(Items I)


{
this.Item.add(I);

public void AddCustomers(Customers C)


{
this.Customer.add(C);

}
public void OrderList(Orders O)
{
this.Order.add(O);

}
public Orders Calculate_bill(Orders O)
{
for (Items i : O.getItem())
{
total_amount = total_amount + i.getPrice();
}
total_amount = total_amount - discount;
O.setTotal_amount(total_amount);

return O;
}
public void GenerateInvoice(String name, Orders O)
{
System.out.println(O.getCust().getName() + name + " Bill : \n");

System.out.printf(O.getCust().getName() + "\n");

for (Items i : O.getItem())


{
System.out.printf(i.getItem_id() + " : " + i.getName() + " : " + i.getPrice() + "\n");
}
}

}
}

Items.java
public class Items
{
private String item_id;
private String name;
private int price;

public Items() {
}

public Items(String item_id, String name, int price, SuperStore s)


{
this.item_id = item_id;
this.name = name;
this.price = price;

s.AddItems(this);

public String getItem_id()


{
return item_id;
}
public void setItem_id(String item_id)
{
this.item_id = item_id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getPrice()
{
return price;
}
public void setPrice(int price)
{
this.price = price;
}

Customers.java
public class Customers
{
private String Customers_id;
private String name;
private String gender;
private int age;

public Customers()
{
}
public Customers(String customers_id, String name, String gender, int age)
{
Customers_id = customers_id;
this.name = name;
this.gender = gender;
this.age = age;
}

public String getCustomers_id()


{
return Customers_id;
}
public void setCustomers_id(String customers_id)
{
Customers_id = customers_id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getGender()
{
return gender;
}
public void setGender(String gender)
{
this.gender = gender;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}

Orders.java
import java.util.ArrayList;

public class Orders


{
private Customers cust;
ArrayList<Items> Item = new ArrayList<Items>();

public Orders()
{
}
public Orders(Customers cust, ArrayList<Items> item)
{
this.cust = cust;
Item = item;
}

public Customers getCust()


{
return cust;
}
public void setCust(Customers cust)
{
this.cust = cust;
}
public ArrayList<Items> getItem()
{
return Item;
}
public void setItem(ArrayList<Items> item)
{
Item = item;
}
}