Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class CS220_Project2 {
- public static <gift> void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- int giftQuantity;
- ArrayList<String> gifts = new ArrayList<String>();
- while (true) {
- System.out.print("Input number of gift items: ");
- giftQuantity = sc.nextInt();
- if (giftQuantity >0)
- break;
- System.out.print("ERROR: number of items must be greater than zero.");
- }
- int i;
- while (arraylist(gifts) <= giftQuantity) {
- for(i=1;i <= giftQuantity; i++) {
- System.out.println("Input name of gift item " + i + ": " );
- gifts.add(sc.next());
- }
- break;
- }
- String userCommand;
- do {
- System.out.println("---------------------");
- System.out.println("MENU");
- System.out.println("---------------------");
- System.out.println("(A)dd a gift item");
- System.out.println("(D)elete a gift item");
- System.out.println("(E)mpty basket");
- System.out.println("(S)how basket");
- System.out.println("(Q)uit");
- System.out.println("---------------------");
- System.out.print("Please enter command:");
- userCommand = sc.next().toLowerCase();
- if (userCommand.contains("a")) {
- System.out.print("Input gift item name: ");
- gifts.add(sc.next());
- }
- {
- if (userCommand.contains("d")) {
- System.out.print("Input gift item name: ");
- gifts.remove(sc.next());
- }
- if (userCommand.contains("e")) {
- System.out.print("Basket emptied.");
- }
- if (userCommand.contains("s")) {
- System.out.print(gifts);
- }
- if (userCommand.contains("q")) {
- System.out.print("Program terminated.");
- }
- else {
- System.out.println("ERROR: Invalid Command");
- }
- }
- }while(userCommand != ("q"));
- }
- private static int arraylist(ArrayList<String> gifts) {
- // TODO Auto-generated method stub
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment