程序编译时的错误

时间:2018-09-23 06:14:32

标签: java java.util.scanner

我正在进行一项工作。总结何时需要完成(只是为了澄清我不要求任何人做我的助手,我只是遇到了一个我无法弄清的问题)导致错误的方法就是存款,这就是它的作用(存款方法金额)。

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

public class TestBank {

    public static void main(String[] args) {
        Bank bank = new Bank();

        bank.enterCustomers();

        System.out.println();
        System.out.println("==========================");
        System.out.println("Opening account balance");

        bank.printBalances();

        System.out.println();

        bank.banking();

        System.out.println();
        System.out.println("==========================");
        System.out.println("Closing account balance");
        bank.printBalances();
    }
}

class Bank {

    String accounts;

    Scanner scanner = new Scanner(System.in);

    Account account = new Account();

    public void enterCustomers() {

        ArrayList CustomerDetails = new ArrayList();

        while (true) {

            System.out.print("Enter Name: ");
            account.name = scanner.next();

            if (account.name.equals("q")) {

                break;

            } else {
                Input.promptText("Enter balance: ");
                account.balance = scanner.nextDouble();

                CustomerDetails.add(account.name);
                CustomerDetails.add(account.balance);

                System.out.println("Enter customer names or q to quit entering names");
            }
        }

        scanner.close();

    }

    public void printBalances() {

        System.out.println(account.name + " " + Math.round(account.balance * 100 / 100));

    }

    public void banking() {

        Account account = new Account();
        account.deposit();
        account.withdraw();

        int Newbalance = (int)(Math.round(account.balance));

        switch (Newbalance) {
            case 1:
                account.deposit();
                break;
            case 2:
                account.withdraw();
                break;
            case 0:
                System.exit(0);
            default:
                break;
        }

    }

    class Account {

        private String name;
        private double balance;

        public Account() {

            this.name = name;
            this.balance = balance;

        }

        public String getName() {

            return this.name;

        }

        public double getBalance() {

            return this.balance;

        }

        public double deposit() {


             Input.promptText("Enter a valid deposit: ");
             double amount = scanner.nextDouble();

            balance = balance + amount;

            Input.promptText("your balance after your deposit is: " + balance);
            return balance;

        }

        public double withdraw() {


              Input.promptText("Enter a valid withdraw: ");
           double amount = scanner.nextDouble();

            if (amount > balance); else {
            balance = balance - amount;
            }

            System.out.println("your balance after your withdrawal is: " + balance);
            return balance;
        }

    }

}

class Input {

    private static Scanner scanner = new Scanner(System.in);

    public static String getText() {
        return scanner.nextLine();
    }

    public static String getText(String prompt) {
        System.out.print(prompt);
        return scanner.nextLine();
    }

    public static String getString() {
        return scanner.nextLine();
    }

    public static String getString(String prompt) {
        System.out.print(prompt);
        return scanner.nextLine();
    }

    public static double getDouble() {
        return scanner.nextDouble();
    }

    public static double getDouble(String prompt) {
        System.out.print(prompt);
        return scanner.nextDouble();
    }

    public static void promptText(String text) {
        System.out.printf("%s", text);

    }

    public static void outputText(String text) {
        System.out.printf("%s\n", text);
    }

    public static void outputInteger(String text, int value) {
        System.out.printf("%s%d\n", text, value);
    }

    public static void outputDouble(String text, double value) {
        outputDouble(text, value, 2);
    }

    public static void outputDouble(String text, double value, int decimalPlaces) {
        System.out.printf("%s%." + decimalPlaces + "f\n", text, value);
    }

    public static void outputBoolean(String text, boolean value) {
        System.out.printf("%s%b\n", text, value);
    }
}

当我尝试运行程序时,错误发生在第130行,即 “两倍数量= Scanner.nextDouble();”银行方法中的第82行是“ account.deposit();”;  我相信这是因为帐户方法没有参数程序,但我不确定,非常感谢朝正确方向的推动

1 个答案:

答案 0 :(得分:0)

提示:请检查关闭扫描仪的位置

scanner.close();