java:创建一个桌子Table类,该类中有桌子名称,重量,桌面宽度,长度及桌子高度属性.
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/06/02 15:00:15
java:创建一个桌子Table类,该类中有桌子名称,重量,桌面宽度,长度及桌子高度属性.
其中有:
1) 编写一个无参的构造方法和带4个参数的构造方法初始化所有数据成员
2) int area() :计算桌面的面积
3) void display():在屏幕上输出所有数据成员的值
4) 建立每个属性的get和set方法
注意:桌子的重量,宽度、长度和高度初始化时不能为负数,改变属性值时也不能为负数.
我是java初学者,老师不值得作业,有点迷茫,
其中有:
1) 编写一个无参的构造方法和带4个参数的构造方法初始化所有数据成员
2) int area() :计算桌面的面积
3) void display():在屏幕上输出所有数据成员的值
4) 建立每个属性的get和set方法
注意:桌子的重量,宽度、长度和高度初始化时不能为负数,改变属性值时也不能为负数.
我是java初学者,老师不值得作业,有点迷茫,
public class Table {
// 名称
private String name;
// 重量
private float weight;
// 宽度
private float width;
// 高度
private float height;
// 长度
private float length;
public Table() {
}
// 带4个参数的构造方法初始化所有数据成员
public Table(float weight, float width, float height, float length) {
super();
if (weight < 0 || height < 0 || width < 0 || length < 0) {
System.out.println("桌子的重量,宽度、长度和高度初始化时不能为负数");
} else {
this.weight = weight;
this.width = width;
this.height = height;
this.length = length;
}
}
// 计算桌面面积
public int area() {
return (int) (this.length * this.width);
}
public void display() {
System.out.println("名字:" + name + ";桌面长度:" + length + ";桌面宽度:" + width
+ ";重量:" + weight+";高度:"+height);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
if (weight < 0) {
System.out.println("桌子的重量不能为负数");
} else {
this.weight = weight;
}
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
if (width < 0) {
System.out.println("桌子的宽度不能为负数");
} else {
this.width = width;
}
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
if (height < 0) {
System.out.println("桌子的高度不能为负数");
} else {
this.height = height;
}
}
public float getLength() {
return length;
}
public void setLength(float length) {
if (height < 0) {
System.out.println("桌子的长度不能为负数");
} else {
this.length = length;
}
}
}
另外 5个属性 4个参数 初始化全部 不能理解
// 名称
private String name;
// 重量
private float weight;
// 宽度
private float width;
// 高度
private float height;
// 长度
private float length;
public Table() {
}
// 带4个参数的构造方法初始化所有数据成员
public Table(float weight, float width, float height, float length) {
super();
if (weight < 0 || height < 0 || width < 0 || length < 0) {
System.out.println("桌子的重量,宽度、长度和高度初始化时不能为负数");
} else {
this.weight = weight;
this.width = width;
this.height = height;
this.length = length;
}
}
// 计算桌面面积
public int area() {
return (int) (this.length * this.width);
}
public void display() {
System.out.println("名字:" + name + ";桌面长度:" + length + ";桌面宽度:" + width
+ ";重量:" + weight+";高度:"+height);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
if (weight < 0) {
System.out.println("桌子的重量不能为负数");
} else {
this.weight = weight;
}
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
if (width < 0) {
System.out.println("桌子的宽度不能为负数");
} else {
this.width = width;
}
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
if (height < 0) {
System.out.println("桌子的高度不能为负数");
} else {
this.height = height;
}
}
public float getLength() {
return length;
}
public void setLength(float length) {
if (height < 0) {
System.out.println("桌子的长度不能为负数");
} else {
this.length = length;
}
}
}
另外 5个属性 4个参数 初始化全部 不能理解
创建一个桌子Table类,该类中有桌子名称、重量、桌面宽度、长度和桌子高度属性,以及以下几个方法.(1)
桌子的尺寸高度
桌子上有许多西红柿 There are ( ) ( ) ( )on the table
桌子的高度和凳子的高度有什么关系?
用英语翻译:桌子上有一个苹果
桌子上有一个书翻译英语
汉译英:桌子上有一个钟
有一个容器,倒扣在桌子上
英语:桌子旁边有一个衣柜
在桌子下面有一个书包 翻译
走进一个房间,看到桌子上放着一个梨,走进第二个房间,有看见桌子上放着一个梨,打一个国家的名称?如题
有一张长方形桌子的桌面长100cm,宽60cm.有一块长方形台布的面积是桌面面积的2倍.并且铺在桌子上时,各边垂下的长度