Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. import java.util.Vector;
  4.  
  5. public class Main {
  6.  
  7. Scanner scan = new Scanner(System.in);
  8. Vector<Items> vecItem = new Vector<Items>();
  9.  
  10. public void clear()
  11. {
  12. for (int i = 0; i < 40; i++) {
  13. System.out.println();
  14. }
  15. }
  16.  
  17. public void enter()
  18. {
  19. scan.nextLine();
  20. System.out.print("Press enter to Continue. . .");
  21. scan.nextLine();
  22. }
  23.  
  24. public void menu()
  25. {
  26. System.out.println("Inventory Management System");
  27. System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=");
  28. System.out.println("1. View Items in Inventory");
  29. System.out.println("2. Add New Item to Inventory");
  30. System.out.println("3. Checkout Item from Inventory");
  31. System.out.println("4. Exit");
  32. System.out.print(">>> ");
  33.  
  34. }
  35. public Main() {
  36. int choice = 0;
  37. do {
  38. clear();
  39. menu();
  40. choice = scan.nextInt();
  41. switch (choice) {
  42. case 1:
  43. if(vecItem.isEmpty())
  44. {
  45. clear();
  46. System.out.println("No Items in Inventory");
  47. enter();
  48. }
  49. else
  50. {
  51. clear();
  52. System.out.println("=================================");
  53. System.out.println("= List Of items in Inventory =");
  54. System.out.println("=================================");
  55. for (Items items : vecItem) {
  56. System.out.println("|" + items.getId() + "|" + items.getName() + "|" + items.getPrice() + "|" + items.getStock() +"|");
  57. }
  58. System.out.println("=================================");
  59. System.out.println();
  60. System.out.println();
  61. System.out.println();
  62. enter();
  63. }
  64.  
  65.  
  66. break;
  67. case 2:
  68. {
  69. clear();
  70. scan.nextLine();
  71. String tempid = "";
  72. String tempname = "";
  73. int tempprice = 0;
  74. int tempstock = 0;
  75.  
  76. int WrongFormat = 0;
  77. do {
  78. WrongFormat = 0;
  79. System.out.print("Please Input Id [Must be exactly 5 numeric character] : ");
  80. tempid = scan.nextLine();
  81. WrongFormat = tempid.matches("^[0-9]+$") ? 0 : 1;
  82. } while (tempid.length() < 5 || tempid.length() > 5 || WrongFormat == 1);
  83.  
  84. int WrongFormat1 = 0;
  85. int IdFound = 0;
  86. for (Items items : vecItem) {
  87. if(tempid.equals(items.getId()))
  88. {
  89. IdFound = 1;
  90. System.out.println("Item Already Exist");
  91. System.out.println("==================");
  92. System.out.println("Item ID : " + items.getId());
  93. System.out.println("Item Name : " + items.getName());
  94. System.out.println("Item Price : " + items.getPrice());
  95. System.out.println(">>Current item stock :" + items.getStock());
  96. do {
  97. WrongFormat1 = 0;
  98. try {
  99. System.out.print("Input Item Stock To be Added : ");
  100. tempstock = scan.nextInt();
  101. } catch (Exception e) {
  102. WrongFormat1 = 1;
  103. System.out.println("Must be numeric");
  104. }
  105.  
  106. } while (WrongFormat1 == 1 || tempstock <= 0);
  107. tempstock = tempstock + items.getStock();
  108. items.setStock(tempstock);
  109. break;
  110. }
  111. }
  112. if(IdFound == 0)
  113. {
  114. do {
  115. System.out.print("Input Item Name [5 - 28] : ");
  116. tempname = scan.nextLine();
  117. } while (tempname.length() < 5 || tempname.length() > 28);
  118. do {
  119. WrongFormat1 = 0;
  120. try {
  121. System.out.print("Input Item Price [Min 10000] : ");
  122. tempprice = scan.nextInt();
  123. } catch (Exception e) {
  124. WrongFormat1 = 1;
  125. System.out.println("Must be numeric");
  126. }
  127. } while (tempprice < 10000 || WrongFormat1 == 1);
  128. do {
  129. WrongFormat1 = 0;
  130. try {
  131. System.out.print("Input Item Stock [Min 10] : ");
  132. tempstock = scan.nextInt();
  133. } catch (Exception e) {
  134. WrongFormat1 = 1;
  135. System.out.println("Must be numeric");
  136. }
  137. } while (tempstock > 10|| tempstock < 0 || WrongFormat1 == 1);
  138. vecItem.add(new Items(tempid, tempname, tempprice, tempstock));
  139. System.out.println();
  140. System.out.println();
  141. System.out.println("Success adding item to inventory");
  142. }
  143. enter();2
  144. break;
  145. }
  146. case 3:{
  147. if(vecItem.isEmpty())
  148. {
  149. System.out.println("No Items in Inventory");
  150. scan.nextLine();
  151. }
  152. else
  153. {
  154.  
  155. System.out.println("=================================");
  156. System.out.println("= List Of items in Inventory =");
  157. System.out.println("=================================");
  158. for (Items items : vecItem) {
  159. System.out.println("|" + items.getId() + "|" + items.getName() + "|" + items.getPrice() + "|" + items.getStock() +"|");
  160. }
  161. System.out.println("=================================");
  162. int WrongFormat = 0;
  163. int WrongFormat1 = 0;
  164. String tempid = "";
  165. int tempstock= 0;
  166. do {
  167. WrongFormat = 0;
  168. System.out.print("Please Input Id [Must be exactly 5 numeric character] : ");
  169. tempid = scan.nextLine();
  170. for (Items items : vecItem) {
  171. if(tempid.equals(items.getId()))
  172. {
  173. do {
  174. WrongFormat1 = 0;
  175. try {
  176. System.out.print("Input Item Stock [1-10]: ");
  177. tempstock = scan.nextInt();
  178. } catch (Exception e) {
  179. WrongFormat1 = 1;
  180. System.out.println("Must be numeric");
  181. }
  182. } while (tempstock > 10 ||tempstock < 0 || WrongFormat1 == 1);
  183. if(items.getStock() - tempstock < 0)
  184. {
  185. System.out.println("Cannot Checkout, Item is out of Stock!");
  186. }
  187. else
  188. {
  189. items.setStock(items.getStock()-tempstock);
  190. System.out.println("You have sold " + tempstock + " of " + items.getName() +" with revenue Rp." + (items.getPrice()*tempstock));
  191. }
  192. scan.nextLine();
  193. break;
  194. }
  195. }
  196. } while (tempid.length() < 5 || tempid.length() > 5 || WrongFormat == 1);
  197. }
  198. break;
  199. }
  200. }
  201.  
  202. } while (choice != 4);
  203. }
  204.  
  205. public static void main(String[] args) {
  206. new Main();
  207.  
  208. }
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement