public class User {
private String name;
private int money;
public User(){
}
public User(String name,int money){
this.name=name;
this.money=money;
}
public void show(){
System.out.println("Name:"+name+" 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;
}
}
Manage类
import java.util.ArrayList;
public class Manager extends User{
public Manager(String name, int money) {
super(name, money);
}
public Manager() {
super();
}
//需要一个集合用来存储发红包的个数以及各个金额
public ArrayList<Integer> List(int totalmoney,int count){//发的钱
ArrayList<Integer> list = new ArrayList<>();
int leftmoney = super.getMoney();//群主总共的钱
if(leftmoney < totalmoney) return list;//群主没那么多钱
int averagemoney = totalmoney/count;//平均每个人
int modemoney = totalmoney%count;//除不尽的余数加在list最后一个
for(int i = 0 ; i < count-1 ; i++){
list.add(averagemoney);
}
super.setMoney(leftmoney - totalmoney);//群主剩的钱
list.add(modemoney+averagemoney);
return list;//返回红包集合
}
}
Member类
import java.util.ArrayList;
import java.util.Random;
public class Member extends User{
public Member() {
super();
}
public Member(String name, int money) {
super(name, money);
}
public void receive(ArrayList<Integer> list){
int random = new Random().nextInt(list.size());//随即索引
int num = list.remove(random);//将这个数去除,并且取出
int money = super.getMoney()+num;//把钱加上
super.setMoney(money);//更新前的金额
}
}
调用
import java.util.ArrayList;
import java.util.Scanner;
public class Using {
public static void main(String[] args) {
Member A= new Member("贤哥",0);
Member B = new Member("超哥",0);
Member C = new Member("小哥",0);
Manager qun = new Manager("群主",10000);
System.out.println("原来的钱");
qun.show();
A.show();
B.show();
C.show();
System.out.println("================");
System.out.println("你想发多少");
int F = new Scanner(System.in).nextInt();
ArrayList<Integer> list = qun.List(F,3);
A.receive(list);
B.receive(list);
C.receive(list);
qun.show();
A.show();
B.show();
C.show();
}
}
测试命令 java jar .\ZookeeperDemo-0.0.1-SNAPSHOT.jar bTest 192.168.206.100:2181 2
1. Barrier(阻塞原语)
1.1 概念 [!quote] A barrier is a primitive that enables a group of processes to synchronize the beginning and the end of a comput…
一、需求: AP通过AC上线。 AC通过控制VLAN管理AP,创建VLAN100和放行。 AP同AC建立CAPWAP关系。
二、实验拓扑图: 三、实验步骤: LSW1: sys Enter system view, return user view with CtrlZ. [Huawei]Sysname lsw1 [lsw1]undo info enable I…