public class Paint //1 name of class { //2 Attributes private String name; private double price; private double w; //width private double h; //height //3 constructor public Paint(String name, double price, double w, double h) { this.name = name; this.price = price; this.w = w; this.h = h; } //3 getters and setters public String getName() { return this.name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public double getW() { return w; }
public void setW(double w) { this.w = w; } public double getH() { return h; }
public void setH(double h) { this.h = h; } // 5 printinng method public String toString() { String str = "Name of Paint:"+this.name; str=str+"\nPrice:"+this.price; str=str+"\nSize:"+this.w+"x"+this.h; return str; } public double area() { return w*h; } } |