Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Vector;
- public class Main {
- Scanner scan = new Scanner(System.in);
- Vector<Items> vecItem = new Vector<Items>();
- public void clear()
- {
- for (int i = 0; i < 40; i++) {
- System.out.println();
- }
- }
- public void enter()
- {
- scan.nextLine();
- System.out.print("Press enter to Continue. . .");
- scan.nextLine();
- }
- public void menu()
- {
- System.out.println("Inventory Management System");
- System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=");
- System.out.println("1. View Items in Inventory");
- System.out.println("2. Add New Item to Inventory");
- System.out.println("3. Checkout Item from Inventory");
- System.out.println("4. Exit");
- System.out.print(">>> ");
- }
- public Main() {
- int choice = 0;
- do {
- clear();
- menu();
- choice = scan.nextInt();
- switch (choice) {
- case 1:
- if(vecItem.isEmpty())
- {
- clear();
- System.out.println("No Items in Inventory");
- enter();
- }
- else
- {
- clear();
- System.out.println("=================================");
- System.out.println("= List Of items in Inventory =");
- System.out.println("=================================");
- for (Items items : vecItem) {
- System.out.println("|" + items.getId() + "|" + items.getName() + "|" + items.getPrice() + "|" + items.getStock() +"|");
- }
- System.out.println("=================================");
- System.out.println();
- System.out.println();
- System.out.println();
- enter();
- }
- break;
- case 2:
- {
- clear();
- scan.nextLine();
- String tempid = "";
- String tempname = "";
- int tempprice = 0;
- int tempstock = 0;
- int WrongFormat = 0;
- do {
- WrongFormat = 0;
- System.out.print("Please Input Id [Must be exactly 5 numeric character] : ");
- tempid = scan.nextLine();
- WrongFormat = tempid.matches("^[0-9]+$") ? 0 : 1;
- } while (tempid.length() < 5 || tempid.length() > 5 || WrongFormat == 1);
- int WrongFormat1 = 0;
- int IdFound = 0;
- for (Items items : vecItem) {
- if(tempid.equals(items.getId()))
- {
- IdFound = 1;
- System.out.println("Item Already Exist");
- System.out.println("==================");
- System.out.println("Item ID : " + items.getId());
- System.out.println("Item Name : " + items.getName());
- System.out.println("Item Price : " + items.getPrice());
- System.out.println(">>Current item stock :" + items.getStock());
- do {
- WrongFormat1 = 0;
- try {
- System.out.print("Input Item Stock To be Added : ");
- tempstock = scan.nextInt();
- } catch (Exception e) {
- WrongFormat1 = 1;
- System.out.println("Must be numeric");
- }
- } while (WrongFormat1 == 1 || tempstock <= 0);
- tempstock = tempstock + items.getStock();
- items.setStock(tempstock);
- break;
- }
- }
- if(IdFound == 0)
- {
- do {
- System.out.print("Input Item Name [5 - 28] : ");
- tempname = scan.nextLine();
- } while (tempname.length() < 5 || tempname.length() > 28);
- do {
- WrongFormat1 = 0;
- try {
- System.out.print("Input Item Price [Min 10000] : ");
- tempprice = scan.nextInt();
- } catch (Exception e) {
- WrongFormat1 = 1;
- System.out.println("Must be numeric");
- }
- } while (tempprice < 10000 || WrongFormat1 == 1);
- do {
- WrongFormat1 = 0;
- try {
- System.out.print("Input Item Stock [Min 10] : ");
- tempstock = scan.nextInt();
- } catch (Exception e) {
- WrongFormat1 = 1;
- System.out.println("Must be numeric");
- }
- } while (tempstock > 10|| tempstock < 0 || WrongFormat1 == 1);
- vecItem.add(new Items(tempid, tempname, tempprice, tempstock));
- System.out.println();
- System.out.println();
- System.out.println("Success adding item to inventory");
- }
- enter();2
- break;
- }
- case 3:{
- if(vecItem.isEmpty())
- {
- System.out.println("No Items in Inventory");
- scan.nextLine();
- }
- else
- {
- System.out.println("=================================");
- System.out.println("= List Of items in Inventory =");
- System.out.println("=================================");
- for (Items items : vecItem) {
- System.out.println("|" + items.getId() + "|" + items.getName() + "|" + items.getPrice() + "|" + items.getStock() +"|");
- }
- System.out.println("=================================");
- int WrongFormat = 0;
- int WrongFormat1 = 0;
- String tempid = "";
- int tempstock= 0;
- do {
- WrongFormat = 0;
- System.out.print("Please Input Id [Must be exactly 5 numeric character] : ");
- tempid = scan.nextLine();
- for (Items items : vecItem) {
- if(tempid.equals(items.getId()))
- {
- do {
- WrongFormat1 = 0;
- try {
- System.out.print("Input Item Stock [1-10]: ");
- tempstock = scan.nextInt();
- } catch (Exception e) {
- WrongFormat1 = 1;
- System.out.println("Must be numeric");
- }
- } while (tempstock > 10 ||tempstock < 0 || WrongFormat1 == 1);
- if(items.getStock() - tempstock < 0)
- {
- System.out.println("Cannot Checkout, Item is out of Stock!");
- }
- else
- {
- items.setStock(items.getStock()-tempstock);
- System.out.println("You have sold " + tempstock + " of " + items.getName() +" with revenue Rp." + (items.getPrice()*tempstock));
- }
- scan.nextLine();
- break;
- }
- }
- } while (tempid.length() < 5 || tempid.length() > 5 || WrongFormat == 1);
- }
- break;
- }
- }
- } while (choice != 4);
- }
- public static void main(String[] args) {
- new Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement