package Test3; import java.io.StreamCorruptedException; import java.util.Scanner; public class Library { //借书怎么会没有图书 //图书馆里有很多书, static int bookNum; //设置两个基本属性 static String bookName; static SystemRun booker = new SystemRun(); public static void main(String[] args) { Library manger = new Library(); manger.Library(); } public static void Library() { // TODO Auto-generated constructor stub System.out.println("欢迎进入图书租借系统!! 正在为您载入图书目录!"); showBook(); System.out.println("1:按图书序号检索 2:按图书名称检索"); try { Scanner input = new Scanner(System.in); int choice = input.nextInt(); switch (choice) { case 1: booker.rentWay1(); break; case 2: booker.rentWay2(); break; default: System.out.println("您的输入有误!!"); Library(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("请输入正确的数字"); Library(); } } static String[] books = { "1:线性代数","2:概率分析","3:Java语言","4:三体","5: 高数"};//我的书 public static void showBook(){ for (String show : books) { System.out.println(show); } } } import java.util.Scanner; public class SystemRun extends Library { public static void rentWay1(){ System.out.println("您将要进行序号检索!! "); System.out.println("请输入图书序号"); try { Scanner input = new Scanner(System.in); int bookNum = input.nextInt(); System.out.println("您的书籍为:"+books[bookNum-1]); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("您的输入有误!!"); Library(); } } public static void rentWay2(){ System.out.println("您将要进行名称检索!!"); System.out.println("请输入图书名称!!"); try { Scanner input = new Scanner(System.in); String bookName = input.next(); switch (bookName) { case "线性代数": bookNum = 1; bookName = "线性代数"; System.out.println("您的图书已找到"+bookNum+bookName); break; case"概率分析": bookNum= 2; bookName="概率分析"; System.out.println("您的图书已找到"+bookNum+bookName); break; case"Java语言": bookNum= 3; bookName = "Java语言"; System.out.println("您的图书已找到"+bookNum+bookName); break; case"三体": bookNum= 4; bookName="三体"; System.out.println("您的图书已找到"+bookNum+bookName); break; case"高数": bookNum = 5; bookName= "高数"; System.out.println("您的图书已找到"+bookNum+" "+bookName); break; default: System.err.println("您的图书早不到!!"); break; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("您的输入有误!!"); Library(); } } }
一起合作刷积分@!!!
写得不错。
public static void main(String[] args) {
Library manger = new Library();
manger.Library();
1,静态方法调用静态方法不需要对象调用,直接就可以,2,这里也不需要用到继承,直接写三个方法就可以了,然后main再调用;3,你要考虑循环查找,有可能要查找好几本,
很乱,变量,数组等定义,位置不是很规范
自己有没有运行过,
可以啊,你的问题我没搞懂
如果不是,让程序重新开始
请教:几处调用 Library();的意图?是让程序重新开始?