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) { System.out.println("已收款"+list.get(num)); setTotalMoney(super.getTotalMoney()+list.get(num)); System.out.println("余额: "+getTotalMoney()); } }//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();
setTotalMoney((double) super.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());
}
@Override
public void shouhongbao(ArrayList<Double> list) {
}//qunzhu.java
}