JAVA的作业,求大神的帮忙,急等谢谢!
编写程序,首先定义一个类Book,类的属性包括title、author、press、price,成员方法包括构造方法、各属性的get方法和set方法、显示全部属性的方法D...
编写程序,首先定义一个类Book,类的属性包括title、author、press、price,成员方法包括构造方法、各属性的get方法和set方法、显示全部属性的方法Display();然后在主类的main()函数中定义Book类的一个对象book,对象的书名为“大数据技术”,作者为“黄宜华”,出版社为“高教出版社”,价格为89元,并调用对象的Display()方法显示对象的全部信息。
展开
3个回答
展开全部
Java代码:
class Book {
protected String title;
protected String author;
protected String press;
protected double price;
public Book(String title, String author, String press, double price) {
this.title = title;
this.author = author;
this.press = press;
this.price = price;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return this.author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return this.press;
}
public void setPress(String press) {
this.press = press;
}
public double getPrice() {
return this.price;
}
public void setPrice(double price) {
this.price = price;
}
public void display() {
System.out.println("Book info:");
System.out.println("Title:\t" + title);
System.out.println("Author:\t" + author);
System.out.println("Press:\t" + press);
System.out.println("Price:\t" + price);
}
}
public class Test {
public static void main(String[] args) {
Book book = new Book("大数据技术", "黄宜华", "高教出版社", 89);
book.display();
}
}
运行效果:
Book info:
Title: 大数据技术
Author: 黄宜华
Press: 高教出版社
Price: 89.0
展开全部
public class Book {
private String title;
private String author;
private String press;
private double price;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public void Display(){
System.out.println("title:"+this.title);
System.out.println("author:"+this.author);
System.out.println("press:"+this.press);
System.out.println("price:"+this.price);
}
public static void main(String[] args) {
Book book = new Book();
book.setAuthor("黄宜华");
book.setTitle("大数据技术");
book.setPress("高教出版社");
book.setPrice(89);
book.Display();
}
}
private String title;
private String author;
private String press;
private double price;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public void Display(){
System.out.println("title:"+this.title);
System.out.println("author:"+this.author);
System.out.println("press:"+this.press);
System.out.println("price:"+this.price);
}
public static void main(String[] args) {
Book book = new Book();
book.setAuthor("黄宜华");
book.setTitle("大数据技术");
book.setPress("高教出版社");
book.setPrice(89);
book.Display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Book {
private String title;
private String author;
private String press;
private String price;
public Book(){}
/**
*
* @param title
* @param author
* @param press
* @param price
*/
public Book(String title,String author,String press,String price){
this.author=author;
this.title=title;
this.press=press;
this.price=price;
}
public void Display(){
System.out.println("书名:"+this.title);
System.out.println("作者:"+this.author);
System.out.println("出版社:"+this.press);
System.out.println("价格:"+this.price+"元");
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public static void main(String args[]) {
Book book=new Book("大数据技术","黄宜华","高教出版社","98");
book.Display();
}
}
private String title;
private String author;
private String press;
private String price;
public Book(){}
/**
*
* @param title
* @param author
* @param press
* @param price
*/
public Book(String title,String author,String press,String price){
this.author=author;
this.title=title;
this.press=press;
this.price=price;
}
public void Display(){
System.out.println("书名:"+this.title);
System.out.println("作者:"+this.author);
System.out.println("出版社:"+this.press);
System.out.println("价格:"+this.price+"元");
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public static void main(String args[]) {
Book book=new Book("大数据技术","黄宜华","高教出版社","98");
book.Display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询