类的继承之发红包的案例----Java
2020-12-18 16:33
标签:class xtend his next info strong 完成 规则 oid 群主发普通红包 群主发普通红包。某群有多名成员,群主给成员发普通红包。普通红包的规则: 类的继承之发红包的案例----Java 标签:class xtend his next info strong 完成 规则 oid 原文地址:https://www.cnblogs.com/zeon/p/13385473.html
1. 群主的一笔金额,从群主余额中扣除,平均分成n等份,让成员领取。
2. 成员领取红包后,保存到成员余额中。
请根据描述,完成案例中所有类的定义以及指定类之间的继承关系,并完成发红包的操作。 1 public class User {
2
3 private String name ; //姓名
4 private int money ; //金额
5
6 public User() {
7 }
8
9 public User(String name, int money) {
10 this.name = name;
11 this.money = money;
12 }
13 // 展示当前用户有多少钱
14 public void show(){
15 System.out.println("姓名:" + name +" 余额:" + money);
16 }
17 public String getName() {
18 return name;
19 }
20
21 public void setName(String name) {
22 this.name = name;
23 }
24
25 public int getMoney() {
26 return money;
27 }
1 import java.util.ArrayList;
2
3 public class Manager extends User{
4
5 public Manager(){
6 //super();默认赠送
7 }
8
9 public Manager(String name, int money) {
10 super(name, money);
11 }
12
13
14 public ArrayList
1 import java.util.ArrayList;
2 import java.util.Random;
3
4 public class Member extends User{
5
6 public Member() {
7 }
8
9 public Member(String name, int money) {
10 super(name, money);
11 }
12
13 public void receive(ArrayList
1 import java.util.ArrayList;
2
3 public class MainRedPacket {
4
5 public static void main(String[] args) {
6 Manager manager = new Manager("群主", 200);
7
8 Member one = new Member("成员A", 0);
9 Member two = new Member("成员B", 0);
10 Member three = new Member("成员C", 0);
11 Member four = new Member("成员D", 0);
12 Member five = new Member("成员E", 0);
13 Member six = new Member("成员F", 0);
14
15 manager.show();
16 one.show();
17 two.show();
18 three.show();
19 four.show();
20 five.show();
21 six.show();
22 System.out.println("==========");
23
24
25 //群主开始发红包
26 ArrayList
下一篇:线程相关工具类
文章标题:类的继承之发红包的案例----Java
文章链接:http://soscw.com/index.php/essay/37121.html