I am missing something in my check sub class and I can't figure it out I know its something simple and I for the life of me can not find it.

package lab61;

public class AccountClass {
    public double annualInterestRate;
    public double balance;
    public int Id;
    public java.util.Date dateCreated= new java.util.Date();

        public AccountClass(){

        }
        public AccountClass(int myId,double mybalance, double annualIntRate){
            Id = myId;
            balance = mybalance;
            annualInterestRate = annualIntRate;     
            dateCreated = getDateCreated();
                    }

        public double getAnnualInterestRate() {
            return annualInterestRate;
        }
        public void setAnnualInterestRate(double annualInterestRate) {
            this.annualInterestRate = annualInterestRate;
        }
        public double getBalance() {
            return balance;
        }
        public void setBalance(double balance) {
            this.balance = balance;
        }
        public int getId() {
            return Id;
        }
        public void setId(int id) {
            Id = id;
        }
        public java.util.Date getDateCreated() {
            return dateCreated;
        }
        public void setDateCreated(java.util.Date dateCreated) {
            this.dateCreated = dateCreated;
        }
        public void withdraw(double amount){ 
            balance = balance-amount;

        }
        public void deposit(double amount){
            setBalance(balance + amount);

        }
        public double getMonthlyInterest(){
            double monthlyIntRate = (getAnnualInterestRate() /12);

            return (balance * monthlyIntRate/100);
        }
}


CHECK ACCOUNT

package lab61;

import java.util.Date;

public class Checking extends AccountClass {

    public String accountType;
    public String getAlert;

    public Checking(double balance) {
        // TODO Auto-generated constructor stub

    }


    public Checking(double annualInterestRate, double balance, int id,
            Date dateCreated, String accountType, String getAlert) {
        super();

    }


    public Checking(int myId, double mybalance, double annualIntRate,String accountType, String getAlert) {
        super(myId, mybalance, annualIntRate);
        // TODO Auto-generated constructor stub



    }



    public void deposit(double amount){
        super.deposit(amount);
    }
    public void withdraw(double amount){
        super.withdraw(amount);
    }
    public String getChecking() {
        return accountType;
    }
    public void setAccountType(String accountType) {
        this.accountType = accountType;
    }
    public String getGetAlert() {
        return getAlert;
    }
    public void setGetAlert(String getAlert) {
        this.getAlert = getAlert;
    }




}

CHECKING OUTPUT


package lab61;

public class CheckingDemo {

    public CheckingDemo() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         Checking check = new Checking(1122, 20000, 4.5); 

            check.withdraw(10000); 
            check.deposit(3000); 
            System.out.println("Account type is " + check.accountType()); 
            System.out.println("Balance is " + check.getBalance()); 
            System.out.println("Monthly interest is " + check.getMonthlyInterest()); 
            System.out.println(check.setGetAlert(10000)); 
            System.out.println("This account was created at " + check.getDateCreated()); 
          } 

    }

Recommended Answers

All 3 Replies

"I am missing something" ...
Firstly, we have no idea what it is you are trying to write. You also forget to mention whether or not your code compiles/runs/..., so, whether it is a problem related to bad coding, or to a flawed logic.

Be specific: we don't know your goal, so we don't know what code to write.
Does it throw an exception, during compilation or running, tell us which exception/error (with stacktrace) and when it is thrown.
Do you get an unexpected result, tell us what result you hope to get, and what result you actually get.

^ like stultuske says.

But anyway - looks like problems with the constructors.
When you create a subclass like that you typically need a constructor that has all the values needed for the superclass, plus the xtra ones needed for the subclass.
Eg (pseudo-code)

class A { 
   variables a.b.c
   constructor with parameters for (a, b,c), copies them to variables
}
class B extends A {
   variable d
   constructor with parameters for (a, b,c, d)
      super (a, b, c); // pass a b c to superclass constructor
      this.d = d;

Thats it thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.