我已经成功完成,程序没有问题,一切正常,除了它没有显示这本书的最高和最低价格。但是,我不想要这样的程序。
目前,该程序由包含书名的预定义数组组成,也就是说,每当用户输入一本书的输入时,程序都会显示书名和书的价格。所以,我在想一些不同的东西,那就是没有在数组中预先存储书名和价格。
无论用户键入的书名是什么,该书名都将与价格一起存储为数组。循环3次,即在输入1次书名和价格后,会再次提示用户输入书名,最后会显示总书本和价格以及最高最低价格。书,用户购买。
谁能帮我这个?请在下面查看我的编码:
import java.util.Scanner;
public class BookStore {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String[] books = {"Introduction To Java","Artificial Intlegence","Web Programming","Introduction To Database","English Speech","Introduction To C#"};
double[] prices ={100,50,25,45,60,90};
System.out.println("Welcome to SAJID's Book Shop");
System.out.println();
System.out.println("Please select the the book and write the number of the book :");
System.out.println();
System.out.println("1.Introduction To Java");
System.out.println("2.Artificial Intlegence");
System.out.println("3.Web Programming");
System.out.println("4.Introduction To Database");
System.out.println("5.English Speech");
System.out.println("6.Introduction To C#");
System.out.println();
System.out.println("Total Number Of Books "+books.length);
int totalBook;
totalBook = books.length;
double totalPrice=0;
int i=0;
while(i<=5){
totalPrice+=prices[i];
i++;
}
System.out.println("Total Price:$" + totalPrice);
int bookTitle;
System.out.print("Enter book Number: ");
bookTitle = input.nextInt();
if(bookTitle == 0){
System.out.println("Book name: "+books[0]);
System.out.print("Book price:$"+prices[0]);
}
if(bookTitle == 1){
System.out.println("Book name: "+books[1]);
System.out.print("Book price:$"+prices[1]);
}
if(bookTitle == 2){
System.out.println("Book name: "+ books[2]);
System.out.print("Book price:$"+prices[2]);
}
if(bookTitle == 3){
System.out.println("Book name: "+books[3]);
System.out.print("Book price:$"+prices[3]);
}
if(bookTitle == 4){
System.out.println("Book name: "+books[4]);
System.out.print("Book price:$"+prices[4]);
}
if(bookTitle == 5){
System.out.println("Book name: "+books[5]);
System.out.print("Book price:$"+prices[5]);
}
/*double min=0;
for(i=0;i<books.length-1;i++){
if(books[i] =< books[i++]){
min=books[i];
minBook = i;
}*/
}
//System.out.print("Cheapest book: " + min);
}
}