I have set a constructor for a Class Book with author; title; price and page. Everything works okey. When I println the manual input and result on the first book, but when I try to write a manual input for the second book the println asks for title directly.
I red the code over and over again and it seems in order, same as for Book1. I just started studying JAVA at school and we need to research for most of the exercises so this one includes actually importing and using java.util.Scanner, while having two argument constructor. I searched to find a similar issue with this scanner, but apparently it's a sintax error that messes up a bit if you call for the constructor to reply twice or thrice.
**Here are some examples of my code and result:**
\\some code above ofcourse
Scanner keyboard = new Scanner(System.in);
//BOOK 1 manual entry.
System.out.println("Your author1: ");
String author1 = keyboard.nextLine();
System.out.println("Title of your book1: " );
String title1 = keyboard.nextLine();
System.out.println("Price of your book1: ");
double price1 = keyboard.nextDouble();
System.out.println("Pages of your book1: ");
int page1 = keyboard.nextInt();
classbook book1 = new classbook(author1, title1, price1, page1);
System.out.println("--------------------------------");
book1.discount(0.20);
System.out.println(book1);System.out.println("+ 10% added discount on your book.");
System.out.println("--------------------------------");
System.out.println("Your author2: ");
String author2 = keyboard.nextLine();
System.out.println("Title of your book2: " );
String title2 = keyboard.nextLine();
System.out.println("Price of your book2: ");
double price2 = keyboard.nextDouble();
System.out.println("Pages of your book2: ");
int page2 = keyboard.nextInt();
classbook book2 = new classbook(author2, title2, price2, page2);
System.out.println("--------------------------------");
book2.discount(0.20);
System.out.println(book2);System.out.println("+ 10% added discount on your book2.");
System.out.println("--------------------------------");
}
}
And here is a picture of the result: "Pic1: It asks me to input directly into second line (Title)"
"Pic2: The result shows that Author field is blank, the dot is directly recalled from the constructor just as an end to a text.