通过模拟ATM系统复习oop基础语法及String类和Arraylist类的常见用法

这篇博客通过构建ATM系统来复习Java的面向对象编程基础,包括账户类的设计以及如何确保账号唯一性。作者运用Random生成账号,并结合String和ArrayList的API进行操作。博客强调了在编写涉及if...else、while、switch、for循环等流程控制语句的代码时,保持逻辑清晰和代码简洁的重要性。
摘要由CSDN通过智能技术生成

//一、账户类   就是一个账户类,用来创建账户对象,储存账户信息。

package com.kjx.atmTest;

public class Account {
    private String cnumber;
    private String password;
    private String name;
    private double balance;
    private double quoto;

    public Account() {
    }

    public Account(String cnumber, String password, String name, double balance, double quoto) {
        this.cnumber = cnumber;
        this.password = password;
        this.name = name;
        this.balance = balance;
        this.quoto = quoto;
    }

    public String getCnumber() {
        return this.cnumber;
    }

    public void setCnumber(String cnumber) {
        this.cnumber = cnumber;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getBalance() {
        return this.balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getQuoto() {
        return this.quoto;
    }

    public void setQuoto(double quoto) {
        this.quoto = quoto;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

二、测试类

package com.kjx.atmTest;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class ATMTest {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Random r=new Random();
        ArrayList<Account> accounts=new ArrayList<>();
        //首页
        homePage(sc,r,accounts);

    }
    //0.首页
    public static void homePage(Scanner sc,Random r,ArrayList<Account> accounts){
        while(true){
            System.out.println("==========ATM系统=========");
            System.out.println("1.登录账户");
            System.out.println("2.注册账户");
            System.out.print("请输入1、2选择功能:");
            int choose=sc.nextInt();
            //流程控制
            switch (choose){
                case 1:
                    //登录账户
                    login(r,sc,accounts);
                    break;
                case 2:
                    //注册账户
                    register(sc,r,accounts);
                    break;
                default:
                    System.out.println("请重新选择!");
                    break;
            }
        }
    }

    //1.注册账户
    public static void register(Scanner sc,Random r,ArrayList<Account> accounts){
        //创建账户对象
        Account account=new Account();
        //录入姓名密码
        System.out.print("请输入户主姓名:");
        String name=sc.next(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值