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

2021/6/16

How can I get this program to run properly?

1
2
divinity divinity

2021/6/16

#
Hi guys, I need some help here. I am going to put all of my classes so that I can get a feedback on each one and to tell m exactly what I am missing, because it is not running like the way it supposed to do so here goes nothing this is the customer class
public class Customer {
    private String first_name;
    private String last_name;
    private String email_add;
    private String home_add;
    private String telephone;
    
    
    
    public String getfirt_name(){
        return this.first_name;
    }
    
     public String getlast_name(){
         return this.last_name;
     }
     
     public String getemail_add(){
         return this.email_add;
     }
     
     public String gethome_add(){
         return this.home_add;
     }
     
     public String gettelephone(){
         return this.telephone;
     }
     
     public void setfirst_name(String first_name){
         this.first_name=first_name;
     }
     
     public void setlast_name(String last_name){
         this.last_name=last_name;
     }
     
     public void setemail_add(String email_add){
         this.email_add=email_add;
     }
     
     public void settelephone(String telephone){
         this.telephone=telephone;
     }
     
    @Override
     public String toString(){
         return "Customer details"+ " First name of the customer :" + this.first_name+","+ "Last name of the customer:" + this.last_name+","+
                 "Home addres of the customer: "+ this.home_add+","+ "Email address of the customer: "+this.email_add+
                 ","+ "The customer telephone contact: "+ this.telephone;
     }
}

this is the account abstract class
public abstract class  Account{
    
      ArrayList <Transaction_Account> transacct = new ArrayList <>();
      
     String acctnum;
     double bal;
     String first_name;
     String last_name;
     String home_add;
     String email_add;
     String telephone;
     
     public Account(String first_name, String last_name, String acctnum, double bal){
         
         this.first_name = first_name;
         this.last_name = last_name;
         this.acctnum = acctnum;
         this.bal = bal;
                 
     }
      
  //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
    
    
    //start of the withdraw methods
    
    public void withdraw(double total_amt){
        if(total_amt < bal){
            System.out.print("Your transaction declined, insufficient funds: $"+ bal);
        }
        else{
           System.out.println("\n "+ "Your current balance is"+this.bal);           
           Transaction_Account newtrans = new Transaction_Account(new Date(), 'W', this.bal, 0,0, "Withdrawal made");
           
           
        
        }
        //end of the withdraw method
    }
    
    //start of the 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(), 'D', bal,0,0, "Deposit deposited");
        
    }
    //end of the deposit method
    
    
    //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;
    }
}
this is the transaction_account class
public class Transaction_Account{
    
    private Date date;
    private double bal;
    private String description;
    private char type;
    private double total_amt;
    double newbal;
    private char W, D;
   
    
    public Transaction_Account(Date date, char type, double bal, double total_amt,double newbal,  String description){
        
        this.date = new Date();
        this.type = type;
        this.bal=bal;
        this.total_amt = total_amt;
        this.newbal= newbal;
        this.description=description;
        
    }   

    public Date getDate(){     
        return date;
    }
    public char gettype(){
        return type;
    } 
    public double getbal(){
        return bal;
    }
    public String getdescription(){
        return description;
    }
    public double gettotal_amt(){
        return total_amt;
    }
    public double getnewbal(){
       double newbal = bal - total_amt;
        setbal(bal);
        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 settotal_amt(double total_amt){
        this.total_amt = total_amt;
    }
    public void setnewbal(double newbal){
        this.newbal = newbal;
    }
    
    @Override
   public String toString(){
       return "\n"+new Date()+" "+ "Type "+ this.type + " "+ "Account Balance"+ this.bal +" "+"Description"+ this.description;
   }
       
            
}
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 acctnum, double bal, float interestRate){
        super(first_name, last_name, acctnum, bal);
        this.interestRate=interestRate;
       
    }
    
    
     public float getinterestRate(){
        return interestRate;
    }
     public double getbal(){
         return bal;
     }
    public void setinterestRate(float interestRate){
        this.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;
    }
}
this is the chequing_account class
public Chequing_Account(String first_name, String last_name, String acctnum, double bal){
        super(first_name, last_name, acctnum, bal);
        
    }
    
    
    public float getoverdraft(){
        return overdraft;
    }
    public void setoverdraft(float overdraft){
        if(bal < overdraft){
            System.out.println("Sorry but the limit for the overdraft cannot exceeded : $"+ overdraft);
        }
                
    }
    
    public void withdrawal(double total_amt){
        double acctamt=getbal();
        double bal=0;
        if(total_amt > bal && total_amt < 0){
            System.out.println("I'm sorry but you have gone over your limit");
        }
        else{
            bal = acctamt-=total_amt;
            setbal(bal);
            System.out.println(total_amt+"Your current balance is:$"+ bal);
            Transaction_Account newtrans= new Transaction_Account(new Date(), 'W', bal, 0,0, "Withdrawal made");
        }
       
    }
    @Override
    public void deposit(double total_amt){
        double acctamt = getbal();
        double bal = 0;
        bal = acctamt+=total_amt;
        setbal(bal);
        System.out.println("You have deposited: $"+total_amt+ "have been added to your account balance"+ "Your new balance is: $"+total_amt);
        Transaction_Account newtrans = new Transaction_Account(new Date(), 'D', bal,0,0,"Deposit deposited");
        
    }
    
    
    @Override
   public String toString(){
       return this.toString()+ "Over Draft Limit"+ this.overdraft;
   } 
}
and this is the bank account class which is the main, aint finish it as yet but when i gave it a test run,
 */
public class BankAccount {
    
    public static void main(String[]args){
        Scanner keyin = new Scanner(System.in);
        
        
        char type;
        boolean quit;
        boolean isContains;
        String first_name;
        String last_name;
        String acctnum;
        double bal=0;
        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 account you will like to open s-Saving or c-Chequing");
              type = keyin.next().trim().toUpperCase().toLowerCase().charAt(0);
                
                switch (type) {
                    case '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("Please enter a starting balance $"+bal);
                        bal = keyin.nextDouble();
                        System.out.println("Please enter your current interest rate");
                        interestRate = keyin.nextFloat();
                        break;
                    case 'c':
                        System.out.println("Please enter a chequing account number:");
                        acctnum=keyin.next();
                        System.out.println("Enter a starting balance:");
                        bal=keyin.nextDouble();
                        break;
                    case 'd':
                        System.out.println("Please enter the account number you wish to make a deposit to");
                        acctnum = keyin.next();
                        
                        break;
                    default:
                        break;
                        
                     
                }
            }
        }
        
    } 
          
          
yea when ah gave it a test run run this is the result
 Please select one of the following opeitons
| o-To Open Account  |
| d-To Make a deposit
| w-To Make a Withdrawal
| i-To Pay Interest
| t-To View the Transation
| q-To quit
danpost danpost

2021/6/16

#
I noticed you have the Customer fields duplicated in your Account class. It would be better to just retain a Customer instance. Also, in main, the only root option started is 'o' for opening an account. And 'd' is not a sub-option of 'o', but a second root option ('d' option is misplaced).
divinity divinity

2021/6/16

#
this is the instruction for the customer class : 0. Customer. This class stores personal information about the customer, fields include first name, last name, address, email and telephone contact. Methods will include getters and setters for all instance variables and toString() method that displays customer’s details. and this is the instruction for the account class please tell me how i can go about fixing it here is the instruction for the account class Account (abstract). Instances of this class will store customer’s details (Customer), an account number (String), the balance (double value), transactions on the account, stored in an arraylist. Methods will include getters and setters for all instance variables, a toString() method, methods to deposit and withdraw funds
danpost danpost

2021/6/17

#
divinity wrote...
please tell me how i can go about fixing it here is the instruction for the account class Account (abstract). Instances of this class will store customer’s details (Customer),
Remove lines 7 thru 11 in Account class, plus their respective "getter" and "setter" methods Add instead:
private Customer customer;

public Customer getCustomer()
{
    return customer;
}

public void setCustomer(Customer customer)
{
    this.customer = customer;
}
Then adjust the constructor of the class to start:
public Account(Customer)
First line of code in subclass constructors should be:
super(customer);
and those constructors should be like:
public Saving_Account(Customer customer, double bal, float interestRate)
Although, I would have the balance start at zero and treat the initial deposit as a standard transaction.
divinity divinity

2021/6/17

#
how do i construct both he chequing_account and the saving_account. and in the chequing_acct, am getting some errors with the setbal and getbal. it is say that cannot find symbol. in the account class, I had to put back the firstname, lastname, email and home address, because of the toString method. how do i fix that.
danpost danpost

2021/6/17

#
divinity wrote...
how do i construct both he chequing_account and the saving_account
As an example:
Customer customer = new Customer();
customer.setfirst_name(first_name);
customer.setlast_name(last_name);
customer.setemail_add(email_add);
/** customer.sethhome_add(home_add); // sethome_add missing */
customer.settelephone(telephone);
Account account = new Saving_Account(customer);
(I would add a constructor to Customer class to receive its initial information)
in the chequing_acct,. am getting some errors with the setbal and getbal. it is say that cannot find symbol.
Does it extend the Account class?
in the account class, I had to put back the firstname, lastname, email and home address, because of the toString method. how do i fix that.
Use, for example: customer.getfirst_name()
divinity divinity

2021/6/17

#
no the account class does not extend to the customer class only the chequing and saving class it extend to
divinity divinity

2021/6/17

#
the example above that u wrote, where do i put that, do i put it in the saving, chequing, account or customer class and how do i construct the transaction class. any suggestion
danpost danpost

2021/6/17

#
divinity wrote...
no the account class does not extend to the customer class only the chequing and saving class it extend to
I was referring to the Cheequing_Account class. What, exactly is not being found?
danpost danpost

2021/6/17

#
divinity wrote...
the example above that u wrote, where do i put that, do i put it in the saving, chequing, account or customer class and how do i construct the transaction class. any suggestion
It would go in your BankAccount class, main method, in case 'o'.
divinity divinity

2021/6/17

#
if u would go to the Chequing Account, it is the setbal(bal) and getbal(bal)
danpost danpost

2021/6/17

#
divinity wrote...
if u would go to the Chequing Account, it is the setbal(bal) and getbal(bal)
From what I can tell, they ( setbal(bal) and getbal() ) should be found and not cause any errors.
divinity divinity

2021/6/18

#
hi danpost when i add the example in the bank account main class I got an error. the error say to add a constructor in the customer class but apparently it is not recognizing the customer constructor I have that but when I click on the little bulb at the side this is what is get tell me how to fix this without adding another constructor in the customer class also I am having rel errors with all of them, it is telling that firstname, lastname, telephone, email must not be initalized. what do i do
Customer() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
divinity divinity

2021/6/19

#
hi danpost can I get some help on my question above
danpost danpost

2021/6/21

#
divinity wrote...
how to fix this without adding another constructor in the customer class
Actually, I do not see a constructor in the Customer class. However, it should still work without one in the class, inheriting the one in Object class (which Customer implicitly extends).
There are more replies on the next page.
1
2