File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes super Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super Constructor " Watch "super Constructor " New topic
Author

super Constructor

mike hew
Greenhorn

Joined: Oct 26, 2006
Posts: 27
Well I took some good advise and started my program over and did 1 line at a time to fix errors and not end of with a bunch.

But now I got a problem. CheckingAccount has no errors but trying to compile CheckingAccountPlus I get this error revolving around Keyword "SUPER"?

Also included is partial Test class, which I stopped with current errors.

If anyone can help me ? or show me what I need to do? or an Example, I would be very grateful, and thank you in advance.


CheckingAccount class
[code
//public class file name
public class CheckingAccount
{

private String accountId;
private String accountType = "Regular";
private double balance;
private double beginningBalance;
private double deposits;
private double fees;
private String firstName;
private String lastName;
private double overdraftFee = 50.0;
private double overdrafts;
private double withdrawals;

public CheckingAccount(String accountId, String firstName, String lastName, double balance)
{
accountId = this.accountId;
firstName = this.firstName;
lastName = this.lastName;

if (balance >= 0){
balance = this.balance;
}
else
{
this.balance = 0;
}//end if

this.beginningBalance = this.balance;
this.deposits = 0;
this.withdrawals = 0;
this.fees = 0;

}//end method

//A-2-3-01)RETURN accountId
public String getAccountId()
{
return accountId;
}

//A-2-4-01)RETURN accountType
public String getAccountType()
{
return accountType;
}

//A-2-5-01)RETURN balance
public double getBalance()
{
return balance;
}

//A-2-6-01)RETURN beginningBalance
public double getBeginningBalance()
{
return beginningBalance;
}

//A-2-7-01)RETURN deposits
public double getDeposits()
{
return deposits;
}

//A-2-8-01)RETURN fees
public double getFees()
{
return fees;
}

//A-2-9-01)RETURN firstName
public String getFirstName()
{
return firstName;
}

//A-2-10-01)RETURN lastName
public String getLastName()
{
return lastName;
}

//A-2-11-01)RETURN overdraftFee
public double getOverdraftFee()
{
return overdraftFee;
}

//A-2-12-01)RETURN overdrafts
public double getOverdrafts()
{
return overdrafts;
}

//A-2-13-01)RETURN withdrawals
public double getWithdrawals()
{
return withdrawals;
}

public void makeDeposit(double amount)
{
setBalance(getBalance() + amount);
}

public boolean makeWithdrawal(double amount)
{
double balanceAfterWithdrawal = getBalance() - amount;
if (balanceAfterWithdrawal >= 0){
setBalance(getBalance() - amount);
withdrawals += amount;
return true;
}
else
{
setBalance(getBalance() - getOverdraftFee());
overdrafts = overdrafts + amount;
fees += getOverdraftFee();
return false;
}//end if

}//end makeWithdrawal method

//A-2-16-01)ASSIGN amount TO this.balance
public void setBalance(double amount)
{
this.balance = amount;
}

//A-2-17-01)ASSIGN amount TO this.withdrawals
public void setWithdrawals(double amount)
{
this.withdrawals = amount;
}

//A-2-18-01)RETURN the following expression : getLastName() + ", " + getFirstName()
public String toString()
{
return getLastName() + ", " + getFirstName();
}

}//end public class CheckingAccount [/code]

Errors:
-Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe-
-Target File: G:\NEW9~1\CheckingAccount.java-

-Finished-


CheckingAccountPlus class


Errors:
-Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe-
-Target File: G:\NEW9~1\CheckingAccountPlus.java-
G:\NEW9~1\CheckingAccountPlus.java:25: '.' expected
super Constructor CheckingAccount(accountId, firstName, lastName, balance);
^
G:\NEW9~1\CheckingAccountPlus.java:25: <identifier> expected
super Constructor CheckingAccount(accountId, firstName, lastName, balance);
^
2 errors

-Finished-


CheckingAccountsTest class
Partial code



Errors:
-Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe-
-Target File: G:\NEW9~1\CheckingAccountsTest.java-
.\CheckingAccountPlus.java:25: '.' expected
super Constructor CheckingAccount(accountId, firstName, lastName, balance);
^
.\CheckingAccountPlus.java:25: <identifier> expected
super Constructor CheckingAccount(accountId, firstName, lastName, balance);
^
G:\NEW9~1\CheckingAccountsTest.java:53: non-static method getAccountType() cannot be referenced from a static context
if(myFields[indexForAccountType].equals(CheckingAccount.getAccountType())){
^
G:\NEW9~1\CheckingAccountsTest.java:96: cannot find symbol
symbol : variable currentAcccount
location: class CheckingAccountsTest
currentAcccount.getBalance += sumOfBeginningBalances;
^
.\CheckingAccountPlus.java:63: cannot find symbol
symbol : method getBalance()
location: class CheckingAccountPlus
double balanceAfterWithdrawal = (getBalance() - amount);
^
.\CheckingAccountPlus.java:67: cannot find symbol
symbol : method getBalance()
location: class CheckingAccountPlus
setBalance(getBalance() - amount);
^
.\CheckingAccountPlus.java:67: cannot find symbol
symbol : method setBalance(double)
location: class CheckingAccountPlus
setBalance(getBalance() - amount);
^
.\CheckingAccountPlus.java:68: cannot find symbol
symbol : method getWithdrawals()
location: class CheckingAccountPlus
setwithdrawals(getWithdrawals() += amount);
^
.\CheckingAccountPlus.java:73: cannot find symbol
symbol : method setBalance(int)
location: class CheckingAccountPlus
setBalance(0);
^
.\CheckingAccountPlus.java:76: cannot find symbol
symbol : method getWithdrawals()
location: class CheckingAccountPlus
setWithdrawals(getWithdrawals() += actualWithdrawal);
^
10 errors

-Finished-
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212


A few things wrong with this.

1. It is not a method at all, but a constructor.
2. You do not extend any class so the only parent is Object. There is no constructor in object that accepts the arguments String, String, String, souble. The only constructor in Object is a no-args constructor.
3. Assuming you actually have a super class that accepts those types that is not how you call the super class constructor:

super (accountId, firstName, lastName, balance);

For that to work, it looks like you must extend CheckingAccount. Clean this part up and recompile and see what errors are left.

I just have a small comment about some of your code



That is an excessive amount of comments. Commenting nearly every line is unnecessary. It clutters up your code and makes it harder to understand when you drown it in comments.
[ November 15, 2006: Message edited by: David McCombs ]

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super Constructor