在使用java的ATM程序中要解决的两个错误

时间:2014-11-06 19:52:53

标签: java error-handling

即时制作ATM软件,这是创建新帐户的管理方法。 我在我的(大多数参数)参数化ctor on line' currball = curr;' 当我这样做时,下一个错误是在createnewAccount方法中: 客户ACC =新客户(持有人N,计数,统计,类型,SBal,日志,Pin); 错误说参数的数量与构造函数的数量不匹配。请你解释一下我的错误。

import java.util.*;
    class Customer
    {

        private String name;
        private int accountno;
        private String status;
        private String type;
        private int currbal;
        private String Login;
        private int Pin;

        public void Customers()
        {

            this.name   = " ";
            this.accountno = accountno;
            this.currbal = currbal; 
        }
        public void Customers( String name1, int A, int Bal)
        {
            name = name1;
            accountno = A;
            currbal = Bal;      
        }
        public void Customers ( String name1,int accountno1, String status1, String type1, int curr, String Login1, int Pin1)
        {   
            name = name1;
            accountno = accountno1;
            status = status1;
            type = type1;
            currball = curr;
            Login = Login1;
            Pin = Pin1;
        }
        public String getHolderName()
        {
            return name;
        }

    }

    class ATMmain
    {
        public static void main()
        {
            int count = 0;
            Customer [] Carray = new Customer [100];
            Customer [] C1 = new Customer[1];
            System.out.println(createNewAccount(count, C1));




        }

        public static int createNewAccount( int count, Customer [] Carray)
        {
            //Customer [] Carray = new Customer[10];
            System.out.println("Enter account information");
            Scanner S = new Scanner (System.in); 
            System.out.println("Login:");
            String log = S.next();
            System.out.println("Pin Code:");
            int Pin = S.nextInt();
            System.out.println("Holder's name: ");
            String holderN = S.next();
            System.out.println("Type:" );
            String type = S.next();
            if (type != "Savings" || type != "Current")
            {
                System.out.println("error type! please Re-enter");
                System.out.println("Type:" );
                type = S.next();
            }
            System.out.println("Starting Balance:");
            int SBal = S.nextInt();
            System.out.println("Status:");
            String Stat = S.next();
            Customer ACC = new Customer(holderN, count,Stat, type,SBal,log, Pin );
            Carray[count] = ACC;

            System.out.println("Account Successfully created!");
            System.out.println("account number is" +count);
            count++;

        }

        public void DeleteExistingAcc(int count, Customer [] Carray )
        {
            System.out.println ("Enter Account Number: ");
            Scanner S = new Scanner(System.in);
            int acc = S.nextInt();

            System.out.println("Are you sure you want to delete this Account:" +acc);
            Carray[acc].getHolderName();

        }
    }

1 个答案:

答案 0 :(得分:0)

是。您的字段为currbal而不是currball

currbal = bal;

您的第二个问题是该课程为Customers而不是Customer

Customers ACC = new Customers(holderN, count,Stat, type,SBal,log, Pin );

我还注意到您正在使用String测试!=平等。这是参考平等。使用!String.equals(String)。此外,您的测试在逻辑上是不可能的。储蓄不是最新的。

if (type != "Savings" || type != "Current")

应该是

if (!type.equals("Savings") && !type.equals("Current"))