我正在为一个班级的“大学书店”编写一个程序。而且我觉得一切都应该正常工作,但是对于 publishingPrice 和标记,我收到“变量未初始化”错误。然而我给了他们两个价值观。我究竟做错了什么?我正在使用 Netbeans。
import java.util.Scanner;
public class ProgrammingProject {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
//Set my variables for the program
double publisherPrice;
double newBook;
double usedBook;
double usedBookDiscount;
double rentalBook;
double rentalBookDiscount;
double markup;
int booksOrdered;
String bookName;
System.out.println("Enter the Book Title: ");
bookName = keyboard.next();
System.out.println("Enter the Amount of Books Ordered: ");
booksOrdered = keyboard.nextInt();
//Set the conditions for markup
if (booksOrdered < 20) {
markup = .40;
}
if (booksOrdered >= 20 && booksOrdered < 50){
markup = .35;
}
if (booksOrdered >= 50 && booksOrdered < 100){
markup = .30;
}
if (booksOrdered >=100){
markup = .25;
}
//Set calculations for program to use
usedBookDiscount = .75;
rentalBookDiscount = .40;
newBook = (publisherPrice + markup);
usedBook = ((newBook * usedBookDiscount) - usedBookDiscount);
rentalBook = ((newBook * rentalBookDiscount - rentalBookDiscount));
System.out.println(bookName + publisherPrice + newBook + usedBook + rentalBook);
}
}