Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package storemanagement;
- import java.util.*;
- import java.util.Scanner;
- public class StoreManagement {
- static Scanner console=new Scanner(System.in);
- static ArrayList<String> pname= new ArrayList<String>();
- static ArrayList<Float> pprice= new ArrayList<Float>();
- static ArrayList<Integer> pqty= new ArrayList<Integer>();
- static boolean x=true;
- static char option;
- public static void main(String[] args) {
- //login();
- menu();
- }
- public static void login(){
- String username;
- String password;
- System.out.println("\t\t\t\t\tLog in ");
- System.out.println("\t\t\t\t************************");
- System.out.print("\t\t\t\tUsername: ");
- username = console.nextLine();
- System.out.print("\t\t\t\tPassword: ");
- password = console.nextLine();
- System.out.println("\t\t\t\t************************");
- users check = new users(username, password);
- if(check.auth())
- System.out.println("You are logged in");
- }
- public static void menu(){
- int choice;
- do{
- System.out.println("\t\t\t\t\t\tStore Management");
- System.out.println("\t\t\t\t*********************************************");
- System.out.println("\t\t\t\t* [1] Add Items\t\t\t\t *"
- + "\n\t\t\t\t* [2] Edit Items\t\t\t *"
- + "\n\t\t\t\t* [3] Search Items\t\t\t *"
- + "\n\t\t\t\t* [4] Delete Items\t\t\t *"
- + "\n\t\t\t\t* [5] Display the Lists of Items\t *"
- + "\n\t\t\t\t* [6] Exit\t\t\t\t *");
- System.out.println("\t\t\t\t*********************************************");
- System.out.print("\t\t\t\tEnter Option: ");
- choice=console.nextInt();
- switch(choice)
- {
- case 1:
- add();
- break;
- case 2:
- edit();
- break;
- case 3:
- search();
- break;
- case 4:
- delete();
- break;
- case 5:
- display();
- break;
- case 6:
- toexit();
- break;
- default:
- System.out.println("\t\t\t\tInvalid input");
- break;
- }
- System.out.print("\t\t\t\tGo back to Menu? [y/n]: ");
- option=console.next().charAt(0);
- if( option=='n'){
- x=false;
- }
- }while(x=true);
- }
- public static void add(){
- String name;
- Float price;
- int qty;
- do{
- try
- {
- System.out.println("\t\t\t\t*********************************************");
- System.out.print("\t\t\t\t Quantity of Products to Add: ");
- qty=console.nextInt();
- System.out.print("\t\t\t\t Product Name: ");
- name=console.next();
- if(" ".equalsIgnoreCase(name))
- System.out.print("\t\t\t\t Please Enter a Name: ");
- else{
- pname.add(name);
- pqty.add(qty);
- }
- System.out.print("\t\t\t\t Product Price: ");
- price=console.nextFloat();
- if(price==-1)
- System.out.print("\t\t\t\t Please Enter a Price");
- else
- pprice.add(price);
- }
- catch(InputMismatchException exception)
- {
- System.out.println("\t\t\t\t Invalid Input");
- }
- System.out.println("\t\t\t\t*********************************************");
- System.out.print("\t\t\t\t Add More Items? [y/n]: ");
- option=console.next().charAt(0);
- if( option=='n'){
- x=false;
- }
- }while(x!=false);
- }
- public static void display(){
- int choice1;
- do{
- System.out.println("\t\t\t\t\t\tSee Lists: ");
- System.out.println("\t\t\t\t--------------------------------------------------");
- System.out.println("\t\t\t\t| [1] Sorted Display By Price\t\t\t |"
- + "\n\t\t\t\t| [2] Unsorted Display Based on User Input\t |"
- + "\n\t\t\t\t| [3] Go Back to Menu \t\t\t\t|");
- System.out.println("\t\t\t\t--------------------------------------------------");
- System.out.print("\t\t\t\tEnter Option: ");
- choice1=console.nextInt();
- switch(choice1)
- {
- case 1:
- Float[] pricearray=pprice.toArray(new Float[pprice.size()]);
- String[] namearray = pname.toArray(new String[pname.size()]);
- Integer[] qtyarray = pqty.toArray(new Integer[pqty.size()]);
- Object[] object=sort(pricearray,namearray,qtyarray);
- Float[] price = (Float[]) object[0];
- String[] name = (String[]) object[1];
- Integer[] qty = (Integer[]) object[2];
- for(int i=0;i<name.length;i++){
- System.out.println("\t\t\t\t\t\tProducts : ");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- System.out.println("\t\t\t\t| NAME\t\t\tPRICE\t\t QUANTITY\t |");
- System.out.println("\t\t\t\t| "+name[i]+"\t\t\t"+ price[i]+"\t\t\t"+qty[i]+"\t |");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- }
- System.out.print("Go back to Display Lists: [y/n]");
- option=console.next().charAt(0);
- if(option=='y')
- display();
- else if(option=='n')
- menu();
- break;
- case 2:
- if(pname.isEmpty())
- System.out.println("\t\t\t\t\t\tNo Added Items");
- else{
- System.out.println("\t\t\t\t\t\tProducts : ");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- System.out.println("\t\t\t\t| NAME\t\t\tPRICE\t\t QUANTITY\t |");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- for(int i=0;i<pname.size();i++){
- System.out.println("\t\t\t\t| "+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i)+"\t |");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- }
- }
- break;
- case 3:
- menu();
- break;
- default:
- System.out.println("\t\t\t\tInvalid input");
- break;
- }
- }while((choice1!=1)&&(choice1!=2)&&(choice1!=3));
- }
- public static Object[] sort(Float[] p, String[] n, Integer[] x){
- int minIndex, tempQty;
- Float tempPrice;
- String tempName;
- for(int i=0;i<p.length-1;i++){
- minIndex=i;
- for(int j=i+1;j<p.length;j++){
- if(p[j]<p[minIndex]){
- minIndex=j;
- }
- }
- tempPrice=p[minIndex];
- tempName = n[minIndex];
- tempQty=x[minIndex];
- p[minIndex]=p[i];
- n[minIndex]=n[i];
- x[minIndex]=x[i];
- p[i]=tempPrice;
- n[i]=tempName;
- x[i]=tempQty;
- }
- return new Object[]{p,n,x};
- }
- public static void search(){
- String sproduct;
- System.out.println("\t\t\t\t\t\tSEARCH: ");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\t Product Name: ");
- sproduct=console.next();
- System.out.println("\t\t\t\t---------------------------------------------");
- if(pname.contains(sproduct)){
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.println("\t\t\t\t\t\tProduct Found:");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.println("\t\t\t\t NAME\t\t\tPRICE\t\t\tQUANTITY");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- for(int i=0;i<pname.size();i++){
- if(sproduct.equals(pname.get(i))){
- System.out.println("\t\t\t\t"+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i));
- System.out.println("\t\t\t\t----------------------------------------------------------");
- }
- }
- }
- else
- System.out.println("\t\t\t\t No "+sproduct+" Product in the List !");
- }
- public static void edit(){
- String sproduct, eproduct;
- Float oprice;
- int choice;
- int qty;
- int index = 0;
- int pindex;
- int qindex;
- do{
- System.out.println("EDIT: ");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.println("\t\t\t\t|[1] Edit Item\t\t|");
- System.out.println("\t\t\t\t|[2] Go Back to Menu\t\t\t\t|");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tEnter Option: ");
- choice=console.nextInt();
- switch(choice)
- {
- case 1:
- System.out.println("\t\t\t\t\t\tEDIT: ");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\t Search Product to Edit: ");
- sproduct=console.next();
- System.out.println("\t\t\t\t---------------------------------------------");
- if(pname.contains(sproduct)){
- System.out.println("\t\t\t\t\t\tProduct Found:");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.println("\t\t\t\t NAME\t\t\tPRICE\t\t\tQUANTITY");
- System.out.println("\t\t\t\t----------------------------------------------------------");
- for(int i=0;i<pname.size();i++){
- if(sproduct.equals(pname.get(i))){
- index=index+i;
- System.out.println("\t\t\t\t"+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i));
- System.out.println("\t\t\t\t----------------------------------------------------------");
- }
- }
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tType New Name to be replaced: ");
- eproduct=console.next();
- System.out.println("\t\t\t\t---------------------------------------------");
- pname.set(index,eproduct);
- System.out.println("\t\t\t\tDone!");
- System.out.print("\t\t\t\tDo you want to edit also the price ?[y/n] : ");
- option=console.next().charAt(0);
- switch (option) {
- case 'n':
- System.out.print("\t\t\t\tDo you want to edit also the quantity ?[y/n] : ");
- option=console.next().charAt(0);
- if(option=='n'){
- System.out.println("\t\t\t\tGoing Back To Menu");
- menu();
- }
- else if(option=='y'){
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tType New Quantity to be replaced: ");
- qty=console.nextInt();
- System.out.println("\t\t\t\t---------------------------------------------");
- qindex=+index;
- pqty.set(qindex,qty);
- System.out.println("\t\t\t\tDone!");
- }
- break;
- case 'y':
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tType New Price to be replaced: ");
- oprice=console.nextFloat();
- System.out.println("\t\t\t\t---------------------------------------------");
- pindex=+index;
- pprice.set(pindex,oprice);
- System.out.println("\t\t\t\tDone!");
- System.out.print("\t\t\t\tDo you want to edit also the quantity ?[y/n] : ");
- option=console.next().charAt(0);
- if(option=='n'){
- System.out.println("\t\t\t\tGoing Back To Menu");
- menu();
- }
- else if(option=='y'){
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tType New Quantity to be replaced: ");
- qty=console.nextInt();
- System.out.println("\t\t\t\t---------------------------------------------");
- qindex=+index;
- pqty.set(qindex,qty);
- System.out.println("\t\t\t\tDone!");
- break;
- }
- break;
- case 2:
- menu();
- break;
- default:
- System.out.println("\t\t\t\t Invalid input");
- break;
- }
- }
- }
- }while((choice!=1)&&(choice!=2));
- }
- public static void delete(){
- int choice;
- String pdelete;
- System.out.println("DELETE: ");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.println("\t\t\t\t|[1] Delete Specific Item\t\t|");
- System.out.println("\t\t\t\t|[2] Delete All\t\t\t\t|");
- System.out.println("\t\t\t\t---------------------------------------------");
- System.out.print("\t\t\t\tEnter Option: ");
- choice=console.nextInt();
- switch(choice)
- {
- case 1:
- System.out.print("\t\t\t\tEnter Product You Want to Delete: ");
- pdelete=console.next();
- if(pname.contains(pdelete)){
- for(int i=0;i<pname.size();i++){
- if(pdelete.equals(pname.get(i))){
- pname.remove(pname.get(i));
- pprice.remove(pprice.get(i));
- pqty.remove(pqty.get(i));
- System.out.println("\t\t\t\tDone!");
- }
- }
- }
- else
- System.out.println("\t\t\t\tNo "+pdelete+" product in th List !");
- break;
- case 2:
- System.out.println("\t\t\t\t Items Deleted!");
- pname.clear();
- pprice.clear();
- pqty.clear();
- break;
- default:
- System.out.println("\t\t\t\t Invalid input");
- break;
- }
- }
- public static void toexit(){
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement