Guest User

Untitled

a guest
Oct 2nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class CS220_Project2 {
  5.  
  6. public static <gift> void main(String[] args) {
  7. // TODO Auto-generated method stub
  8.  
  9.  
  10. Scanner sc = new Scanner(System.in);
  11. int giftQuantity;
  12. ArrayList<String> gifts = new ArrayList<String>();
  13.  
  14.  
  15.  
  16.  
  17. while (true) {
  18. System.out.print("Input number of gift items: ");
  19. giftQuantity = sc.nextInt();
  20.  
  21. if (giftQuantity >0)
  22. break;
  23. System.out.print("ERROR: number of items must be greater than zero.");
  24.  
  25. }
  26. int i;
  27. while (arraylist(gifts) <= giftQuantity) {
  28.  
  29. for(i=1;i <= giftQuantity; i++) {
  30. System.out.println("Input name of gift item " + i + ": " );
  31. gifts.add(sc.next());
  32. }
  33. break;
  34. }
  35. String userCommand;
  36. do {
  37. System.out.println("---------------------");
  38. System.out.println("MENU");
  39. System.out.println("---------------------");
  40. System.out.println("(A)dd a gift item");
  41. System.out.println("(D)elete a gift item");
  42. System.out.println("(E)mpty basket");
  43. System.out.println("(S)how basket");
  44. System.out.println("(Q)uit");
  45. System.out.println("---------------------");
  46.  
  47. System.out.print("Please enter command:");
  48. userCommand = sc.next().toLowerCase();
  49.  
  50.  
  51. if (userCommand.contains("a")) {
  52. System.out.print("Input gift item name: ");
  53. gifts.add(sc.next());
  54. }
  55. {
  56. if (userCommand.contains("d")) {
  57. System.out.print("Input gift item name: ");
  58. gifts.remove(sc.next());
  59. }
  60. if (userCommand.contains("e")) {
  61. System.out.print("Basket emptied.");
  62. }
  63. if (userCommand.contains("s")) {
  64. System.out.print(gifts);
  65. }
  66. if (userCommand.contains("q")) {
  67. System.out.print("Program terminated.");
  68. }
  69. else {
  70. System.out.println("ERROR: Invalid Command");
  71. }
  72. }
  73.  
  74. }while(userCommand != ("q"));
  75.  
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. private static int arraylist(ArrayList<String> gifts) {
  91. // TODO Auto-generated method stub
  92. return 0;
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment