Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package asd;
- import java.io.*;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class java2 {
- public static final String [] numofitem = {"100","200","300","400","500"};
- public static final String [] newnumofitem = {"600","700","800","900","1000"};
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- WELCOME();
- int count = 0;
- String [] option = { "Add Item", "Delete Item", "Update Item", "View Item", "Exit"};
- do {
- String opt = (String) (JOptionPane.showInputDialog(null, "Choose:", "Snackwise Inventory System", JOptionPane.QUESTION_MESSAGE, null, option, option[0]));
- switch (opt)
- {
- case "Add Item" :
- additem();
- break;
- case "Update Item" :
- updateitem();
- break;
- case "Delete Item" :
- deleteitem();
- break;
- case "View Item" :
- viewitem();
- break;
- case "Exit" :
- System.exit(0);
- break;
- }
- }
- while (count == 0);
- }
- public static void WELCOME() {
- JOptionPane.showMessageDialog(null, "Welcome to Snackwise Inventory System!");
- }
- public static void additem () throws IOException {
- String item;
- int qty, price;
- PrintWriter a = new PrintWriter(new FileWriter("fdi.txt", true));
- do {
- item = JOptionPane.showInputDialog("Please enter item: ");
- qty = Integer.parseInt((String)(JOptionPane.showInputDialog(null, "Choose quantity", "QTY", 1, null, numofitem, numofitem[0])));
- price = Integer.parseInt(JOptionPane.showInputDialog("Please enter the item price: "));
- a.println(item+ ":" +qty+ ":" +price+ ":");
- JOptionPane.showMessageDialog(null, "Item has successfully added! ", "Snackwise Inventory System",1);
- }
- while
- (JOptionPane.showConfirmDialog(null, "Add More Items? ")==0);
- a.close();
- }
- public static void updateitem () throws IOException {
- String str = "";
- String item, slct = "", update, new_item = "";
- int qty, price, new_qty, new_price;
- boolean found = false;
- update = JOptionPane.showInputDialog("Select to Update");
- Scanner x = new Scanner (new FileReader("fdi.txt"));
- x.useDelimiter(":");
- while (x.hasNext()) {
- item = x.next();
- qty = x.nextInt();
- price = x.nextInt();
- x.nextLine();
- if(item.equalsIgnoreCase(update))
- {
- found = true;
- new_item = JOptionPane.showInputDialog(null, "New Item: ");
- new_qty = Integer.parseInt((String)(JOptionPane.showInputDialog(null, " Choose New Number of Items:", "NQTY",1, null, newnumofitem, newnumofitem[0])));
- new_price = Integer.parseInt(JOptionPane.showInputDialog(null, "New Price Item: "));
- str += new_item+ ":" +new_qty+ ":" +new_price+ ":" +"\n";
- }
- else
- str += item+ ":" +price+ ":" +slct+ ":" +qty+ ":" +"\n";
- }
- x.close();
- PrintWriter b = new PrintWriter(new FileWriter("fdi.txt"));
- b.println(str);
- b.close();
- if(!found)
- JOptionPane.showMessageDialog(null, "Item not found!", "Snackwise Inventory System",1 );
- else
- JOptionPane.showMessageDialog(null, "Item has successfully updated!");
- }
- public static void deleteitem () throws IOException {
- String str = "";
- String item, slct = "", update, new_item = "";
- int qty, price, new_qty, new_price;
- boolean found1 = false;
- update = JOptionPane.showInputDialog("Select to Delete");
- Scanner x = new Scanner (new FileReader("fdi.txt"));
- x.useDelimiter(":");
- while (x.hasNext()) {
- item = x.next();
- new_price = x.nextInt();
- new_qty = x.nextInt();
- x.nextLine();
- if(!item.equalsIgnoreCase(update))
- {
- str += item+ ":" +new_price+ ":" +slct+ ":" +new_qty+ ":" +"\n";
- }
- else found1 = true;
- }
- PrintWriter b = new PrintWriter(new FileWriter("fdi.txt"));
- b.println(str);
- b.close();
- x.close();
- if(found1)
- JOptionPane.showMessageDialog(null, "Item has successfully deleted!");
- else
- JOptionPane.showMessageDialog(null, "Item not found", "Snackwise Inventory System",1);
- }
- public static void viewitem () throws IOException {
- String str = "";
- Scanner x = new Scanner (new FileReader("fdi.txt"));
- x.useDelimiter(":");
- boolean found2 = false;
- str = JOptionPane.showInputDialog("Select to View");
- while (x.hasNext()) {
- String item = x.next();
- int qty1 = x.nextInt();
- int price = x.nextInt();
- x.nextLine();
- if(item.equalsIgnoreCase(str))
- {
- found2 = true;
- JOptionPane.showMessageDialog(null, "Item: " + item + "\n"
- +"Number of Items: " + qty1 + "\n"
- +"Price Item: " + price + "\n", "Snackwise Inventory System", 1);
- break;
- }
- }
- if(!found2) {
- JOptionPane.showMessageDialog(null, "Item not found", "SnackWise Inventory System",1);
- }
- x.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement