Java-石头剪刀布,银行管理系统

猜拳游戏

/**
 * @ClassName TestDemo1
 * @Description 石头剪刀布
 * @Author LiMingXu
 * @Date 2018/11/5 0:44
 * @Version 1.0
 **/
public class TestDemo1 {
    public static class People{
        private String name;
        private int score;
        public People(){

        }
        public People(String name){
            score = 0;
            this.name = name;
        }
        public String fist(){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入:石头 剪刀 布");
            String str = scanner.next();
            return str;
        }
        public void addScore(){
            score += 1;
        }
        public int getScore(){
            return score;
        }
        public String getName(){
            return name;
        }
    }
    ///
    static class Computer {
        private String name;
        private int score;

        public Computer(String name) {
            score = 0;
            this.name = name;
        }

        public String fist() {
            Random random = new Random(3);
            int n = random.nextInt() + 1;//[1,3]
            String str = null;
            switch (n) {
                case 1:
                    System.out.print(name + "出石头");str = "石头";break;
                case 2:
                    System.out.print(name + "对方出剪刀");str = "剪刀";
                    break;
                case 3:
                    System.out.print(name + "对方出布");str = "布";
                    break;
            }
            return str;
        }

        public void addScore() {
            score += 1;
        }

        public int getScore() {
            return score;
        }

        public String getName(){
            return name;
        }
    }
    public static class Game{
        private People people;
        private Computer computer;
        private Game(){
            People  people= new People("Tyone");
            Computer  computer= new Computer("Alpha");
        }
        public Game(People people,Computer computer){
            this.computer=computer;
            this.people=people;
        }
        private void playThreeTime(){
            int count = 0;
            while(count < 3){
                String pFist = people.fist();
                String cFist = computer.fist();
                if(pFist.equals("石头") && cFist.equals("剪刀") || pFist.equals("剪刀") && cFist.equals("布")||pFist.equals("布") && cFist.equals("石头")){
                    System.out.println(people.getName() + "本局获胜");
                    people.addScore();
                }else if(pFist.equals(cFist)){
                    System.out.println("平局!");
                }else{
                    System.out.println(computer.getName() + "本局获胜");
                    computer.addScore();
                }
                count ++;
            }
        }
        private void getResult(){
            int pScore = people.getScore();
            int cScore = computer.getScore();
            if(pScore > cScore){
                System.out.println(people.getName()+ "最终结果赢了");
            }else if(pScore == cScore) {
                System.out.println("平局");
            }else{
                System.out.println(computer.getName() + "最终结果赢了");
            }
            System.out.println(people.getName()+":"+computer.getName()+"="+people.getScore()+":"+computer.getScore);
        }
        public void start(){
            while(true){
                playThreeTime();
                getResult();
                System.out.println("是否继续?");
                Scanner scanner = new Scanner(System.in);
                String str = scanner.next();
                if(str.equals("是")){
                    continue;
                }else{
                    break;
                }
            }
        }
    }
    public static void main(String[] args) {
        People people= new People("Tyone");
        Computer computer = new Computer("Alpha");
        Game game = new Game(people,computer);
        game.start();
    }
}

银行管理系统

/**
 * @ClassName ATM
 * @Description 银行管理系统
 * @Author LiMingXu
 * @Date 2019/4/3 19:49
 * @Version 1.0
 **/
public class ATM {
    private Bank bankGS;
    private Bank bankNH;

    public ATM(){
        bankGS = new Bank();
        bankNH = new Bank();
    }

    private BankCard searchCard(Bank bank,int id,int passwd){
        BankCard[] arr = bank.getCards();
        for(int i=0;i>1));
        }
    }
    public void add(BankCard card){
        ensureCapacity(size);
        cards[size] = card;
        size++;
    }
    public int getSize(){
        return size;
    }
public class BankCard {
    private int id;
    private int passwd;
    private int money;
    public BankCard(int id,int passwd){
        this.id =id;
        this.passwd = passwd;
        this.money = 0;
    }

    public int getId() {
        return id;
    }
    public int getPasswd() {
        return passwd;
    }
    public void saveMoney(int money){
        this.money+=money;
    }
    public void withdraw(int money){
        if(this.money >= money) {
            this.money -= money;
        }else{
            System.out.println("取钱失败");
        }
    }
    public int getMoney() {
        return money;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        ATM atm = new ATM();
        atm.operator();
    }
}


你可能感兴趣的:(java基础)