Counter 翻译是计数器,我就不当实体类写了public class Counter {
private int a;
private int b;
private int c;
public Counter(int a,int b,int c){
this.a = a;
this.b = b;
this.c = c;
}
public void AddA(int a){
this.a+=a;
}
public void AddB(int b){
this.b+=b;
}
public void AddC(int c){
this.c+=c;
}
public void getMoney(){
System.out.println("a的存款:"+a+"b的存款:"+b+"c的存款"+c+"总余额"+(a+b+c));
}
}
主方法随便放哪public static void main(String[] args) {
Counter con = new Counter(0, 0, 0);
con.AddA(1000);
con.AddB(500);
con.AddC(500);
con.AddA(2500);
con.AddB(500);
con.getMoney();
}