public class Test{
public static void main(String[] args)
{
TableInfo t=new TableInfo("Round",4,100,7850);
Worker w1 = new Worker("zhang",50,4500,1,t);
w1.display();
}
}
class Worker {
private String name;
private int age;
private double salary;
private int level;
private TableInfo table;
public Worker(String name,int age,double salary,int level,TableInfo table){
this.name=name;
this.age=age;
this.salary=salary;
this.level=level;
this.table=table;
}
public Worker(String name)
{
this.name=name;
this.age=0;
this.salary=0;
this.level=0;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return this.age;
}
public void setSalary(double salary){
this.salary=salary;
}
public double getSalary(){
return this.salary;
}
public void setLevel(int level){
this.level=level;
}
public int getLevel(){
return this.level;
}
public void setTable(TableInfo table){
this.table=table;
}
public TableInfo getTable(){
return this.table;
}
public void display(){
System.out.println("Name="+name);
System.out.println("Age="+age);
System.out.println("Salary="+salary);
System.out.println("Level="+level);
table.print();
}
}
class TableInfo{
String shape;
int legs;
int hight;
double area;
public TableInfo(String shape, int legs,int hight,double area){
this.shape = shape;
this.legs = legs;
this.hight = hight;
this.area = area;
}
public void print(){
System.out.println("My Table is:" + shape);
}
}
【问题描述】请根据已知的程序代码,补全类Worker,显示工人和桌子的信息。【输入形式】无【输出形式】Name=zhangAge=50Salary=4500.0Level=1
最新推荐文章于 2022-04-06 09:25:57 发布