JavaSE进阶

(7)NoteBook、PC、Printer类

观察显示格式:

  • NoteBook显示的是型号(价格)
  • PC显示的是型号(显示器)
  • Printer显示的是名称(类型)

package com.atguigu.bean;

public class NoteBook implements Equipment{

private String model;//型号

private double price;//价格

public NoteBook() {

super();

}

public NoteBook(String model, double price) {

super();

this.model = model;

this.price = price;

}

public String getModel() {

return model;

}

public void setModel(String model) {

this.model = model;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

@Override

public String getDescription() {

return model+"("+price+")";

}

@Override

public String toString() {

return getDescription();

}

}

package com.atguigu.bean;

public class PC implements Equipment{

private String model;//型号

private String display;//显示器

public PC() {

super();

}

public PC(String model, String display) {

super();

this.model = model;

this.display = display;

}

public String getModel() {

return model;

}

public void setModel(String model) {

this.model = model;

}

public String getDisplay() {

return display;

}

public void setDisplay(String display) {

this.display = display;

}

@Override

public String getDescription() {

return model +"("+ display+")";

}

@Override

public String toString() {

return getDescription();

}

}

package com.atguigu.bean;

public class Printer implements Equipment {

private String type;//类型

private String name;//名称

public Printer() {

super();

}

public Printer(String type, String name) {

super();

this.type = type;

this.name = name;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

@Override

public String getDescription() {

return name + "(" + type + ")";

}

@Override

public String toString() {

return getDescription();

}

}