我为作者设置了一本类书的构造函数;标题;价格和页面。 一切正常。当我在第一本书上打印手动输入和结果时,当我尝试为第二本书编写手动输入时,println会直接询问标题。
我一遍又一遍地重新编码代码,它看起来像顺序,与Book1相同。我刚开始在学校学习JAVA,我们需要研究大部分练习,所以这个练习包括实际导入和使用java.util.Scanner,同时有两个参数构造函数。我搜索到了这个扫描仪发现了一个类似的问题,但显然这是一个sintax错误,如果你要求构造函数回复两次或三次,那就会有点麻烦。
**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("--------------------------------");
}
}
以下是结果图: “Pic1:它要求我直接输入第二行(标题)”
“Pic2:结果显示作者字段为空白,从构造函数直接调用点作为文本的结尾。