编写程序,首先定义一个类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();
}
}
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();
}
}
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();
}
}