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

2021/5/30

#
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;
    }
    @Override
   public String toString(){
       return "\n"+new Date()+" "+ "Type "+ type + " "+ "Account Balance"+ bal +" "+"Description"+description;
   }
        
            
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");
    }
}
divinity divinity

2021/5/30

#
i put it just the way the error say and still getting the error what am i doing wrong here
Gbasire Gbasire

2021/5/30

#
the constructor wants : a Date, and you give a Date, so it's correct a char and you give a String, so it's incorrect (change "W" with 'W' with single quote) a double and you give a double, so it's correct another double and you give nothing, so it's incorrect another double and you give nothing, so it's incorrect a String and you give a String, so it's correct just give 2 more double after the "bal" double and change "W" to 'W'
divinity divinity

2021/5/30

#
ok gbasire here is the correct version at least i would like to think it is
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 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;
    }
    @Override
   public String toString(){
       return "\n"+new Date()+" "+ "Type "+ type + " "+ "Account Balance"+ bal +" "+"Description"+description;
   }
        
            
it did say date, char, double double double string, and when i change "W" to 'W' am getting an unclosed character lateral
*/
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

#
Single quotes are for char type literals, not String literals -- Withdrawal made is of String type and requires double quotes. You are still missing two double type parameters after this.bal, for double amt and double newbal.
divinity divinity

2021/5/30

#
hi danpost it required three (3) double) and a string and that is what I have in the transacation class, date date(), char, double, double, double, string which is as u can see, Date date(), char type, double bal, double amt, double newbal and String description, as u can see in the transaction below, am posting the transaction class again
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 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;
    }
    @Override
   public String toString(){
       return "\n"+new Date()+" "+ "Type "+ type + " "+ "Account Balance"+ bal +" "+"Description"+description;
   }
what is it that you are seeing that I am not clearly seeing.
divinity divinity

2021/5/30

#
are u talking about the transaction class or the account class.
danpost danpost

2021/5/30

#
divinity wrote...
are u talking about the transaction class or the account class.
danpost wrote...
after this.bal,
Line 83, Account class.
divinity divinity

2021/5/30

#
tell me what i am missing here danpost, still getting more errors, it is now say , like ah missing a laterial tell me what ah missing here,
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 getters 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 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,double amt, double newbal, String description, "Withdrawal made");
    }
}
Gbasire Gbasire

2021/5/30

#
I don't think you understand how a constructor truely works here is an example of a constructor :
public Cat(int age, double weight, String name)
{
    this.age = age;
    this.weight = weight;
    this.name = name;
}
and here is how you can call it, for example in class named Animal :
Cat cat = new Cat(9, 7.6, "Robert");
you CAN'T call it like this :
Cat cat = new Cat(int age, double weight, String name);
because you won't send any values. you MUST send some values. if you already have some variables in Animal, for example :
int a = 9; 
double b = 7.6; 
String c = "Robert";
You can call it like this :
Cat cat = new Cat(a, b, c);
because you will in fact send some values (9, 7.6 and "Robert") so in your case, you can do it like this FOR EXAMPLE :
Transaction_Account trans = new Transaction_Account(new Date(), 'W', bal,  0, 0, "Withdrawal made");
for the 0 of amt and the 0 of newbal, just put whatever double value you want
divinity divinity

2021/5/30

#
hi gbasire I tried using what u said above and this is the error am getting ')' expected
Gbasire Gbasire

2021/5/30

#
that's weird, I don't know why this could happen. Please share your code
divinity divinity

2021/5/30

#
 Transaction_Account newtrans = new Transaction_Account(new Date(),'W', bal,?, 0, "Withdrawal made");
Gbasire Gbasire

2021/5/30

#
Well I see nothing wrong there
divinity divinity

2021/5/30

#
yeah but it still giving me grief am still getting the errors
There are more replies on the next page.
1
2
3
4
5