java编程题 希望大家能够帮助我一下,谢谢?
package book;
/**
* @Author: Cool_Wu
* @Date: 2020-12-07 20:18
*/
public class Book {
private String name;
private String num;
private String author;
private double price;
private String publishing_House;
private String publication_Date;
public Book() {}
public Book(String name, String num, String author, double price, String publishing_House, String publication_Date) {
this.name = name;
this.num = num;
this.author = author;
this.price = price;
this.publishing_House = publishing_House;
this.publication_Date = publication_Date;
}
@Override
public String toString() {
return "图书信息:\n----------------------" +
"\n书名:" + name +
"\n书号:" + num +
"\n作者:" + author +
"\n单价:" + price +
"\n出版社:" + publishing_House +
"\n出版日期:" + publication_Date +
"\n----------------------\n";
}
}
package book;
public class Test {
public static void main(String[] args) {
Book book1 = new Book("百年孤独","10000","加西亚·马尔克斯",40.00,"南海出版公司","2017年08月");
System.out.println(book1);
Book book2 = new Book("时间简史","10086","史蒂芬·霍金",22.50,"湖南科技出版社","2014年06月");
System.out.println(book2);
}
}
您好,不知道是不是您要的答案。
package com.test;
import java.math.BigDecimal;
import java.util.Date;
/**
* 用于描述当当网中图书商品的信息,序号01
*/
public class Book {
//Id
private int id;
//书名
private String bookName;
//书号
private int bookNum;
//作者
private String author;
//单价
private BigDecimal price;
//出版社
private String press;
//出版日期
private Date publish;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getBookNum() {
return bookNum;
}
public void setBookNum(int bookNum) {
this.bookNum = bookNum;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public Date getPublish() {
return publish;
}
public void setPublish(Date publish) {
this.publish = publish;
}
/**
* 打印输出图书的基本信息
*/
@Override
public String toString() {
return "Book [id=" + id + ", bookName=" + bookName + ", bookNum=" + bookNum + ", author=" + author + ", price="
+ price + ", press=" + press + ", publish=" + publish + "]";
}
}
package com.test;
import java.math.BigDecimal;
import java.util.Date;
public class Book_01 {
public static void main(String[] args) {
Book book1 = new Book();
Book book2 = new Book();
book1.setId(1);
book1.setBookName("新华字典");
book1.setBookNum(1001);
book1.setAuthor("小可爱");
book1.setPrice(new BigDecimal(50));
book1.setPress("新华大学出版社");
book1.setPublish(new Date());
book2.setId(2);
book2.setBookName("Java");
book2.setBookNum(1002);
book2.setAuthor("小坏蛋");
book2.setPrice(new BigDecimal(100));
book2.setPress("程序员出版社");
book2.setPublish(new Date());
System.out.println(book1.toString());
System.out.println(book2.toString());
}
}
//书名、书号、作者、单价、出版社、出版日期等)
public class Book {
private String bookName;
private String isbn;
private String author;
private Double price;
private String publisher;
private Date date;
public Book () {}
public Book (String bookName, String isbn, String author,
Double price, String publisher, Date date) {
this.bookName = bookName;
this.isbn = isbn;
this.author = author;
this.price = price;
this.publisher = publisher;
this.date = date;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Override
public String toString() {
return "Book [bookName=" + bookName + ", isbn=" + isbn + ", author=" + author + ", price=" + price
+ ", publisher=" + publisher + ", date=" + date + "]";
}
}
import java.util.Date;
//再定义一个以自己姓名命名的主类(类名最后包含本题序号),在该类main方法中创建图书类的2个对象,
//给对象的各个成员变量赋值,并调用它的方法。
public class ZhuGe02 {
public static void main(String[] args) {
Book book01 = new Book("面朝大海春暖花开", "1233-233", "海子", 45.5, "中国人民大学出版社", new Date());
System.out.println("===============图书1的信息================");
System.out.println(book01.toString());
Book book02 = new Book();
book02.setBookName("闰土");
book02.setIsbn("1111-222");
book02.setAuthor("鲁迅");
book02.setPrice(78.6);
book02.setPublisher("浙江大学出版社");
book02.setDate(new Date());
System.out.println("===============图书2的信息================");
System.out.println(book02.toString());
}
}