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

2021/5/29

Problem with an transaction arraylist

1
2
3
4
5
Gbasire Gbasire

2021/5/31

#
Are you sure the error is coming from this line of code ?
danpost danpost

2021/5/31

#
The error should go away with:
Transaction_Account newtrans = new Transaction_Account(new Date(),'W', bal, 0, 0, "Withdrawal made");
but I am sure zeros are not the correct values.
Gbasire Gbasire

2021/5/31

#
Ohhh I didn't see it, but of course putting a "?" won't work haha
divinity divinity

2021/5/31

#
hi danpost and gbrasire: the error is saying that I am missing a semi-colon somewhere in between the lines of codes. have no idea where, i have been trying for days on end to find it and where. the error says, class expected, like a semi colon or a comma supposed to be there and where i dont know it is both in the withdraw method and deposit methods
 public void withdraw(double total_amt){
        if(total_amt < bal){
            System.out.print("Your transaction declined because there is no funds available"+ bal);
        }
        else{
           System.out.println("\n "+ "Your current balance is"+this.bal);
          
        }
        
        Transaction_Account newtrans = new Transaction_Account(new Date(), char type, this.bal, double amt, double newbal, 'W' "Withdrawal made");
        
    }
    
    //deposit method
    public void deposit(double total_amt){
        this.bal +=total_amt;
        System.out.print("\n"+total_amt+"Your balance is:"+this.bal);
        
        Transaction_Account newtrans = new Transaction_Account(new Date(), char type, this.bal, double amt, double newbal, 'D', "Deposit deposited");
        
Gbasire Gbasire

2021/5/31

#
I told you that you couldn't put things like "char type" or "double amt" when you're creating an object with a constructor with several parameters. You must put some values when creating an object with a complex constructor. That might fix the problem.
danpost danpost

2021/5/31

#
danpost wrote...
The error should go away with:
Transaction_Account newtrans = new Transaction_Account(new Date(),'W', bal, 0, 0, "Withdrawal made");
but I am sure zeros are not the correct values.
divinity divinity

2021/6/1

#
hi danpost and gbasire, it work thanks guys> i have some other problems but lemme see if i can work through it first before i come back to u
divinity divinity

2021/6/2

#
hi danpost, gbasire I have another one for you guys, I am presently building up the main, i have still have a couple of things to do with the other classes but for now i will leave it alone, my question is like this. hope u guys would understand what i am trying to explain am trying to bring up a function but for some reasons it is not coming up.
System.out.println("Please enter a saving account number");
   acctnum = keyin.next();
  Savings.add(acctnum) this function is what i am trying to bring up but for some reason it is not coming and the savings is causing a  error I am trying to understand what can I do to bring up this function and what it is called
danpost danpost

2021/6/2

#
Show Savings class.
divinity divinity

2021/6/2

#
this is the saving class
public class Saving_Account extends Account{
    
    private float interestRate;
    
    
    public Saving_Account(String first_name, String last_name, String home_add, String email_add, double bal, String telephone, double acctnum, float interestRate){
        super(first_name, last_name, home_add, email_add, acctnum,telephone);
        this.interestRate=interestRate;
       
    }
    
     public float getinterestRate(){
        return interestRate;
    }
     public double getbal(){
         return bal;
     }
    public float setinterestRate(float interestRate){
        return  interestRate = interestRate/100;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    public void payInterest(){
      double total_amt = getbal();
      double bal=0;
      bal=(total_amt + (total_amt *getinterestRate()));
      setbal(bal);
       
      System.out.println("Account balance with interest is: $"+bal);
      Transaction_Account newtrans = new Transaction_Account(new Date(), 'I', bal,0,0,"Interest Paid");
    }
    //withdrawal method
    @Override
    public void withdraw(double total_amt){
        double bal=0;
        double acctamt=0;
        
        if(acctamt < total_amt){
           
         System.out.println("Insufficient funds, balance is :$"+ acctamt);
        }
        else{
            bal=acctamt-=total_amt;
            setbal(bal);
            System.out.println();
            
        }
        
    }
    @Override
      public void deposit(double total_amt){
        double acctamt = getbal();
        bal = acctamt+=total_amt;
        setbal(bal);
        System.out.println("Your deposit amount is: $"+ bal + "was successful, your new balance is: $"+bal);
        Transaction_Account newtrans= new Transaction_Account(new Date(), 'D', bal, 0,0, "deposit made");
        }  
    @Override
    public String toString(){
        
        return this.toString()+ "Interest Rate"+ interestRate;
    }
}
danpost danpost

2021/6/3

#
divinity wrote...
this is the saving class << Code Omitted >>
That is a Saving_Account class.
divinity wrote...
System.out.println("Please enter a saving account number");
   acctnum = keyin.next();
  Savings.add(acctnum) this function is what i am trying to bring up but for some reason it is not coming and the savings is causing a  error I am trying to understand what can I do to bring up this function and what it is called
What does "Savings" on line 3 refer to?
divinity divinity

2021/6/3

#
i was just trying to show u what function that I am trying to invoke.
danpost danpost

2021/6/3

#
divinity wrote...
i was just trying to show u what function that I am trying to invoke.
Well, I did not see any add method defined anywhere What type of object is Savings supposed to represent and what does the add method look like in that class?
divinity divinity

2021/6/3

#
it is not there i was asking how to bring it up. i guess u didnt understand but anyway, i have another problems, i have error in my main. The error is telling me imcpatitable type, String cannot be converted to double, in my main, i dont have it as a string but a double but i am wondering if it is pulling that error from the saving account class, i am sending u the codes for both the main and the saving accts. I would like to take a look and tell if it that I am thinking where it pulling the string from here is my main this is my main
 */
public class BankAccount {
    public static void main(String[]args){
        Scanner keyin = new Scanner(System.in);
        char type, choice;
        boolean quit;
        String first_name;
        String acctnum;
        double bal;
        float interestRate;
        
          
          
        System.out.println("\n "+ "Please select one of the following opeitons");
        System.out.println("| o-To Open Account  |");
        System.out.println("| d-To Make a deposit");
        System.out.println("| w-To Make a Withdrawal");
        System.out.println("| i-To Pay Interest");
        System.out.println("| t - To View the Transation");
        System.out.println("| q - To quit");
        type = keyin.next().trim().toUpperCase().toLowerCase().charAt(0);
        
        while (type !='q'){
           if(type == 'o'){
             System.out.println("please select the type of accoun you will like to open s-Saving or c-Chequin");
              choice = keyin.next().trim().toUpperCase().toLowerCase().charAt(0);
                
             if(choice == 's'){
               System.out.println("Enter the account holder first name");
                first_name = keyin.next();
                
                System.out.println("Please enter a saving account number");
                acctnum = keyin.next();
                
                
                System.out.println("Enter the saving acct number");
                acctnum = keyin.next();
                
                System.out.println("Please enter a starting balance");
                bal = keyin.nextDouble();
                
                
                System.out.println("Please enter your current interest rate");
                interestRate = keyin.next(); ( the error is right here, incompitatible type, string cannot be converted to double
                    
                }
            }
        }
        
    } 
          
          
  }

this is the saving account class
public class Saving_Account extends Account{
    
    private float interestRate;
    
    
    public Saving_Account(String first_name, String last_name, String home_add, String email_add, double bal, String telephone, double acctnum, float interestRate){
        super(first_name, last_name, home_add, email_add, acctnum,telephone);
        this.interestRate=interestRate;
       
    }
    
     public float getinterestRate(){
        return interestRate;
    }
     public double getbal(){
         return bal;
     }
    public float setinterestRate(float interestRate){
        return  interestRate = interestRate/100;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    public void payInterest(){
      double total_amt = getbal();
      double bal=0;
      bal=(total_amt + (total_amt *getinterestRate()));
      setbal(bal);
       
      System.out.println("Account balance with interest is: $"+bal);
      Transaction_Account newtrans = new Transaction_Account(new Date(), 'I', bal,0,0,"Interest Paid");
      
    }
    //withdrawal method
    @Override
    public void withdraw(double total_amt){
        double bal=0;
        double acctamt=0;
        
        if(acctamt < total_amt){
           
         System.out.println("Insufficient funds, balance is :$"+ acctamt);
        }
        else{
            bal=acctamt-=total_amt;
            setbal(bal);
            System.out.println();
            
        }
        
    }
    @Override
      public void deposit(double total_amt){
        double acctamt = getbal();
        bal = acctamt+=total_amt;
        setbal(bal);
        System.out.println("Your deposit amount is: $"+ bal + "was successful, your new balance is: $"+bal);
        Transaction_Account newtrans= new Transaction_Account(new Date(), 'D', bal, 0,0, "deposit made");
        
        
        }  
    @Override
    public String toString(){
        
        return this.toString()+ "Interest Rate"+ interestRate;
    }
}
danpost danpost

2021/6/3

#
The Scanner instance next method returns a String object. Try using the nextFloat method.
There are more replies on the next page.
1
2
3
4
5