JAVA设计并实现类book,所包含的实例数据表示书名、作者、出版社及版权日期。

设计并实现类Book,所包含的实例数据表示书名、作者、出版社及版权日期。Book构造方法接收和初始化这些数据,并定义接收和设置这些数据的方法。定义toString方法返回... 设计并实现类Book,所包含的实例数据表示书名、作者、出版社及版权日期。 Book构造方法接收和初始化这些数据,并定义接收和设置这些数据的方法。定义toString方法返回多行且格式美观的描述书的字符串。创建驱动雷Bookshelf,该类的main方法实例化并更新若干个Book对象。

悲剧啊,求各位大哥给我下。139409414@qq.com
搞不出来要挂科了。在线急等。!
展开
 我来答
dreamwangqing
2011-01-12 · 超过51用户采纳过TA的回答
知道小有建树答主
回答量:129
采纳率:0%
帮助的人:161万
展开全部
class Book { //定义Book类
private String bookName; //书名
private String author; //作者
private String publisher; //出版社
private String publishDate; //出版日期

public Book(String bookName, String author, String publisher, String publishDate) { //构造方法
this.setBookName(bookName);
this.setAuthor(author);
this.setPublisher(publisher);
this.setPublishDate(publishDate);
}

public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBookName() {
return bookName;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAuthor() {
return author;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getPublisher() {
return publisher;
}
public void setPublishDate(String publishDate) {
this.publishDate = publishDate;
}
public String getPublishDate() {
return publishDate;
}
public String toString() {
return "|--书名:" + this.getBookName() + "\n\t" + "|--作者:" + this.getAuthor() +
"\n\t" + "|--出版社:" + this.getPublisher() + "\n\t" + "|--出版日期:" + this.getPublishDate();
}
}

public class BookShelf {
public static void main(String[] args) {
Book b1 = new Book("书名1", "作者1", "出版社1", "2010-01-01");
System.out.println(b1);
Book b2 = new Book("书名2", "作者2", "出版社2", "2010-02-02");
System.out.println(b2);
Book b3 = new Book("书名3", "作者3", "出版社3", "2010-03-03");
System.out.println(b3);
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
willhard
2011-01-12
知道答主
回答量:15
采纳率:0%
帮助的人:7.4万
展开全部
package com.wondersgroup.wssip.bc.i1.retirepersonmgmt.bs;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

class Bookshelf {
public static void main(String[] args) {
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");

try {
Book b1=new Book("射雕英雄传","金庸","什么出版社忘记了",formatter.parse("1985-01-01"));
Book b2=new Book("神雕侠侣","金庸","什么出版社忘记了",formatter.parse("1986-11-01"));
//System.out.println(b1.getPubDate().toLocaleString());
System.out.println("更新前……");
System.out.println(b1);
System.out.println(b2);

b1.setAuthor("不是我");
b1.setPubCompany("xxx出版社");
b1.setPubDate(new Date());

b2.setAuthor("反正不是我");
b2.setPubCompany("YYYY出版社");
b2.setPubDate(new Date());
System.out.println("\n\n更新后……");
System.out.println(b1);
System.out.println(b2);

}
catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
class Book{

private String name;
private String author;
private String pubCompany;
private Date pubDate;
public Book(String name, String author, String pubCompany, Date pubDate) {
super();
this.name = name;
this.author = author;
this.pubCompany = pubCompany;
this.pubDate = pubDate;
}
public Book() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPubCompany() {
return pubCompany;
}
public void setPubCompany(String pubCompany) {
this.pubCompany = pubCompany;
}
public Date getPubDate() {
return pubDate;
}
public void setPubDate(Date pubDate) {
this.pubDate = pubDate;
}
@Override
public String toString() {
StringBuilder sb=new StringBuilder();
sb.append("\nname: "+this.getName());
sb.append("\nauthor: "+this.getAuthor());
sb.append("\npubCompany: "+this.getPubCompany());
sb.append("\npubDate: "+this.getPubDate().toLocaleString());
return sb.toString();
}

}
自己真是闲得蛋疼。几年前曾经写过这个。哈哈
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式