請大佬指點
//構(gòu)造方法
public class bookborrow {
book[] books= {new book(1,"高數(shù)"),new book(2,"線性代數(shù)"),new book(3,"大學(xué)物理B")};
Scanner input=new Scanner(System.in);
public void xuhao() {
int a=input.nextInt();
int i;
try {
for(i=0;i<books.length;i++) {
if(a==books[i].getId()) {
System.out.println("圖書名稱:"+books[i].getName());
borrow();
break;
}
else {
System.out.println("你輸入的序號不正確!");
borrow();
}
}
}
catch(Exception e) {
}
}
public void mingcheng() {
String b=input.next();
int i;
try {
for(i=0;i<books.length;i++) {
if(b.equals(books[i].getName())) {
System.out.println("圖書序號:"+books[i].getId());
borrow();
break;
}
else {
System.out.println("輸入錯誤!??!");
borrow();
}
}
}
catch(Exception e) {
}
}
public void borrow() {
System.out.println("輸入命令:1.按名稱查找圖書 2.按序號查找圖書:3.退出");
String c=input.next();
if(c.equals("1")) {
System.out.println("請輸入圖書名稱:");
mingcheng();
}
else if(c.equals("2")){
System.out.println("請輸入序號:");
xuhao();
}
else if(c.equals("3")){
input.close();
}
else {
System.out.println("輸入錯誤,請重新輸入?。?!");
borrow();
}
}
//程序入口
public static void main(String[] args) {
// TODO Auto-generated method stub
bookborrow p=new bookborrow();
p.borrow();
}
}
//book類
public class book {
private int id;
private String name;
public? ?book(int id,String name) {
this.id=id;
? ? this.name=name;
? ? }
public int getId() {
return id;
}
public void SetId(int id) {
this.id=id;
}
public String getName() {
return name;
}
public void SetName(String name) {
this.name=name;
}
}
2020-01-14