import java.util.Scanner;
public class Assignment6 {
public static void main(String[] args)
{
String projName;
int projNumber;
String projLocation;
double initialFunding;
double spending;
double currentBalance;
Project project = new Project(2.0);
Scanner keyboard = new Scanner(System.in);
String userInput;
char userChoice;
do {
System.out.println("Choice\t\tAction\n "
+ "------\t\t------\n"
+ " A\t\tAdd Project\n "
+ "D\t\tDisplay Project\n "
+ "Q\t\tQuit\n "
+ "R\t\tAdd Expenditure\n "
+ "?\t\tDisplay Help\n\n");
System.out.println("What action would you like to perform?");
userInput = keyboard.nextLine().toUpperCase();
userChoice = userInput.charAt(0);
switch (userChoice) {
case 'A':
System.out.println("Please enter the project information:");
System.out.println("Enter a project name:");
project.setName(keyboard.nextLine());
System.out.println("Enter a project number:");
project.setNumber(keyboard.nextInt());
keyboard.nextLine(); // consuming the \n
System.out.println("Enter a project location:");
project.setLocation(keyboard.nextLine());
System.out.println("Enter a project initial funding:");
initialFunding = keyboard.nextDouble();
break;
case 'D':
System.out.println(project.toString());
break;
case 'Q':
//Quit here just in case.
break;
case 'R':
break;
case '?':
break;
}
} while (userChoice != 'Q');
}
}
I do not know why I get an error after I enter the initial funding value.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(Unknown Source) at Assignment6.main(Assignment6.java:34)