不同于老师说的结构,但实现同样效果,不知道两种方法有什么区别

来源:1-9 经验总结

慕瓜6161585

2020-08-07 11:09

每本书创建成单独类调用

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;

}

       

//        

        

        }

}

}


写回答 关注

1回答

  • 慕的地2195603
    2020-10-13 00:02:49

    当书本数量很多的时候,一个个创建类就麻烦了

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409773 学习 · 4341 问题

查看课程

相似问题