java如何存储在60位字符串和int的数组中
我想制作一个图书馆系统,它有一个菜单:
1.)添加新书
2.)编辑一本书
3.)从ISBN中搜索一本书
4.)展示所有书籍
5.)从ISBN中删除一本书
6.)退出
为了保存这些书,我必须使用60个货舱。这本书将有:
1) Isbn(字符串)
2) 名称(字符串)
3) 作者(字符串)
4) 图书数量(整数)
到目前为止我已经做到了
//This goes above your class declaration, this is importing the Scanner class.
import java.lang.reflect.Array;
import java.lang.Object.*;
import java.util.Scanner;
import java.util.Arrays;
public class BookLibrary {
public static void main (String[] args)
{
// allocates memory for 60 slots
String[] book_array;
//Program keeps running till this condition updates. Only updates
//if the user "chooses" quit option.
boolean keepRunning = true;
//User choice from the menu is stored here.
int userChoice = 0;
Scanner keyboard = new Scanner(System.in);
while (true)
{
//your code here
System.out.println("");
System.out.println("");
System.out.println("Choose:");
System.out.println("1:Add a new Book");
System.out.println("2:Edit Book Infos");
System.out.println("3:Search a Book (From ISBN)");
System.out.println("4:Show all the Books");
System.out.println("5:Delete a Book (From ISBN)");
System.out.println("6:Exit");
int choose = keyboard.nextInt();
if (choose == 1)
{
System.out.println("You Choose to Add a New Book1 ");
String zero = keyboard.nextLine();
System.out.println("Book Name:");
String book = keyboard.nextLine();
System.out.println("Author:");
String author = keyboard.nextLine();
System.out.println("ISBN:");
String isbn = keyboard.nextLine();
System.out.println("# of Books:");
int numbooks = keyboard.nextInt();
System.out.println("");
System.out.println("");
String bookinfo = book + " ," + author + " ," + isbn;
//String[] splits = bookinfo.split(",");
System.out.println(bookinfo);
System.out.println("Name of Book | " + "Author | " + "ISBN");
// System.out.println(splits[0] +" | "+ splits[1] +" | "+ splits[2]);
}
else
if (choose == 2)
{
System.out.println("You Choose to Edit an existing Book ");
String zero = keyboard.nextLine();
}
else
if (choose == 3)
{
System.out.println("You Choose to Search a Book ");
String zero = keyboard.nextLine();
}
else
if (choose == 4)
{
System.out.println("You Choose to view all the Books ");
String zero = keyboard.nextLine();
}
else
if (choose == 5)
{
System.out.println("You Choose to Delete a Book ");
String zero = keyboard.nextLine();
}
else
if(choose == 6)
{
System.out.println("Library System Terminated!!! ");
String zero = keyboard.nextLine();
System.exit(0);
}
else
{
System.out.println("Wrong Choice");
}
}
}
}
你能帮忙吗
# 1 楼答案
不过我不太明白你的问题
更好的方法: 只需使用一个数组或一系列类型的Book:
而你的书类型有以下几点:
# 2 楼答案
使用面向对象编程概念。创建一个图书对象,属性为ISBN、名称、作者和图书编号。创建图书类型列表
试试这个:这是book类和构造函数
以下是您的代码: