I know I have to use the Scanner class to first create the scanner object to receive user input in java, although I don't know how to input multiple words into one string variable. For example, I have this code here:
System.out.println("Please enter the following information");
System.out.print("Author:");
author = input.nextLine();
System.out.print("Title:");
title = input.nextLine();
System.out.print("Grade Level:");
gradeLevel = input.nextDouble();
System.out.print("Pages:");
pages = input.nextDouble();
Which according to many forums, should allow the user to input the entire line into the String variable, but instead, it skips the Author prompt entirely. What am I doing wrong?
EDIT: I have added the full loop below:
do {
System.out.printf("What kind of book is this?\n"
+ "(0 = Textbook, 1 = Novel, 2 = Biography, 3 = Author Information, 4 = Other)");
switch(input.nextInt()) {
case 0:
System.out.println("Please enter the following information.");
System.out.print("Author:");
author = input.nextLine();
System.out.print("Title:");
title = input.nextLine();
System.out.print("Grade Level:");
gradeLevel = input.nextDouble();
input.readLine();
System.out.print("Pages:");
pages = input.nextDouble();
//Creation of textBooks
texts[i] = new Textbook(gradeLevel, author, pages, title);
boolText = true;
break;
case 1:
System.out.print("Please enter the following information.\n");
System.out.print("Author:");
author = input.nextLine();
System.out.print("Genre:");
genre = input.next();
System.out.print("Title:");
title = input.nextLine();
System.out.print("Pages:");
pages = input.nextDouble();
//Creation of Novels
novels[i] = new Novel(genre, title, author, pages);
boolNovel = true;
break;
case 2:
System.out.print("Please enter the following information.\n");
System.out.print("Author:");
author = input.nextLine();
System.out.print("Title:");
title = input.nextLine();
System.out.print("Subject:");
subject = input.nextLine();
System.out.print("Pages:");
pages = input.nextDouble();
//Creation of Biographies
bio[i] = new Biography(subject, title, author, pages);
boolBiography = true;
break;
case 3:
System.out.print("Please enter the following information.\n");
System.out.print("Author:");
author = input.nextLine();
System.out.print("Email:");
email = input.next();
System.out.print("Address:");
address = input.nextLine();
System.out.print("Number of Titles:");
numOfTitles = input.nextDouble();
//Creation of Author Infortmation
authors[i] = new Author(author, address, email, numOfTitles);
boolAuthor = true;
break;
case 4:
System.out.println("Please enter the following information.");
System.out.print("Title:");
title = input.nextLine();
System.out.print("Author:");
author = input.nextLine();
System.out.print("Pages:");
pages = input.nextDouble();
//Creation of Author Infortmation
other[i] = new Books(title, author, pages);
boolOther = true;
default:
System.out.println("Program will now terminate.");
System.exit(1);
}
i++;
}
while (i < t);