其他分享
首页 > 其他分享> > 微信红包平均分法

微信红包平均分法

作者:互联网

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

}
 

标签:红包,name,微信,ArrayList,totalMoney,list,double,public,平均分
来源: https://www.cnblogs.com/resort-033/p/13027659.html