JAVA设计并实现类book,所包含的实例数据表示书名、作者、出版社及版权日期。
设计并实现类Book,所包含的实例数据表示书名、作者、出版社及版权日期。Book构造方法接收和初始化这些数据,并定义接收和设置这些数据的方法。定义toString方法返回...
设计并实现类Book,所包含的实例数据表示书名、作者、出版社及版权日期。 Book构造方法接收和初始化这些数据,并定义接收和设置这些数据的方法。定义toString方法返回多行且格式美观的描述书的字符串。创建驱动雷Bookshelf,该类的main方法实例化并更新若干个Book对象。
悲剧啊,求各位大哥给我下。139409414@qq.com
搞不出来要挂科了。在线急等。! 展开
悲剧啊,求各位大哥给我下。139409414@qq.com
搞不出来要挂科了。在线急等。! 展开
2个回答
展开全部
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);
}
}
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);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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();
}
}
自己真是闲得蛋疼。几年前曾经写过这个。哈哈
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();
}
}
自己真是闲得蛋疼。几年前曾经写过这个。哈哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询