创建以下两个子类,扩展练习1中的artwork类。具有以下特性的雕塑:
材料
具有以下特性的权重绘制:
油漆类型(如水彩画、亚克力画、油画)
画布宽度
画布高度将相关的构造器(使用super)、getter和setter添加到雕刻和绘画类中。你的绘画和雕塑课程必须扩展基础艺术课程。在您的设置程序中,添加画布宽度、重量和画布高度的验证,以防止存在大小/重量为负值的艺术品。如果创建了无效的绘图,则应显示错误。向程序中至少添加一个雕刻对象和一个绘画对象,并调用超类和子类方法。我希望程序不接受高度和宽度的负值。但是当我接受输入时,它不起作用,也就是说,它接受负值
class Artwork2 {
String Artist;
int Value;
public Artwork2(String artist, int value) {
this.Artist=artist;
this.Value=value;
}
public int getValue() {
return this.Value;
}
public void setValue(int value) {
this.Value=value;
}
public String getArtist() {
return this.Artist;
}
public void setArtist(String artist) {
this.Artist=artist;
}
}
class Sculpture extends Artwork2 {
protected String material;
protected double weight;
public Sculpture(String artist, int value, String material, double weight) {
super(artist, value);
this.material=material;
this.weight=weight;
}
public String getMaterial() {
return this.material;
}
public void setMaterial(String material) {
this.material=material;
}
public double getWeight() {
return this.weight;
}
public void setWeight(double weight) {
this.weight=weight;
}
}
class Painting extends Artwork2 {
protected String paintType;
protected double canvasWidth;
protected double canvasHeight;
public Painting(String artist, int value,String paintType, double canvasWidth, double canvasHeight) {
super(artist, value);
this.paintType=paintType;
this.canvasHeight=canvasWidth;
this.canvasWidth=canvasHeight;
}
public double getCanvasWidth() {
return this.canvasWidth;
}
public void setCanvasWidth(double canvasWidth) {
this.canvasWidth=canvasWidth;
}
public double getCanvasHeight() {
return this.canvasHeight;
}
public void setCanvasHeight(double canvasHeight) {
if (canvasHeight < 0) {
throw new IllegalArgumentException();}
this.canvasHeight = canvasHeight;
}
public String getPaintType() {
return this.paintType;
}
public void setPaintType(String paintType) {
this.paintType=paintType;
}
}
public class SuperClass {
public static void main(String[] args) {
Sculpture sculpture= new Sculpture("lap", 1000,"top", 99);
system.out.println(sculpture.getartist()+sculpture.getmaterial()+sculpture.getvalue()+sculpture.getweight());
Scanner in=new Scanner(System.in);
double canvas=in.nextDouble();
Painting painting =new Painting("lap", -1000,"oil", canvas, -10);
System.out.println(painting.getArtist()+
painting.getCanvasHeight()+painting.getCanvasWidth()+painting.getPaintType()+
painting.getValue());
}
}
暂无答案!
目前还没有任何答案,快来回答吧!