JAVA的作业,求大神的帮忙,急等谢谢!

编写程序,首先定义一个类Book,类的属性包括title、author、press、price,成员方法包括构造方法、各属性的get方法和set方法、显示全部属性的方法Display();然后在主类的main()函数中定义Book类的一个对象book,对象的书名为“大数据技术”,作者为“黄宜华”,出版社为“高教出版社”,价格为89元,并调用对象的Display()方法显示对象的全部信息。

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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-07
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();
}
}
第2个回答  2016-06-07
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();
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网