package sentmoney;
import java.util.ArrayList;
public class demomain {
public static void main(String[] args) {
manner ma=new manner("群主",500);
manber one=new manber("one",100);
manber two=new manber("two",100);
manber three=new manber("three",100);
ma.show();
one.show();
two.show();
three.show();
System.out.println("=============");
ArrayList<Integer> list=ma.sent(100,3);
one.now(list);
two.now(list);
three.now(list);
}
}
package sentmoney;
public class users {
private String name;
private int money;
public users(String name, int money) {
this.name = name;
this.money = money;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public void show()
{
System.out.println("我的名字是:"+name+",账户余额为:"+money);
}
}
package sentmoney;
import java.util.ArrayList;
public class manner extends users {
public manner(String name, int money) {
super(name, money);
}
public ArrayList<Integer> sent(int totalmoney,int count)
{
ArrayList<Integer> list=new ArrayList<>();
int nowmoney=super.getMoney();
if(nowmoney<totalmoney)
{
System.out.println("余额不足!");
}
else{
int avg=totalmoney/count;
int der=totalmoney%count;
int last=avg+der;
for(int i=0;i<count-1;i++)
{
list.add(avg);
}
list.add(last);
super.setMoney(nowmoney-totalmoney);
super.show();
}
return list;
}
}
package sentmoney;
import java.util.ArrayList;
import java.util.Random;
public class manber extends users {
public manber(String name, int money) {
super(name, money);
}
public void now(ArrayList<Integer>list)
{
int nowmoney=super.getMoney();
int in= new Random().nextInt(list.size());
int der=list.remove(in);
nowmoney=nowmoney+der;
super.setMoney(nowmoney);
super.show();
}
}