3个回答
展开全部
public class ListDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Worker worker1=new Worker("zhang3", 18, new BigDecimal(3000));
Worker worker2=new Worker("li4", 25, new BigDecimal(3500));
Worker worker3=new Worker("wang5", 22, new BigDecimal(3200));
List<Worker> list=new ArrayList<>();
list.add(worker1);
list.add(worker2);
list.add(worker3);
System.out.println(list.toString());
}
static class Worker implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
String name;
int age;
BigDecimal money;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public BigDecimal getMoney() {
return money;
}
public void setMoney(BigDecimal money) {
this.money = money;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public Worker(String name,int age,BigDecimal money) {
// TODO Auto-generated constructor stub
this.name=name;
this.age=age;
this.money=money;
}
@Override
public String toString() {
return "Worker [name=" + name + ", age=" + age + ", money=" + money
+ "]";
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.*;
public final class Worker {
public final String name;
public final int age;
public final int wage;
public Worker(String name, int age, int wage){
this.name = name;
this.age = age;
this.wage = wage;
}
@Override public String toString(){
return String.format("工人[姓名:%s,年龄:%d,工资:%d]", name, age, wage);
}
public static void main(String[] args) {
ArrayList<Worker> workers = new ArrayList<>();
workers.add(new Worker("zhang3",18,3000));
workers.add(new Worker("li4",25,3500));
workers.add(new Worker("wang5",22,3200));
for(Worker worker: workers)
System.out.println(worker);
}
}
javac -encoding utf-8 Worker.java && java Worker
工人[姓名:zhang3,年龄:18,工资:3000]
工人[姓名:li4,年龄:25,工资:3500]
工人[姓名:wang5,年龄:22,工资:3200]
更多追问追答
追问
final 不是不能更改了吗?
追答
是
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-07-16
展开全部
public class Test{
public static void main(String...args){
List<Employee> list = new ArrayList<Employee>();
list.add(new Employee("zhang3",18,3000));
list.add(new Employee("li4",25,3500));
list.add(new Employee("wang5",22,3200));
}
}
class Employee{
private String name;
private int age;
private double salary;
public Employee(String name,int age,int salary){
this.name=name;
this.age=age;
this.salary.salary
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询