标题:问程序错误的解法,在图书管理程序中,类Book,Newspaper和Video都是Media的 ...
只看楼主
茯苓
Rank: 1
等 级:新手上路
帖 子:5
专家分:6
注 册:2013-9-20
结帖率:0
已结贴  问题点数:20 回复次数:2 
问程序错误的解法,在图书管理程序中,类Book,Newspaper和Video都是Media的子类。编写一个类,该类能够实现对一组书,报纸等的存储,并提供一定的
public abstract class Media {
public String name;
public String authorName;
public abstract String toString();
public Media(String name,String authorName){
this.name=name;
this.authorName=authorName;
}
}
class Book extends Media {
public String name;
public String authorName;
public Book(String name,String authorName){
super(name,authorName);
this.name=name;
this.authorName=authorName;
}
public String toString(){
String message="书名为"+name+",作者是"+authorName+"";
return message;
}
}
class Newspapper extends Media{
public String name;
public String authorName;
public Newspapper(String name,String authorName){
super(name,authorName);
this.name=name;
this.authorName=authorName;
}
public String toString(){
String message="报名为"+name+",编辑是"+authorName+"";
return message;
}
}
import java.util.*;
public class Manage {
public static ArrayList<Media> a=new ArrayList<Media>();
public static void find(String name){
Iterator<Media> ite=a.iterator();
while(ite.hasNext()){
Media exe=ite.next();
if(exe.name==name||exe.authorName==name){
System.out.println(exe.toString());
return;
}
}
System.out.println("没有此记录");
}
public void add(Media m){
a.add(m);
}
public static void main(String args[]){
Media temp1=new Book("钢铁是怎样炼成的","保尔.柯察金");
a.add(temp1);
Media temp2=new Newspapper("人民日报","李刚");
a.add(temp2);
Media temp3=new Book("一座城池","韩寒");
Media temp4=new Book("平凡的世界","路遥");
a.add(temp3);
a.add(temp4);
Manage.find("路遥");
}
}

搜索更多相关主题的帖子: abstract message 管理程序 public return 
2013-10-23 14:57
格式化秘密
Rank: 2
等 级:论坛游民
帖 子:31
专家分:57
注 册:2013-8-13
得分:20 
提供一定的什么?
2013-10-27 17:23
xihe
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-4-3
得分:0 
这是不是没有video部分啊?
2019-04-03 09:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-422390-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019432 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved