Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.83 KB | None | 0 0
  1. package storemanagement;
  2.  
  3.  
  4. import java.util.*;
  5. import java.util.Scanner;
  6.  
  7. public class StoreManagement {
  8.  
  9. static Scanner console=new Scanner(System.in);
  10. static ArrayList<String> pname= new ArrayList<String>();
  11. static ArrayList<Float> pprice= new ArrayList<Float>();
  12. static ArrayList<Integer> pqty= new ArrayList<Integer>();
  13. static boolean x=true;
  14. static char option;
  15.  
  16.  
  17.  
  18. public static void main(String[] args) {
  19.  
  20.  
  21.  
  22. //login();
  23. menu();
  24.  
  25. }
  26.  
  27. public static void login(){
  28. String username;
  29. String password;
  30.  
  31. System.out.println("\t\t\t\t\tLog in ");
  32. System.out.println("\t\t\t\t************************");
  33. System.out.print("\t\t\t\tUsername: ");
  34. username = console.nextLine();
  35.  
  36. System.out.print("\t\t\t\tPassword: ");
  37. password = console.nextLine();
  38. System.out.println("\t\t\t\t************************");
  39.  
  40. users check = new users(username, password);
  41.  
  42. if(check.auth())
  43. System.out.println("You are logged in");
  44. }
  45. public static void menu(){
  46. int choice;
  47. do{
  48. System.out.println("\t\t\t\t\t\tStore Management");
  49. System.out.println("\t\t\t\t*********************************************");
  50. System.out.println("\t\t\t\t* [1] Add Items\t\t\t\t *"
  51. + "\n\t\t\t\t* [2] Edit Items\t\t\t *"
  52. + "\n\t\t\t\t* [3] Search Items\t\t\t *"
  53. + "\n\t\t\t\t* [4] Delete Items\t\t\t *"
  54. + "\n\t\t\t\t* [5] Display the Lists of Items\t *"
  55. + "\n\t\t\t\t* [6] Exit\t\t\t\t *");
  56. System.out.println("\t\t\t\t*********************************************");
  57. System.out.print("\t\t\t\tEnter Option: ");
  58. choice=console.nextInt();
  59. switch(choice)
  60. {
  61. case 1:
  62. add();
  63. break;
  64. case 2:
  65. edit();
  66. break;
  67. case 3:
  68. search();
  69. break;
  70. case 4:
  71. delete();
  72. break;
  73. case 5:
  74. display();
  75. break;
  76. case 6:
  77. toexit();
  78. break;
  79. default:
  80. System.out.println("\t\t\t\tInvalid input");
  81. break;
  82. }
  83. System.out.print("\t\t\t\tGo back to Menu? [y/n]: ");
  84. option=console.next().charAt(0);
  85. if( option=='n'){
  86. x=false;
  87. }
  88. }while(x=true);
  89. }
  90.  
  91. public static void add(){
  92.  
  93. String name;
  94. Float price;
  95. int qty;
  96.  
  97. do{
  98. try
  99. {
  100. System.out.println("\t\t\t\t*********************************************");
  101. System.out.print("\t\t\t\t Quantity of Products to Add: ");
  102. qty=console.nextInt();
  103.  
  104. System.out.print("\t\t\t\t Product Name: ");
  105. name=console.next();
  106. if(" ".equalsIgnoreCase(name))
  107. System.out.print("\t\t\t\t Please Enter a Name: ");
  108. else{
  109. pname.add(name);
  110. pqty.add(qty);
  111. }
  112.  
  113. System.out.print("\t\t\t\t Product Price: ");
  114. price=console.nextFloat();
  115. if(price==-1)
  116. System.out.print("\t\t\t\t Please Enter a Price");
  117. else
  118. pprice.add(price);
  119. }
  120. catch(InputMismatchException exception)
  121. {
  122. System.out.println("\t\t\t\t Invalid Input");
  123. }
  124. System.out.println("\t\t\t\t*********************************************");
  125.  
  126.  
  127. System.out.print("\t\t\t\t Add More Items? [y/n]: ");
  128. option=console.next().charAt(0);
  129. if( option=='n'){
  130. x=false;
  131. }
  132. }while(x!=false);
  133.  
  134.  
  135. }
  136.  
  137. public static void display(){
  138.  
  139. int choice1;
  140.  
  141.  
  142. do{
  143. System.out.println("\t\t\t\t\t\tSee Lists: ");
  144. System.out.println("\t\t\t\t--------------------------------------------------");
  145. System.out.println("\t\t\t\t| [1] Sorted Display By Price\t\t\t |"
  146. + "\n\t\t\t\t| [2] Unsorted Display Based on User Input\t |"
  147. + "\n\t\t\t\t| [3] Go Back to Menu \t\t\t\t|");
  148. System.out.println("\t\t\t\t--------------------------------------------------");
  149. System.out.print("\t\t\t\tEnter Option: ");
  150. choice1=console.nextInt();
  151. switch(choice1)
  152. {
  153. case 1:
  154. Float[] pricearray=pprice.toArray(new Float[pprice.size()]);
  155. String[] namearray = pname.toArray(new String[pname.size()]);
  156. Integer[] qtyarray = pqty.toArray(new Integer[pqty.size()]);
  157. Object[] object=sort(pricearray,namearray,qtyarray);
  158. Float[] price = (Float[]) object[0];
  159. String[] name = (String[]) object[1];
  160. Integer[] qty = (Integer[]) object[2];
  161. for(int i=0;i<name.length;i++){
  162. System.out.println("\t\t\t\t\t\tProducts : ");
  163. System.out.println("\t\t\t\t----------------------------------------------------------");
  164. System.out.println("\t\t\t\t| NAME\t\t\tPRICE\t\t QUANTITY\t |");
  165. System.out.println("\t\t\t\t| "+name[i]+"\t\t\t"+ price[i]+"\t\t\t"+qty[i]+"\t |");
  166. System.out.println("\t\t\t\t----------------------------------------------------------");
  167. }
  168. System.out.print("Go back to Display Lists: [y/n]");
  169. option=console.next().charAt(0);
  170. if(option=='y')
  171. display();
  172. else if(option=='n')
  173. menu();
  174. break;
  175. case 2:
  176. if(pname.isEmpty())
  177. System.out.println("\t\t\t\t\t\tNo Added Items");
  178. else{
  179. System.out.println("\t\t\t\t\t\tProducts : ");
  180. System.out.println("\t\t\t\t----------------------------------------------------------");
  181. System.out.println("\t\t\t\t| NAME\t\t\tPRICE\t\t QUANTITY\t |");
  182. System.out.println("\t\t\t\t----------------------------------------------------------");
  183. for(int i=0;i<pname.size();i++){
  184. System.out.println("\t\t\t\t| "+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i)+"\t |");
  185. System.out.println("\t\t\t\t----------------------------------------------------------");
  186. }
  187. }
  188. break;
  189. case 3:
  190. menu();
  191. break;
  192.  
  193. default:
  194. System.out.println("\t\t\t\tInvalid input");
  195. break;
  196. }
  197. }while((choice1!=1)&&(choice1!=2)&&(choice1!=3));
  198.  
  199. }
  200. public static Object[] sort(Float[] p, String[] n, Integer[] x){
  201.  
  202. int minIndex, tempQty;
  203. Float tempPrice;
  204. String tempName;
  205. for(int i=0;i<p.length-1;i++){
  206. minIndex=i;
  207. for(int j=i+1;j<p.length;j++){
  208. if(p[j]<p[minIndex]){
  209. minIndex=j;
  210. }
  211. }
  212. tempPrice=p[minIndex];
  213. tempName = n[minIndex];
  214. tempQty=x[minIndex];
  215. p[minIndex]=p[i];
  216. n[minIndex]=n[i];
  217. x[minIndex]=x[i];
  218. p[i]=tempPrice;
  219. n[i]=tempName;
  220. x[i]=tempQty;
  221.  
  222. }
  223. return new Object[]{p,n,x};
  224. }
  225.  
  226.  
  227. public static void search(){
  228.  
  229. String sproduct;
  230.  
  231. System.out.println("\t\t\t\t\t\tSEARCH: ");
  232. System.out.println("\t\t\t\t---------------------------------------------");
  233. System.out.print("\t\t\t\t Product Name: ");
  234. sproduct=console.next();
  235. System.out.println("\t\t\t\t---------------------------------------------");
  236.  
  237. if(pname.contains(sproduct)){
  238. System.out.println("\t\t\t\t---------------------------------------------");
  239. System.out.println("\t\t\t\t\t\tProduct Found:");
  240. System.out.println("\t\t\t\t---------------------------------------------");
  241. System.out.println("\t\t\t\t NAME\t\t\tPRICE\t\t\tQUANTITY");
  242. System.out.println("\t\t\t\t----------------------------------------------------------");
  243. for(int i=0;i<pname.size();i++){
  244. if(sproduct.equals(pname.get(i))){
  245. System.out.println("\t\t\t\t"+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i));
  246. System.out.println("\t\t\t\t----------------------------------------------------------");
  247. }
  248. }
  249. }
  250. else
  251. System.out.println("\t\t\t\t No "+sproduct+" Product in the List !");
  252. }
  253.  
  254.  
  255. public static void edit(){
  256.  
  257. String sproduct, eproduct;
  258. Float oprice;
  259. int choice;
  260. int qty;
  261. int index = 0;
  262. int pindex;
  263. int qindex;
  264. do{
  265. System.out.println("EDIT: ");
  266. System.out.println("\t\t\t\t---------------------------------------------");
  267. System.out.println("\t\t\t\t|[1] Edit Item\t\t|");
  268. System.out.println("\t\t\t\t|[2] Go Back to Menu\t\t\t\t|");
  269. System.out.println("\t\t\t\t---------------------------------------------");
  270. System.out.print("\t\t\t\tEnter Option: ");
  271. choice=console.nextInt();
  272. switch(choice)
  273. {
  274. case 1:
  275. System.out.println("\t\t\t\t\t\tEDIT: ");
  276. System.out.println("\t\t\t\t---------------------------------------------");
  277. System.out.print("\t\t\t\t Search Product to Edit: ");
  278. sproduct=console.next();
  279. System.out.println("\t\t\t\t---------------------------------------------");
  280.  
  281. if(pname.contains(sproduct)){
  282. System.out.println("\t\t\t\t\t\tProduct Found:");
  283. System.out.println("\t\t\t\t---------------------------------------------");
  284. System.out.println("\t\t\t\t NAME\t\t\tPRICE\t\t\tQUANTITY");
  285. System.out.println("\t\t\t\t----------------------------------------------------------");
  286. for(int i=0;i<pname.size();i++){
  287. if(sproduct.equals(pname.get(i))){
  288. index=index+i;
  289. System.out.println("\t\t\t\t"+pname.get(i)+"\t\t\t"+ pprice.get(i)+"\t\t\t"+pqty.get(i));
  290. System.out.println("\t\t\t\t----------------------------------------------------------");
  291. }
  292. }
  293. System.out.println("\t\t\t\t---------------------------------------------");
  294. System.out.print("\t\t\t\tType New Name to be replaced: ");
  295. eproduct=console.next();
  296. System.out.println("\t\t\t\t---------------------------------------------");
  297. pname.set(index,eproduct);
  298. System.out.println("\t\t\t\tDone!");
  299.  
  300. System.out.print("\t\t\t\tDo you want to edit also the price ?[y/n] : ");
  301. option=console.next().charAt(0);
  302. switch (option) {
  303. case 'n':
  304. System.out.print("\t\t\t\tDo you want to edit also the quantity ?[y/n] : ");
  305. option=console.next().charAt(0);
  306. if(option=='n'){
  307. System.out.println("\t\t\t\tGoing Back To Menu");
  308. menu();
  309. }
  310. else if(option=='y'){
  311. System.out.println("\t\t\t\t---------------------------------------------");
  312. System.out.print("\t\t\t\tType New Quantity to be replaced: ");
  313. qty=console.nextInt();
  314. System.out.println("\t\t\t\t---------------------------------------------");
  315. qindex=+index;
  316. pqty.set(qindex,qty);
  317. System.out.println("\t\t\t\tDone!");
  318. }
  319. break;
  320. case 'y':
  321. System.out.println("\t\t\t\t---------------------------------------------");
  322. System.out.print("\t\t\t\tType New Price to be replaced: ");
  323. oprice=console.nextFloat();
  324. System.out.println("\t\t\t\t---------------------------------------------");
  325. pindex=+index;
  326. pprice.set(pindex,oprice);
  327. System.out.println("\t\t\t\tDone!");
  328. System.out.print("\t\t\t\tDo you want to edit also the quantity ?[y/n] : ");
  329. option=console.next().charAt(0);
  330. if(option=='n'){
  331. System.out.println("\t\t\t\tGoing Back To Menu");
  332. menu();
  333. }
  334. else if(option=='y'){
  335. System.out.println("\t\t\t\t---------------------------------------------");
  336. System.out.print("\t\t\t\tType New Quantity to be replaced: ");
  337. qty=console.nextInt();
  338. System.out.println("\t\t\t\t---------------------------------------------");
  339. qindex=+index;
  340. pqty.set(qindex,qty);
  341. System.out.println("\t\t\t\tDone!");
  342. break;
  343. }
  344.  
  345. break;
  346. case 2:
  347. menu();
  348. break;
  349. default:
  350. System.out.println("\t\t\t\t Invalid input");
  351. break;
  352. }
  353. }
  354. }
  355. }while((choice!=1)&&(choice!=2));
  356. }
  357.  
  358.  
  359.  
  360. public static void delete(){
  361.  
  362. int choice;
  363. String pdelete;
  364.  
  365. System.out.println("DELETE: ");
  366. System.out.println("\t\t\t\t---------------------------------------------");
  367. System.out.println("\t\t\t\t|[1] Delete Specific Item\t\t|");
  368. System.out.println("\t\t\t\t|[2] Delete All\t\t\t\t|");
  369. System.out.println("\t\t\t\t---------------------------------------------");
  370. System.out.print("\t\t\t\tEnter Option: ");
  371. choice=console.nextInt();
  372. switch(choice)
  373. {
  374. case 1:
  375. System.out.print("\t\t\t\tEnter Product You Want to Delete: ");
  376. pdelete=console.next();
  377. if(pname.contains(pdelete)){
  378. for(int i=0;i<pname.size();i++){
  379. if(pdelete.equals(pname.get(i))){
  380. pname.remove(pname.get(i));
  381. pprice.remove(pprice.get(i));
  382. pqty.remove(pqty.get(i));
  383. System.out.println("\t\t\t\tDone!");
  384. }
  385. }
  386. }
  387. else
  388. System.out.println("\t\t\t\tNo "+pdelete+" product in th List !");
  389.  
  390. break;
  391. case 2:
  392. System.out.println("\t\t\t\t Items Deleted!");
  393. pname.clear();
  394. pprice.clear();
  395. pqty.clear();
  396. break;
  397. default:
  398. System.out.println("\t\t\t\t Invalid input");
  399. break;
  400. }
  401.  
  402.  
  403. }
  404.  
  405. public static void toexit(){
  406. System.exit(0);
  407. }
  408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement