package hongbao;
import java.util.ArrayList;
public abstract class user {
private String name;
private double totalMoney;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getTotalMoney() {
return totalMoney;
}
public void setTotalMoney(double totalMoney) {
this.totalMoney = totalMoney;
}
public user(String name, double totalMoney) {
this.name = name;
this.totalMoney = totalMoney;
}
public abstract void fahongbao(ArrayList<Double> list);
public abstract void shouhongbao(ArrayList<Double> list);//user.java
}
package hongbao;
import java.util.ArrayList;
public class qunyuan extends user {
private int num;
public qunyuan(String name, double totalMoney,int num) {
super(name, totalMoney);
this.num=num;
}
@Override
public void fahongbao(ArrayList<Double> list) {
}
@Override
public void shouhongbao(ArrayList<Double> list) {
Random r = new Random();
int num = 0;
try {
num = r.nextInt(list.size());
System.out.println("已收款" + list.remove(num));
setTotalMoney(super.getTotalMoney() + list.remove(num));
System.out.println("余额: " + getTotalMoney());
}catch (IllegalArgumentException e){
System.out.println("无法生成红包");
}
}
}//qunyuan.java
package hongbao;
import java.util.ArrayList;
public class demo_hongbao {
public static void main(String[] args){
qunzhu qz=new qunzhu("alex",3000);
qunyuan qy1=new qunyuan("Linda",200,1);
ArrayList<Double> list=new ArrayList<>();
qz.fahongbao(list);
qy1.shouhongbao(list);
}
}//hongbao_demo
package hongbao;
import java.util.ArrayList;
import java.util.Scanner;
public class qunzhu extends user {
public qunzhu(String name, double totalMoney) {
super(name, totalMoney);
}
public void fahongbao(ArrayList<Double> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入金额");
int i = sc.nextInt();
if (i <= super.getTotalMoney()&&i>=0) {
setTotalMoney((double) getTotalMoney() - i);
System.out.println("请输入红包数量");
int j = sc.nextInt();
double money = (double) i / j;
for (double x = 0; x < j; x++) {
list.add(money);
}
System.out.println("群主余额为: " + getTotalMoney());
}else {
System.out.println("余额不足");
}
}
@Override
public void shouhongbao(ArrayList<Double> list) {
}//qunzhu.java
}