Advertisement
cynthiarez

delete

Oct 15th, 2019
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. package asd;
  2.  
  3. import java.io.*;
  4. import java.util.Scanner;
  5.  
  6. import javax.swing.JOptionPane;
  7.  
  8. public class java2 {
  9.  
  10. public static final String [] numofitem = {"100","200","300","400","500"};
  11. public static final String [] newnumofitem = {"600","700","800","900","1000"};
  12.  
  13. public static void main(String[] args) throws IOException {
  14. // TODO Auto-generated method stub
  15.  
  16.  
  17. WELCOME();
  18. int count = 0;
  19.  
  20. String [] option = { "Add Item", "Delete Item", "Update Item", "View Item", "Exit"};
  21.  
  22.  
  23. do {
  24. String opt = (String) (JOptionPane.showInputDialog(null, "Choose:", "Snackwise Inventory System", JOptionPane.QUESTION_MESSAGE, null, option, option[0]));
  25.  
  26. switch (opt)
  27. {
  28. case "Add Item" :
  29. additem();
  30. break;
  31.  
  32. case "Update Item" :
  33. updateitem();
  34. break;
  35.  
  36. case "Delete Item" :
  37. deleteitem();
  38. break;
  39.  
  40. case "View Item" :
  41. viewitem();
  42. break;
  43.  
  44. case "Exit" :
  45. System.exit(0);
  46. break;
  47.  
  48. }
  49. }
  50.  
  51. while (count == 0);
  52. }
  53.  
  54. public static void WELCOME() {
  55. JOptionPane.showMessageDialog(null, "Welcome to Snackwise Inventory System!");
  56. }
  57.  
  58.  
  59. public static void additem () throws IOException {
  60.  
  61. String item;
  62. int qty, price;
  63.  
  64. PrintWriter a = new PrintWriter(new FileWriter("fdi.txt", true));
  65.  
  66. do {
  67.  
  68. item = JOptionPane.showInputDialog("Please enter item: ");
  69. qty = Integer.parseInt((String)(JOptionPane.showInputDialog(null, "Choose quantity", "QTY", 1, null, numofitem, numofitem[0])));
  70. price = Integer.parseInt(JOptionPane.showInputDialog("Please enter the item price: "));
  71.  
  72.  
  73. a.println(item+ ":" +qty+ ":" +price+ ":");
  74.  
  75. JOptionPane.showMessageDialog(null, "Item has successfully added! ", "Snackwise Inventory System",1);
  76.  
  77. }
  78. while
  79. (JOptionPane.showConfirmDialog(null, "Add More Items? ")==0);
  80. a.close();
  81. }
  82.  
  83. public static void updateitem () throws IOException {
  84.  
  85. String str = "";
  86. String item, slct = "", update, new_item = "";
  87. int qty, price, new_qty, new_price;
  88. boolean found = false;
  89.  
  90. update = JOptionPane.showInputDialog("Select to Update");
  91. Scanner x = new Scanner (new FileReader("fdi.txt"));
  92. x.useDelimiter(":");
  93.  
  94.  
  95. while (x.hasNext()) {
  96.  
  97. item = x.next();
  98. qty = x.nextInt();
  99. price = x.nextInt();
  100. x.nextLine();
  101.  
  102. if(item.equalsIgnoreCase(update))
  103. {
  104. found = true;
  105. new_item = JOptionPane.showInputDialog(null, "New Item: ");
  106. new_qty = Integer.parseInt((String)(JOptionPane.showInputDialog(null, " Choose New Number of Items:", "NQTY",1, null, newnumofitem, newnumofitem[0])));
  107. new_price = Integer.parseInt(JOptionPane.showInputDialog(null, "New Price Item: "));
  108.  
  109. str += new_item+ ":" +new_qty+ ":" +new_price+ ":" +"\n";
  110.  
  111. }
  112. else
  113. str += item+ ":" +price+ ":" +slct+ ":" +qty+ ":" +"\n";
  114.  
  115. }
  116.  
  117. x.close();
  118.  
  119. PrintWriter b = new PrintWriter(new FileWriter("fdi.txt"));
  120. b.println(str);
  121. b.close();
  122.  
  123. if(!found)
  124. JOptionPane.showMessageDialog(null, "Item not found!", "Snackwise Inventory System",1 );
  125. else
  126. JOptionPane.showMessageDialog(null, "Item has successfully updated!");
  127.  
  128. }
  129.  
  130. public static void deleteitem () throws IOException {
  131.  
  132. String str = "";
  133. String item, slct = "", update, new_item = "";
  134. int qty, price, new_qty, new_price;
  135. boolean found1 = false;
  136.  
  137. update = JOptionPane.showInputDialog("Select to Delete");
  138. Scanner x = new Scanner (new FileReader("fdi.txt"));
  139. x.useDelimiter(":");
  140.  
  141. while (x.hasNext()) {
  142.  
  143. item = x.next();
  144. new_price = x.nextInt();
  145. new_qty = x.nextInt();
  146. x.nextLine();
  147.  
  148. if(!item.equalsIgnoreCase(update))
  149. {
  150. str += item+ ":" +new_price+ ":" +slct+ ":" +new_qty+ ":" +"\n";
  151. }
  152.  
  153. else found1 = true;
  154. }
  155.  
  156. PrintWriter b = new PrintWriter(new FileWriter("fdi.txt"));
  157. b.println(str);
  158. b.close();
  159. x.close();
  160.  
  161. if(found1)
  162. JOptionPane.showMessageDialog(null, "Item has successfully deleted!");
  163. else
  164. JOptionPane.showMessageDialog(null, "Item not found", "Snackwise Inventory System",1);
  165.  
  166. }
  167. public static void viewitem () throws IOException {
  168.  
  169. String str = "";
  170. Scanner x = new Scanner (new FileReader("fdi.txt"));
  171. x.useDelimiter(":");
  172. boolean found2 = false;
  173.  
  174. str = JOptionPane.showInputDialog("Select to View");
  175.  
  176.  
  177. while (x.hasNext()) {
  178.  
  179. String item = x.next();
  180. int qty1 = x.nextInt();
  181. int price = x.nextInt();
  182. x.nextLine();
  183.  
  184. if(item.equalsIgnoreCase(str))
  185. {
  186. found2 = true;
  187. JOptionPane.showMessageDialog(null, "Item: " + item + "\n"
  188. +"Number of Items: " + qty1 + "\n"
  189. +"Price Item: " + price + "\n", "Snackwise Inventory System", 1);
  190. break;
  191. }
  192. }
  193. if(!found2) {
  194. JOptionPane.showMessageDialog(null, "Item not found", "SnackWise Inventory System",1);
  195.  
  196. }
  197.  
  198. x.close();
  199.  
  200.  
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement