//感觉不太好,为什么try...catch没啥作用勒。麻烦帮我看看
package com.Home;
import java.util.Scanner;
public class rentForBook {
public static void main(String args[]){
rentForBook Rent = new rentForBook();
Rent.waysOfRent();
}
public String[] typesOfRent(){
String[] bookTypes = {"高数","数据结构"};
return bookTypes;
}
public void waysOfRent(){
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
Scanner Input = new Scanner(System.in);
int way = Input.nextInt();
try{if(way == 1){
BasedOnName();
}
if(way == 2){
BasedOnNums();
}
else{
System.out.println("输入错误!请重新输入");
}
}catch(Exception e){
System.out.println("输入错误!请重新输入!");
}
}
public void BasedOnName(){
System.out.println("请输入图书名称:");
Scanner Input1 = new Scanner(System.in);
String name = Input1.next();
String bookTypes[] = typesOfRent();
rentForBook ifsure = new rentForBook();
try{
if(name.equals(bookTypes[0])){
ifsure.AdvancedMath();
}
if(name.equals(bookTypes[1])){
ifsure.DataConstructure();
}
else{
System.out.println("输入错误!请重新输入!");
}
}catch(Exception e){
e.printStackTrace();
System.out.println("输入错误!请重新输入!");
}
BasedOnName();
}
public void BasedOnNums(){
System.out.println("请输入图书序号:");
Scanner Input2 = new Scanner(System.in);
int nums = Input2.nextInt();
rentForBook ifsure = new rentForBook();
try{
if(nums == 1){
ifsure.AdvancedMath();
}
if(nums == 2){
ifsure.DataConstructure();
}
if(nums > 2){
System.out.println("输入错误!请重新输入!");
}
}catch(Exception e){
e.printStackTrace();
System.out.println("输入错误!请重新输入!");
}
BasedOnNums();
}
public void AdvancedMath(){
System.out.println("book : 高数");
System.out.println("确认请按 1!");
Scanner Input = new Scanner(System.in);
int num = Input.nextInt();
try{if(num == 1)
System.out.println("您已成功租借高数!");
}catch(Exception e){
e.printStackTrace();
System.out.println("输入不正确,请重新输入!");
}
}
public void DataConstructure(){
System.out.println("book : 数据结构");
System.out.println("确认请按 1!");
Scanner Input = new Scanner(System.in);
int num = Input.nextInt();
try{if(num == 1)
System.out.println("您已成功租借数据结构!");
}catch(Exception e){
e.printStackTrace();
System.out.println("输入不正确,请重新输入!");
}
}
}