This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/11/29

cannot find symbol, help

1
2
divinity divinity

2016/11/29

#
hi this program here is my second assignment, it is an upgrade to the first one that I had posted before but with a few more classes added; I am supposed to used the same set of coding with this one as in the first one but few more coding added to it and it is supposed to run the same way as the first one. the problem I am having is the cannot find symbol, I have tried looking in the respective classes to see where the error is originated from but cannot for the life of me, seem to find it. as i said, this is my second assignment, it is an upgrade to the first one with just a few more classes added. here is the codes and class the atm is the main class this is where the program will run from. can someone tell me how to fix it
public class ATM {
    DecimalFormat df = new DecimalFormat("#.00");
        public static void main(String[] args) {
            createAccount();
    }
        public static void createAccount()
        {
            Scanner input = new Scanner(System.in);
            int i=0; 
            double bal=50.0;
            //this account hold 10 account
            Account[] acct = new Account[10];
            //creating a new person
            Person[] p = new Person[i++];
            
            for(i=0; i<acct.length; i++){
                System.out.println("Enter your name");
                String n = input.next();
                System.out.println("Enter your address");
                String a = input.next(); 
                System.out.println("Enter your contact");
                String c = input.next();            
                System.out.println("Enter the client number");
                int cn = input.nextInt(); 
                                
                
                //creating a new client each time the program runs
                Clients client = new Clients(n, a, c, cn);
                
            }
                //asking the user to enter the type of account they want to utilize
                System.out.println("Welcome to the Account Type:\n  ");
                System.out.println("Please select from the following menu option:\n");
                System.out.println("=======================================");
                System.out.println("|   Please select your account type  | ");
                System.out.println("=======================================");
                System.out.println("| [\n1] Savings Account              |");
                System.out.println("| [\n2] Checking Account             |");
                System.out.println("| [\n3] CreditCard Account           |");
                System.out.println("======================================");      
                int accType = input.nextInt();
               
                if(accType == 1)
                {
                    acct[i] = new SavingsAccount(i, bal, client);this is where I am getting the cannot find symbol error(client- is the error)
                }
                else if(accType == 2)
                {
                    acct[i] = new CheckingAccount(i, bal, client);his is where I am getting the cannot find symbol error(client- is the error)
                                                                                                                                                 
                }
                else if(accType == 3)
                {
                    acct[i] = new CreditCardAccount(i, bal, client);his is where I am getting the cannot find symbol error(client- is the error)
                }
            while(true)
            {
                System.out.println("Enter your account id");
                int id = input.nextInt();
                
                   if(id == -1)
                   {
                       break;
                   }
                   //this loop indicate that the id should be between 1 - 9
                while(id < 0 || id > 9)
                {
                    System.out.println("ID is incorect, try again");
                    id = input.nextInt();
                }
                //this while indicate whether the user enter the wrong id, given another chance to re-enter
                while(true)
                {
                    displayMenu();
                    
                    if(!useMenu(acct[id],input))
                    {
                        System.out.println();
                        break;
                    }
                    
                    System.out.println("\n");
                }
            }
        }
        public static boolean useMenu(Account acc, Scanner input)
        {
            int userchoice = input.nextInt();
            
            //everytime it runs it shall be false until it is true
            double amt=0;
            if(userchoice == 5)
            {
                return false;
            }
            else if(userchoice == 1)//
            {
                //user checking their balances
                System.out.println("The account balance is: "+ acc.getbalance());
                return true;
            }
            else if(userchoice == 2)
            {
                //indicating the amount to be withdrawn
                System.out.println("Enter the amount to withdraw");
                amt =input.nextDouble();//hold the amt to be withdrawn
                if(amt > acc.getbalance())//indicating if the amt withdrwn is over the limit
                {
                    //indicating that there is not enough funds in the account
                    System.out.println("Insufficient amount " + "Balance is "+acc.getbalance());
                }
                else
                {
                    //otherwise there is enought to be withdrawn
                    acc.withdraw(amt);
                    System.out.println("Balance is: "+ acc.getbalance());
                }
            }
            else if(userchoice == 3)
            {
                //user is asked to enter the amount to be deposited
                System.out.println("Enter the amount to deposit");
                acc.deposit(input.nextDouble());//hold the amt deposited
                System.out.println("Balance is "+ acc.getbalance());//gathering the balance after the  transactions
                return true;
            }
            else if(userchoice == 4)
            {
                //gathering the user information 
                System.out.println(acc.getClient().toString());
            }
            else
            {
                //this indicated that the user enter a choice that is not there.
                System.out.println("invalid choice");
            }
            return true;
        }
        
        public static void displayMenu()
        {
            //displaying the menu where the user has to choose from
            System.out.println("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("=======================================");
            System.out.println("|         Main Menu                   |");
            System.out.println("=======================================");
            System.out.println("| [1] Check Balance                   |");
            System.out.println("| [2] Withdraw                        |");
            System.out.println("| [3] Deposit                         |");
            System.out.println("| [4] Display User Information        |");
            System.out.println("| [5] Exist                           |");
            System.out.println("Please select your choice now!!       |");
            System.out.println("=======================================");
        }
}

this is the account class
public abstract class Account {
    //instantiate the variable
    private int id;
    private double balance;
    private Clients client;
    private double acctTransaction;
    
    
    //constructor with parameter, this initialiing the id, bal and client number
    public Account(int i, double b, Clients c)
    {
        id = i;
        balance = b;
        client = c;
        acctTransaction=0;
    }
    // getting clients
    public Clients getClient()
    {
        return client;
    }
    // getting accid
    public int getid()
    {
        return id;
    }
    // getting balance
    public double getbalance()
    {
        return balance;
    }
    //setting clients
    public void setClients(Clients client)
    {
        this.client = client;
    }
    //setting accid
    public void setid(int id)
    {
        this.id = id;
    }
    // setting balance
    public void setbalance(double balance)
    {
        this.balance = balance;
    }
    public void setacctBalance(double balance){
        this.balance = balance;
    }
    public abstract void withdraw(double amt);
    
    public abstract void deposit(double amt);
    
    @Override // getting user information
    public String toString(){
        String getdetails = "acct ID "+id+"balance "+balance
                +"\nClient "+client.toString();
        
        return getdetails;
    }
    public void reviseTransaction(){
        acctTransaction++;
    }
    public double getacctTransaction(){
        return acctTransaction;
    }
}
this is the checkingAccount class
package Project;

/**
 *
 * @author luanataylor
 */
public class CheckingAccount extends Account {
    //intantiate variable
    
    private final double withdraw;
    

    //constructor with parameter
    public CheckingAccount(int i, double b, Clients c, double w) {
        super(i, b, c);//refering to the variable in the parents class
        withdraw = 0.3167;
    }
    
    
    public void deposit(double amt){
        super.setbalance(super.getbalance() + amt);
    }
    

    @Override
    public void withdraw(double amt) {
        reviseTransaction();// transaction is being updated
        if (amt > super.getbalance()) {//super calling the getbalance
            super.setacctBalance(super.getbalance() - amt);
            if(super.getacctTransaction() > 10)
            applyFee();
        }
    }
    //applying the fee 
    public void applyFee() {
        double Tempbalance = super.getbalance() - 0.3167;
        super.setbalance(Tempbalance);

    }

    @Override
    //gathering the information needed
    public String toString() {
        return super.toString()
                + " -> CheckingAccount:\n\t"
                + "acct balance "
                + super.getbalance()
                + " num of account transaction "
                + super.getbalance();
    }
}




this is the client class
public class Clients extends Person{
    
    //instantiate the variable
    
    private final int clientNumber;
    
    //constructor with parameter
    public Clients(String n, String a, String c, int cn) {
        super(n, a, c);
        clientNumber = cn;
    }

    public int getclientNumber() {
        return clientNumber;
    }
    //getting user detailsride
    @Override
    public String toString() {
       return super.toString()+
               "\nClient Number "+ clientNumber;
    }
this is the creditcard class

public class CreditCardAccount extends Account {
    private final double withdrawTax;
        
        public CreditCardAccount(int i, double b, Clients c, double w) 
        {
            super(i, b, c);
            withdrawTax = 0.1075;
        }
        
        public double getwithdrawTax(){
             return withdrawTax;
         }
        @Override
        public void deposit( double amt){
            super.setbalance(super.getbalance() + amt);
        }
        @Override
        public void withdraw(double amt){
            reviseTransaction();
            if(amt > super.getbalance()){
                super.setacctBalance(super.getbalance() - amt);
                if(super.getacctTransaction() > 10)
                    applyFee();
            }
            
        }
        public void applyFee(){
            double TempBalance = super.getbalance()- 0.1075;
            super.setbalance(TempBalance);
        }
        public String toString(){
            return super.toString()+
                    "\n CreditCardAccount "+
                    "Account Balance "+
                    super.getbalance();
        }
}
this is the person class
package Project;

public abstract class Person {
    //instantiating the variables
    private String name;
    private String address;
    private String contact;
    private Person person;
                        
    //implementing the constructor with arguements
    public Person(String n, String a, String c)
    {
        name = n;
        address = a;
        contact = c;
    }
    public Person getperson(){
        return person;
    }
    //getting name
    public String getname(){
        return name;
    }
    //getting address
    public String getaddress(){
        return address;
    }
    //getting contact
    public String getcontact(){
        return contact;
    }
    public void setPerson(Person person){
        this.person = person;
    }
    //setting the name
    public void setname(String newName){
        this.name = newName;
    }
    //setting address
    public void setaddress(String newaddress){
        this.address = newaddress;
    }
    //setting contact
    public void setcontact(String newContact){
        this.contact = newContact;
    }
    //toString to display the client information
    
    @Override
    public String toString(){
        String details = " name "+name+
                         "\naddress "+address+
                         "\ncontact "+contact+
                         "\nPerson "+person;
        
        return details;
    }
            
            
}
this is the savingsaccount class
package Project;

public class SavingsAccount extends Account {
    //instantiating the variables
    double balance;
    

    //constructor with parameters
    public SavingsAccount(int i, double b, Clients c) {
        super(i, b, c);//this is refering the variables in the parent class
    }
    
    
    @Override
    public void deposit(double amt) {
        super.setbalance(super.getbalance() + amt);
    }

    @Override
    //get the withdra method
    public void withdraw(double amt) {
        reviseTransaction();
        if (amt > super.getbalance()) {// calling the balance method 
            super.setacctBalance(super.getbalance() - amt);//calculating the balance from the amt

        }
    }
    @Override
    //gathering the account information
    public String toString() {
        return super.toString()+
                "-> Saving Account "+
                "account balance "+
                super.getbalance();

    }
}


Super_Hippo Super_Hippo

2016/11/29

#
As far as I know, "cannot find Symbol" is always a compilation error, so it should tell you exactly the line where the error occurs.
divinity divinity

2016/11/29

#
hi super_hippo I have been looking all over the program, been checking in the other class and cant seem to find where the compilation error is and in the creditcard account it incur a 10.75% fee which should be applied to the balance, how do i applied this before the withdraw and in the checking account it incur a 31.67% fee which should be applied to the balance, how do i applied this before the withdraw how do i calculate this in both account and applied it to the balance plz
Super_Hippo Super_Hippo

2016/11/29

#
Well, "normally" when it tells you what error it is, it shows you the part red underlined. I am not sure how the fee should work. So let's say you have 100 $ and want to withdraw 10 $. Without fee, you would have 90 $ left. What exactly should be the result here? Do you want, that an additional 10.75 % of the withdraw will be "lost"? I am a bit confused about line 325 in the previous post. It checks if it tries to withdraw more than the balance? Shouldn't it be the other way around?
        @Override
        public void withdraw(double amt){
            //reviseTransaction();
            if(1.1075*amt < balance){ //if you make balance protected instead of private, you don't have to use a method to get it
                setacctBalance(balance - 1.1075*amt);
                //if(getacctTransaction() > 10)
                    //applyFee();
            }
             
        }
I am not sure what this acctTransaction should do. You increase it by one every time something is withdrawn (or tried to withdraw and failed, because it is before the condition is checked) and only if it is above 10, it should apply the fee? Btw, line 208 and 210. Methods which don't have code in it. I have never done that, so I am not sure if you can do this.
danpost danpost

2016/11/29

#
Super_Hippo wrote...
Btw, line 208 and 210. Methods which don't have code in it. I have never done that, so I am not sure if you can do this.
Those lines declare methods that must be overridden by any subclass of the class. Notice that all three classes that extend the Account class have 'deposit' and 'withdraw' methods. You can read up on this here. @divinity, usually the message will continue with what it could not find 'Cannot find symbol -- ____ _____' (giving the type and name). Does it not give you these?
divinity divinity

2016/11/29

#
in line 208 and 210, it is declared as an abstract method as you can see. hence the reason there is no code in it. if at any time i put any codes in it, it would give me an errors or can i put any codes in it
divinity divinity

2016/11/29

#
@danpost, i have overriden them in the classes but am still getting the cannot find symbol error. something is causing that error and I am exhausted trying to find it. but I will keep trying though even though I am exhaused trying it doesnt mean I have given up
danpost danpost

2016/11/29

#
divinity wrote...
in line 208 and 210, it is declared as an abstract method as you can see. hence the reason there is no code in it. if at any time i put any codes in it, it would give me an errors or can i put any codes in it
I was not suggesting that you add codes to those methods. I was just letting Super_Hippo know why they were coded the way you had them.
am still getting the cannot find symbol error
Again, what cannot it find? It should be saying more than 'cannot find symbol'.
divinity divinity

2016/11/29

#
hi danpost that is what the error is telling me, cannot find symbol, nothing else
Super_Hippo Super_Hippo

2016/11/29

#
Could you make a screenshot please?
divinity divinity

2016/11/29

#
ok
divinity divinity

2016/11/29

#
i took the screenshot but how do i upload it and put it here
danpost danpost

2016/11/29

#
divinity wrote...
i took the screenshot but how do i upload it and put it here
You need to upload it to some image hosting site, like imgur or tinypic. Then get the URL of the image (not the page the image is on) and use the image link below the reply box to insert the image into your post.
divinity divinity

2016/11/29

#
Super_Hippo Super_Hippo

2016/11/29

#
Hm, I am not even seeing an error message.
There are more replies on the next page.
1
2