测试

import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static BankService bankService = new BankService();

    public static void main(String[] args) {
        printAvailableServices();
        int command = 0;
        while((command = Integer.parseInt(sc.nextLine())) != 0) {
            switch(command) {
                case 1:
                    createAccount();
                    break;
                case 2:
                    checkBalance();
                    break;
                case 3:
                    makeDeposit();
                    break;
                case 4:
                    withdraw();
                    break;
                case 5:
                    getMortgageInfo();
                    break;
                case 0:
                    sc.close();
                    System.exit(0);
                default:
                    System.err.println("invalid input, try again");
                    break;
            }
            System.out.println();
            printAvailableServices();
        }
    }

    public static void printAvailableServices() {
        System.out.println("- Press 1 to create an account");
        System.out.println("- Press 2 to check account balance");
        System.out.println("- Press 3 to make a deposit");
        System.out.println("- Press 4 to withdraw cash");
        System.out.println("- Press 5 to get advices on house mortgage loan");
        System.out.println("- Press 0 to exit");
    }

    public static void createAccount() {
        System.out.println("Please provide the following information:");
        System.out.print("Your first name: ");
        String firstName = sc.nextLine().trim();
        System.out.print("Your last name: ");
        String lastName = sc.nextLine().trim();
        System.out.print("Your gender (type 'm' for Male and 'f' for Female): ");
        char gender = Character.toLowerCase(sc.nextLine().trim().charAt(0));
        System.out.print("Your social security number: ");
        String ssn = sc.nextLine().trim();
        bankService.createAccount(firstName, lastName, gender, ssn);
    }

    public static void checkBalance() {
        System.out.print("Please provide your social security number: ");
        String ssn = sc.nextLine().trim();
        bankService.checkAccountBalance(ssn);
    }

    public static void makeDeposit() {
        System.out.print("Please provide your social security number: ");
        String ssn = sc.nextLine().trim();
        System.out.print("Deposit amount (\u00A5): ");
        double amount = Double.parseDouble(sc.nextLine().trim());
        bankService.makeDeposit(ssn, amount);
    }

    public static void withdraw() {
        System.out.print("Please provide your social security number: ");
        String ssn = sc.nextLine().trim();
        System.out.print("Withdraw amount (\u00A5): ");
        double amount = Double.parseDouble(sc.nextLine().trim());
        bankService.withdraw(ssn, amount);
    }

    public static void getMortgageInfo() {
        System.out.print("Loan amount (\u00A5): ");
        double amount = Double.parseDouble(sc.nextLine().trim());
        System.out.print("Loan term (years): ");
        int years = Integer.parseInt(sc.nextLine().trim());
        BankService.calculateMonthlyPayment(amount, years);
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值