Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class MyInventory{
- int id[] = new int[30];
- String name[] = new String[30];
- int quantity[] = new int[30];
- int count = 0;
- }
- interface AddItem{
- public void addItem(String name);
- public void addItem(int qty);
- public void addItem(int qty, int id);
- }
- interface RemoveItem{
- public void delete(int id);
- }
- interface DisplayItems{
- public void displayAll();
- public void display();
- public void displayQuantity(int id);
- }
- class Inventory{
- public static void main(String args[]){
- Scanner sc = new Scanner(System.in);
- while(true){
- System.out.println("\n1.Log in as Manager\n2.Exit");
- switch(sc.nextInt()){
- case 1 :
- System.out.print("Enter your password: ");
- if("S22".equals(sc.next()))
- new Manager().call();
- else System.out.println("Wrong Password.");
- break;
- case 0:
- return;
- }
- }
- }
- }
- class Manager extends MyInventory implements AddItem,RemoveItem,DisplayItems{
- public void addItem(String n){
- name[count] = n;
- }
- public void addItem(int qty){
- quantity[count] = qty;
- }
- public void addItem(int qty, int count){
- quantity[count]+=qty;
- }
- public void delete(int count){
- quantity[count]=0;
- }
- public void displayAll(){
- System.out.println("ID\tNAME\tQUANTITY");
- for(int i=0;i<count;i++)
- System.out.println(+id[i]+"\t"+name[i]+"\t"+quantity[i]);
- }
- public void display(){
- System.out.println("ID\tNAME\tQUANTITY");
- for(int i=0;i<count;i++)
- if(quantity[i]!=0)
- System.out.println(+id[i]+"\t"+name[i]+"\t"+quantity[i]);
- }
- public void displayQuantity(int id){
- System.out.println("ID\tNAME\tQUANTITY");
- System.out.println(+id+" \t"+name[id]+"\t"+quantity[id]);
- }
- void call(){
- Scanner sc = new Scanner(System.in);
- int quan,id;
- String name;
- while(true){
- System.out.println("\n1.New Item 2.Remove Item 3.Display Items in Stock\n4.Display All Items 5.Update Quantity 6.Display Quantity\n0.Log out");
- int choice = sc.nextInt();
- switch(choice){
- case 1:
- System.out.print("Name of new item: ");
- addItem(sc.next());
- System.out.print("Enter the quantity of the new item: ");
- addItem(sc.nextInt());
- count++;
- break;
- case 2:
- System.out.print("Enter Product Id: ");
- delete(sc.nextInt());
- break;
- case 3:
- display();
- break;
- case 4:
- displayAll();
- break;
- case 5:
- System.out.print("Enter Product Id: ");
- id = sc.nextInt();
- System.out.print("Enter quantity of product: ");
- quan = sc.nextInt();
- addItem(quan,id);
- break;
- case 6:
- System.out.println("Enter Product Id: ");
- displayQuantity(sc.nextInt());
- break;
- case 0: return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement