不同于老师说的结构,但实现同样效果,不知道两种方法有什么区别
每本书创建成单独类调用
package com.xiaohongshu;
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("书库中的图书目录:");
System.out.println("1.《红楼梦》");
System.out.println("2.《三国演义》");
System.out.println("3.《水浒传》");
System.out.println("4.《西游记》");
while(true) {
System.out.println("请输入图书的编号或名字:");
Scanner input=new Scanner(System.in);
String score=input.next();
switch (score) {
case "1" :
case "红楼梦":
book hello=new HongLouMeng();
hello.name();
hello.category();
hello.author();
break;
case "2":
case "三国演义":
book hello2=new SanGuoYanYi();
hello2.name();
hello2.category();
hello2.author();
break;
case "3":
case "水浒传":
book hello3=new ShuiHuZhuan();
hello3.name();
hello3.category();
hello3.author();
break;
case "4":
case "西游记":
book hello4=new SanGuoYanYi();
hello4.name();
hello4.category();
hello4.author();
break;
default:
System.out.println("输入错误,请重新输入!");
continue;
}
//
}
}
}