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
divinity divinity

2021/5/29

#
hi danpost and others i am building another program, this time it is a banking program. In this program I need to build an acct class, transaction class, customer class, saving and checking acct class which i have already done. In the acct class which is supposed to abstract,(and it is) it supposed to have an arraylist transaction lis, i did it but i am getting an error where it is telling u to build a transaction class which i have already did. can u tell me how to fix this error. here is the codes that i used. it supposed to also have a toString method but I havent do that as yet, right now i am just trying to get this error fix any help will do
ublic abstract class  Account{
    private String acctnum;
     double bal;
     ArrayList <transactions> trans = new ArrayList <transactions>(); the error is right here. it telling me to build a transaction class which i have already build.  I dont know if it is not recongizing the transaction class that i have
 
   
  
    public String getacctnum(){
        return acctnum;
    }
    
    public double getbal(){
        return bal;
        
    }
    public void setacctnum(String acctnum){
        this.acctnum= acctnum;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
Gbasire Gbasire

2021/5/29

#
is your class named "Transactions" with a capital T or "transactions" ? that could be the problem
danpost danpost

2021/5/29

#
Or is it "transaction" or "Transaction" without the "s" at the end?
divinity divinity

2021/5/29

#
hi danpost and gbasire I had spell like this transactions with a common t and with and s at the end but I changed it to a capital T like this Transaction and take off the s at the end and i am still getting the error
Gbasire Gbasire

2021/5/29

#
if you put your mouse over the red error line, what does it say ?
danpost danpost

2021/5/29

#
Please show your transaction class.
divinity divinity

2021/5/29

#
this is the transaction class
import java.util.Date;

/**
 *
 * @author Luana
 */
public class Transaction_Account {
    
    private java.util.Date date;
    private double bal;
    private String description;
    char type;
    private double amt;
    private double newbal;
    
    
    public Transaction_Account(char type, double bal, String description, double amt, double newbal){
        
        Date date = new java.util.Date();
        this.bal=bal;
        this.description=description;
        this.type = type;
        this.amt = amt;
        this.newbal = newbal;
    }   
    public java.util.Date getDate(){     
        return date;
    }
    public char gettype(){
        return type;
        
    } 
    public double getbal(){
        return bal;
    }
    public String getdescription(){
        return description;
    }
    public double getamt(){
        return amt;
    }
    public double getnewbal(){
        return newbal;
    }
    public void setDate(Date date){
        this.date=date;
    }
    public void settype(char type){
        this.type=type;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    public void setdescription(String description){
        this.description=description;
    }
    public void setamt(double amt){
        this.amt = amt;
    }
    public void setnewbal(double newbal){
        this.newbal = newbal;
    }
        
divinity divinity

2021/5/29

#
and this is the account abstract class havent finish building it still have a lot of things in it just want to get the error fix first
public abstract class  Account{
    private String acctnum;
     double bal;
     ArrayList <Transaction> trans = new ArrayList <Transaction>();
 
   
  
    public String getacctnum(){
        return acctnum;
    }
    
    public double getbal(){
        return bal;
        
    }
    public void setacctnum(String acctnum){
        this.acctnum= acctnum;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    
}
Gbasire Gbasire

2021/5/29

#
your class is named Transaction_Account but your arraylist is a "Transaction" ArrayList your ArrayList should be created like this : ArrayList <Transaction_Account > trans = new ArrayList <Transaction_Account >();
divinity divinity

2021/5/29

#
thank u gbasire, it work much appreciated so much
divinity divinity

2021/5/30

#
hey danpost, gbasire, i have another problem(error) iI have created a constructor in the abstract account class which was part of the specification and now am getting an error telling to constructed a constructor in the transaction class which i have already have how do i get it to read and fix the error. here is the code
public abstract class  Account{
    private String acctnum;
     double bal;
     private String first_name;
     private String last_name;
     private String home_add;
     private String email_add;
     
     ArrayList <Transaction_Account> trans = new ArrayList <>();
 
    public Account(String first_name, String last_name, String home_add, String email_add, double bal, String acctnum){
        
        this.first_name = first_name;
        this.last_name = last_name;
        this.acctnum= acctnum;
        this.bal= bal;
        this.home_add=home_add;
        this.email_add=email_add;
                
    }
  //setters and getter methods
   //getters methods
    public String getfirst_name(){
        return first_name;
    }
    public String getlast_name(){
        return last_name;
    }
    public String gethome_add(){
        return home_add;
    }
    public String getemail_add(){
        return email_add;
    }
    public String getacctnum(){
        return acctnum;
    }
    
    public double getbal(){
        return bal;
        
    }
    public void setfirst_name(String first_name){
        this.first_name = first_name;
    }
    //setters method 
    
    public void setlast_name(String last_name){
        this.last_name = last_name;
    }
    public void sethome_add(String home_add){
        this.home_add = home_add;
    }
    public void setemail_add(String email_add){
        this.email_add = email_add;
    }
    public void setacctnum(String acctnum){
        this.acctnum= acctnum;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    //end of getters and setters methods
    
    //toString method
    @Override
    public String toString(){
        return "Customers details" + this.first_name+" "+this.last_name+" "+this.acctnum+" "+
                this.home_add+" "+" "+this.email_add +" "+this.bal;
    }
    
    //withdraw methods
    
    public void withdraw(double total_amt){
        if(total_amt < bal){
            System.out.print("Your transaction has been 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(), "W", this.bal, "A withdrawal has been made"); this is where the error is it is telling me required a date, char double double which i have already have 
    }
}
the code above is the account class and the code below is the transaction codes
public class Transaction_Account {
    
    private Date date;
    private double bal;
    private String description;
    char type;
    private double amt;
    private double newbal;
    
    
    public Transaction_Account(Date date, char type, double bal, String description, double amt, double newbal){
        
        this.date = new Date();
        this.bal=bal;
        this.description=description;
        this.type = type;
        this.amt = amt;
        this.newbal = newbal;
    }   
    public java.util.Date getDate(){     
        return date;
    }
    public char gettype(){
        return type;
        
    } 
    public double getbal(){
        return bal;
    }
    public String getdescription(){
        return description;
    }
    public double getamt(){
        return amt;
    }
    public double getnewbal(){
        return newbal;
    }
    public void setDate(Date date){
        this.date=date;
    }
    public void settype(char type){
        this.type=type;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    public void setdescription(String description){
        this.description=description;
    }
    public void setamt(double amt){
        this.amt = amt;
    }
    public void setnewbal(double newbal){
        this.newbal = newbal;
    }
danpost danpost

2021/5/30

#
divinity wrote...
it is telling me required a date, char double double which i have already have
It should be saying -- required: Date, char, double, String, double, double. However, you have the following on that line: Date, String, double, String, double, double
divinity divinity

2021/5/30

#
ok danpost i have change it to what it is asking for and i am still getting the same errors here is the transaction class with the changees
import java.util.Date;

/**
 *
 * @author Luana
 */
public class Transaction_Account {
    
    private Date date;
    private double bal;
    private String description;
    char type;
    private double amt;
    double newbal;
   
    
    
    public Transaction_Account(Date date, char type, double bal,  double amt, double newbal, String description){
        
        this.date = new Date();
        this.bal=bal;
        this.description=description;
        this.type = type;
        this.amt = amt;
        this.newbal= newbal;
        
    }   

  
    public java.util.Date getDate(){     
        return date;
    }
    public char gettype(){
        return type;
        
    } 
    public double getbal(){
        return bal;
    }
    public String getdescription(){
        return description;
    }
    public double getamt(){
        return amt;
    }
    public double getnewbal(){
        return newbal;
    }
    
    public void setDate(Date date){
        this.date=date;
    }
    public void settype(char type){
        this.type=type;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    public void setdescription(String description){
        this.description=description;
    }
    public void setamt(double amt){
        this.amt = amt;
    }
    public void getnewbal(double newbal){
        this.newbal = newbal;
    }
   
        
            
}
and here again is the acct class
public abstract class  Account{
    private String acctnum;
     double bal;
     private String first_name;
     private String last_name;
     private String home_add;
     private String email_add;
     
     ArrayList <Transaction_Account> trans = new ArrayList <>();
 
    public Account(String first_name, String last_name, String home_add, String email_add, double bal, String acctnum){
        
        this.first_name = first_name;
        this.last_name = last_name;
        this.acctnum= acctnum;
        this.bal= bal;
        this.home_add=home_add;
        this.email_add=email_add;
                
    }
  //setters and getter methods
   //getters methods
    public String getfirst_name(){
        return first_name;
    }
    public String getlast_name(){
        return last_name;
    }
    public String gethome_add(){
        return home_add;
    }
    public String getemail_add(){
        return email_add;
    }
    public String getacctnum(){
        return acctnum;
    }
    
    public double getbal(){
        return bal;
        
    }
    public void setfirst_name(String first_name){
        this.first_name = first_name;
    }
    //setters method 
    
    public void setlast_name(String last_name){
        this.last_name = last_name;
    }
    public void sethome_add(String home_add){
        this.home_add = home_add;
    }
    public void setemail_add(String email_add){
        this.email_add = email_add;
    }
    public void setacctnum(String acctnum){
        this.acctnum= acctnum;
    }
    public void setbal(double bal){
        this.bal=bal;
    }
    //end of getters and setters methods
    
    //toString method
    @Override
    public String toString(){
        return "Customers details" + this.first_name+" "+this.last_name+" "+this.acctnum+" "+
                this.home_add+" "+" "+this.email_add +" "+this.bal;
    }
    
    //withdraw methods
    
    public void withdraw(double total_amt){
        if(total_amt < bal){
            System.out.print("Your transaction has been 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(), "W", this.bal, "Withdrawal made");
    }
}
danpost danpost

2021/5/30

#
Now, from line 18 in Transaction_Account class, it requires: Date, char, double, double, double, String But, you have the following order on line 82 of Account class: Date, String, double, String They need to match exactly, in number and order of parameters.
divinity divinity

2021/5/30

#
I match exactly how it is required now and am still getting the error
There are more replies on the next page.
1
2
3
4