- #1
schapman22
- 74
- 0
Homework Statement
I am supposed to write a program that uses a bag of strings to keep track of a list of chores. The user can add, remove, view, etc. items on the list.
Homework Equations
When I run the program and i choose an option from the menu. It displays the menu again before you can add or remove the item you want. I can't figure out why it is doing this. Thank you in advance.
The Attempt at a Solution
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.colorado.collections;
import java.util.Scanner;
/**
*
* @author Scott
*/
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
ArrayBag<String> choreList = new ArrayBag<>();
int entry;
String chore;
boolean endProgram=false;
Scanner keyboard = new Scanner(System.in);
while(!endProgram)
{
System.out.println("Choose an option from the following list.");
System.out.println();
System.out.println("Add item to list(press 1)");
System.out.println("View number of items on list(press 2)");
System.out.println("View a list of chores(press 3)");
System.out.println("Remove an item from the list(press 4)");
System.out.println("Exit program(press 5)");
entry = keyboard.nextInt();
switch(entry)
{
case 1: System.out.println();
System.out.println("What would you like to add?");
chore = keyboard.nextLine();
choreList.add(chore);
break;
case 2: System.out.println();
System.out.println("There are " + choreList.size() +
" items on your list.");
break;
case 3: System.out.println();
choreList.printList();
break;
case 4: System.out.println();
System.out.println("Which item would you like to remove?");
chore = keyboard.nextLine();
choreList.remove(chore);
break;
case 5: endProgram=true;
break;
}
}
}
}