Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.*;
  3. import java.util.ArrayList;
  4.  
  5. public class StarberksInterface
  6. {
  7.  
  8.  
  9. public static void main(String args[])
  10. {
  11.  
  12. Scanner console = new Scanner(System.in);
  13. store = new Store();
  14. String str, sName1, sName2, name;
  15. char c;
  16. int n=0;
  17. sName1 = "Callahan";
  18. sName2 = "Lambton";
  19.  
  20.  
  21.  
  22. while(n!=5)// Exits the program when 5 is pressed
  23. {
  24.  
  25. //This is the main menu that will be displayed first.
  26. System.out.println(" MAIN MENU FOR MANAGEMENT SYSTEM");
  27. System.out.println("===============================================");
  28. System.out.println("1. CHOOSE STORE");
  29. System.out.println("2. DISPLAY STORES");
  30. System.out.println("3. LOAD STORE VIA FILE");
  31. System.out.println("4. SAVE STORE TO FILE ");
  32. System.out.println("5. EXIT PROGRAM");
  33. System.out.println("===============================================");
  34.  
  35. System.out.print("n Please enter option 1-5 to continue...: ");
  36. n = Integer.parseInt(System.console().readLine());
  37. // Reads user input and takes them to selected code.
  38. if (n>5||n<1)
  39. {
  40. System.out.print("Invalid input, please try again...");
  41. continue;
  42. }
  43. if (n==1)// Takes to option 1 or sub menu
  44. {
  45. str="y";
  46.  
  47. while(str.equals("y")||str.equals("Y"))
  48. {
  49. System.out.println("Enter a store name [Callahan or Lambton] ");
  50. name = console.next();
  51. if (sName1.equals(name)|| sName2.equals(name))
  52. {
  53. StarberksInterface.subMenu();
  54. break;
  55.  
  56. }
  57.  
  58. else
  59. {
  60. System.out.println("There is no store under this name. Please try again.");
  61. }
  62.  
  63. }
  64. continue;
  65. }
  66. if (n==2)// Gathers products in stores and displays the number of products
  67. {
  68. System.out.println(" Store data is being displayed.");
  69. System.out.println("===============================");
  70. System.out.println("Store: Callahan");
  71. System.out.println(" Number of products: "+store.getProductListSize());
  72. System.out.println("===============================n");
  73. System.out.println("Store: Lambton");
  74. System.out.println(" Number of Products: "+store.getProductListSize());
  75. System.out.println("===============================n");
  76.  
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. public static void subMenu()
  85. {
  86. Scanner console = new Scanner(System.in);
  87. String str;
  88. char c;
  89. int n=0;
  90.  
  91.  
  92. // this will be the sub menu that gets displayed.
  93. System.out.println(" INVENTORY MANAGEMENT SYSTEM");
  94. System.out.println("===============================================");
  95. System.out.println("1. ADD PRODUCT DATA");
  96. System.out.println("2. VIEW SINGLE PRODUCT DATA");
  97. System.out.println("3. DELETE PRODUCT");
  98. System.out.println("4. DISPLAY ALL PRODUCTS IN STORE");
  99. System.out.println("===============================================");
  100. System.out.println("5. EXIT SUB MENU");
  101.  
  102. while(n!=5)// Exits the program when 4 is pressed
  103. {
  104. System.out.print("n Please enter option 1-5 to continue...: ");
  105. n = Integer.parseInt(System.console().readLine());
  106. // Reads user input and takes them to selected code.
  107. if (n>5||n<1)
  108. {
  109. System.out.print("Invalid input, please try again...");
  110. continue;
  111. }
  112. if (n==1)// Takes to option 1 or addItem()
  113. {
  114. str="y";
  115. while(str.equals("y")||str.equals("Y"))
  116. {
  117.  
  118. StarberksInterface.addItem();
  119. System.out.print("Would you like to enter another product ? (Y or N) : ");
  120. str = console.next();
  121. }
  122. continue;
  123. }
  124. if (n==2)// Takes to option 2 or prodData
  125. {
  126. str="y";
  127. while(str.equals("y")||str.equals("Y"))
  128. {
  129. StarberksInterface.prodData();
  130. System.out.println("n***************************************************n");
  131. System.out.print("Stay viewing this page? (Y or N) ");
  132. str = console.next();
  133.  
  134. }
  135. continue;
  136. }
  137.  
  138. if (n==3)// Takes to option 3 or delete item
  139. {
  140. System.out.print("Delete a product");
  141. continue;
  142. }
  143.  
  144. if (n==4)// Takes to option 4 or view all products in store
  145. {
  146. System.out.print("Displaying all products in store");
  147. continue;
  148. }
  149. }
  150. if (product != null)// If there is information on the system
  151. // then the user will have the option to view data, before the program quits
  152. {
  153. System.out.println("n***************************************************n");
  154. System.out.println("nAre you sure you want to quit? There is information stored on a product. ");
  155. System.out.println("nWould you like to view if information? (Y / N) ");
  156. str="";
  157. str = console.next();
  158. while(str.equals("y")||str.equals("Y"))
  159. {
  160.  
  161. StarberksInterface.prodData();
  162. return;
  163. }
  164.  
  165. }
  166.  
  167. else
  168. {
  169. System.out.print("nThank you for using this inventory management software.n");
  170. System.out.print("Developed by Xavier Edwards");
  171. System.out.println("n***************************************************n");
  172. }
  173. }
  174.  
  175. public static Product product;
  176. public static Store store;
  177. // Where the user inputs the data for the item
  178. public static void addItem ()
  179. {
  180. Scanner console = new Scanner(System.in);
  181. product = new Product();// initiates the product and store to being empty.
  182.  
  183.  
  184. String desc, id, str="";
  185. double price = 0, sUpPrice = 0, unitCost = 0, inventoryCost = 0;
  186. int stock = 0, demand = 0;
  187.  
  188.  
  189. System.out.print("Please enter product description between 3 to 10 characters...: ");
  190. desc = console.next();
  191. desc = desc.toLowerCase();
  192. product.setName(desc);
  193.  
  194.  
  195. if ((desc.length() < 3 || desc.length() > 10))
  196. {
  197. System.out.println("nThis Input is incorrect. Please make description between 3 to 10 characters.n");
  198. System.out.println("Try again with different input. ");
  199. System.out.println("n*****************************************n");
  200. StarberksInterface.addItem();
  201. }
  202.  
  203. System.out.print("Please enter price in $ : ");
  204. price = console.nextDouble();
  205. product.setPrice(price);
  206.  
  207. if (price < 0)
  208. {
  209. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  210. System.out.println("Because of incorrect input, program will restart. ");
  211. System.out.println("n*****************************************n");
  212. StarberksInterface.addItem();
  213. }
  214.  
  215. System.out.print("Please enter set up price. $ : ");
  216. sUpPrice = console.nextDouble();
  217. product.setsUpPrice(sUpPrice);
  218.  
  219. if (sUpPrice < 0)
  220. {
  221. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  222. System.out.println("Because of incorrect input, program will restart. ");
  223. System.out.println("n*****************************************n");
  224. StarberksInterface.addItem();
  225. }
  226.  
  227. System.out.print("Please enter unit- cost. $ : ");
  228. unitCost = console.nextDouble();
  229. product.setunitCost(unitCost);
  230.  
  231. if (unitCost < 0)
  232. {
  233. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  234. System.out.println("Because of incorrect input, program will restart. ");
  235. System.out.println("n*****************************************n");
  236. StarberksInterface.addItem();
  237. }
  238.  
  239. System.out.print("Please enter the inventory cost. $ : ");
  240. inventoryCost = console.nextDouble();
  241. product.setinvCost(inventoryCost);
  242.  
  243. if (inventoryCost < 0)
  244. {
  245. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  246. System.out.println("Because of incorrect input, program will restart. ");
  247. System.out.println("n*****************************************n");
  248. StarberksInterface.addItem();
  249. }
  250.  
  251. System.out.print("Please enter the amount in stock : ");
  252. stock = console.nextInt();
  253. product.setstock(stock);
  254.  
  255. if (stock < 0)
  256. {
  257. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  258. System.out.println("Because of incorrect input, program will restart. ");
  259. System.out.println("n*****************************************n");
  260. StarberksInterface.addItem();
  261. }
  262.  
  263. System.out.print("Please enter the demand of the product : ");
  264. demand = console.nextInt();
  265. product.setdRate(demand);
  266.  
  267. if (demand < 0)
  268. {
  269. System.out.println("nThis Input is incorrect. Please make sure attributes are positve numbersn");
  270. System.out.println("Because of incorrect input, program will restart. ");
  271. System.out.println("n*****************************************n");
  272. StarberksInterface.addItem();
  273. }
  274.  
  275. System.out.println("n*****************************************n");
  276. System.out.print(desc +" Product was added successfully ");
  277. System.out.println("n*****************************************n");
  278. // stores the item in the array
  279.  
  280.  
  281. //Checks to see if item is already in the list
  282. /*while (product != null)
  283. {
  284. if (product.equals(store.getProduct(desc)))
  285. {
  286. System.out.println(desc +" is already a product.");
  287. System.out.println("Input for data will restart");
  288. StarberksInterface.addItem();
  289. }
  290. }*/
  291.  
  292. store.add(product);
  293.  
  294. }
  295.  
  296. import java.util.ArrayList;
  297.  
  298. public class Store{
  299. // stores the product information in an array list
  300. //allows for numerous products and each can be called in the Starberks Interface
  301. public ArrayList <Product> ProductList = new ArrayList<Product> ();
  302.  
  303. public Store()
  304. {
  305.  
  306. }
  307. public int getProductListSize()
  308. {
  309. return ProductList.size();
  310. }
  311.  
  312. public void add(Product product)
  313. {
  314. // Adds the product and all details entered by user to the list.
  315. ProductList.add(product);
  316. }
  317.  
  318. public Product getProduct(String prodName) {
  319. //
  320. for (int i = 0; i < ProductList.size(); i++) {
  321. //searches through list of products to find a specific name entered in
  322. // from the Starberks Interface
  323. if (ProductList.get(i).getName().equals(prodName)) {
  324. return ProductList.get(i);
  325. }
  326. }
  327. return null;
  328. }
  329.  
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement