中易网

Java程序:创建一个桌子(Table)类,该类中有桌子名称、重量、桌面宽度、长度和桌子高度属性,以及以下几个

答案:1  悬赏:50  
解决时间 2021-01-15 09:12
  • 提问者网友:欲望失宠
  • 2021-01-14 15:23
Java程序:创建一个桌子(Table)类,该类中有桌子名称、重量、桌面宽度、长度和桌子高度属性,以及以下几个
最佳答案
  • 二级知识专家网友:话散在刀尖上
  • 2021-01-14 16:05
package com.kaylves;
public class Table {
private String tableName;//名称

private int weight; //重量

private int length; //长度

private int height; //高度

private int width; //宽度

public Table(){
tableName="";
}
public Table(String tableName,int weight,int length,int height,int width){
this.tableName=tableName;
this.weight=weight;
this.length=length;
this.height=height;
this.width=width;
}
public int getArea(){
return length*width;
}

public void display(){
System.out.println("桌名称:"+this.tableName);
System.out.println("重量:"+this.weight);
System.out.println("长度:"+this.length);
System.out.println("高度:"+this.height);
System.out.println("宽度:"+this.width);
System.out.println("面积:"+this.getArea());
}

public void changeWeight(int w){
this.weight=w;
}

public static void main(String[] args){
Table table = new Table("小桌子",20,50,20,20);
int area=table.getArea();
table.changeWeight(30);
table.display();
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息