throw new String query commands1 for int i 0 i

Throw new string query commands1 for int i 0 i

This preview shows page 5 - 7 out of 7 pages.

throw new IllegalArgumentException();}String query = commands[1];for (int i = 0; i < products.size(); i++) {boolean flag1 = false;String[] nameString = products.get(i).getName().split(" ");for (int j = 0; j < nameString.length;j++) {if (nameString[j].equals(query)){flag1 = true;}}if (flag1){System.out.println(products.get(i).toString());}}}catch(IllegalArgumentException ex) {break;}break;case 'a':try {if (commands.length != 2)throw new IllegalArgumentException();if (commands[1] == null) {throw new IllegalArgumentException();}String productName = commands[1];boolean added = false;for (int i = 0; i < products.size(); i++) {
Background image
if (products.get(i).getName().equals(productName)) {currentUser.addToWishList(products.get(i));System.out.println("Added to wishlist");added = true;}}if (!added) System.out.println("Product not found.");}catch(IllegalArgumentException ex) {break;}break;case 'r':try {if (commands.length != 2)throw new IllegalArgumentException();if (commands[1] == null) {throw new IllegalArgumentException();}String productName2 = commands[1];if ((currentUser.removeFromWishList(productName2)) == null) {System.out.println("Product not found.");}}catch(IllegalArgumentException ex) {break;}break;case 'b':for (int i = 0; i < inStock.size(); i++) {String productName3 = inStock.get(i).getName();try {if (currentUser.buy(productName3)){System.out.println("Bought " + productName3);}}catch (InsufficientCreditException ex) {System.out.println("Insufficient fundsfor " + productName3);}}break;case 'c':System.out.println("$" + currentUser.getCredit());break;
Background image
case 'l':done = true;System.out.println("Logged Out");break;default: //a command with no argumentSystem.out.println("Invalid Command");break;}}}}}
Background image

You've reached the end of your free preview.

Want to read all 7 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture