Creating Object Relationships using Java 7
Hi Everyone:
I am new to the forum. This is my first post. I am currently working on a banking app. It has been running fine UNTIL I implemented subclassing.
My relationships are
BANKS have CUSTOMERS.
CUSTOMERS have 1 or more ACCOUNTS.
The code executed as expected until I created 2 subclasses . These subclasses are extended from ACCOUNTS.
public class CheckingAccount extends ACCOUNTS {
-and-
public class SavingsAccount extends ACCOUNTS {
Here's My Question: I'd like some help pushing through the compile errors. I believe the problem is not syntactical, but conceptual. I seem to not fully comprehend some concept at play here. Any seasoned Java programmers want to enlighten me about subclassing?
Thank you so much for looking at my subclassing error(s). I realize that conceptually subclassing is a snap. BUT programming code for subclassing is hard for me to hammer down. I'd love seasoned reasoning that will help this logically click for me. Thank you sooo much!
***COMPILE ERROR***
the TestingChecking.java has 22 errors.
**6 (Identifier) expected.**
line28- customer.setAccount(new CheckingAccount(871.7));
line29- CheckingAccountBalance=CheckingAccount.getBalance();
**5 Illegal start of type.**
line28- (see syntax above)
line33- System.out.println("New Account..." + customer.getAccount());
**5 class, interface, or enum expected**
line37- if
line40- System.out.println("\n\tCreating Checking Account -overdraft waived."); error indicator points to close parenthesis??
***COMPILE ERROR***
===================================================================================
/* code for Account.java Status: Running As Expected */
public class Account {
private double globalBalance;
public boolean status;
public boolean SUCCESS = true;
public boolean FAILURE = false;
public Account(double initialBalance) {
if (initialBalance > 0) {
globalBalance = initialBalance;
System.out.println("New Account Created. Balance is " + globalBalance);
}
}
//method: getBalance
public double getBalance() {
return globalBalance;
}
//method: WITHDRAWL
public boolean Withdrawl(double withdrawlAmount) {
if(globalBalance > withdrawlAmount) {
globalBalance = globalBalance - withdrawlAmount;
status = SUCCESS;
} else status = FAILURE;
// System.out.println("current balance cannot accomodate your request");
return status;
}
//method: DEPOSIT
public boolean Deposit (double depositAmount) {
if(depositAmount >0) {
globalBalance = globalBalance + depositAmount;
status = SUCCESS;
} else status = FAILURE;
// System.out.println("Error in Deposit. Transaction not complete.");
return status;
}
}
========================================================================================
/* source for CheckingAccount.java Status: DOA */
public class CheckingAccount {
public boolean status=false;
public boolean SUCCESS = true;
public boolean FAILURE = false;
private double globalBalance;
protected double overdraftLimit;
public CheckingAccount(double initialBalance) {
if (initialBalance > 0) {
globalBalance = initialBalance;
System.out.println("New Account Created. Balance is " + globalBalance);
status = true;
}
System.out.println("New Checking Account Error: Cannot open CheckingAccount with less than $1.00.
globalBalance= " + globalBalance + " Overdraft Limit= " +overdraftLimit);
}
//method: getBalance
public double getBalance() {
return globalBalance;
}
//method: WITHDRAWL
public boolean Withdrawl(double withdrawlAmount) {
boolean status;
if(globalBalance > withdrawlAmount) {
globalBalance = globalBalance - withdrawlAmount;
status = true;
} else status = false;
// System.out.println("current balance cannot accomodate your request");
return status;
}
//method: DEPOSIT
public boolean Deposit (double depositAmount) {
if(depositAmount >0) {
globalBalance = globalBalance + depositAmount;
status = true;
} else status = false;
System.out.println("Error in Deposit. Transaction not complete.");
====================================================================================
/* source for testCode.java Status: Not Running
public class TestingChecking {
private int Status2;
public static void main(String[] args) {
String firstName = "Kole";
String lastName = "Strepek";
boolean transactionStatus = false;
Bank bank = new Bank();
Customer customerObjectReference; // **initialize "customer" container**
CheckingAccount checkingAccountObjectReference;
double CheckingAccountBalance;
System.out.println("\n\t Creating Kole Strepek Customer Object");
bank.addCustomer("Kole","Strepek");
customerObjectReference = bank.getCustomer(0); //CRITICAL REFERENCE
System.out.println("\n\tCustomer has been established: " + customer.getFirstName() + " " + customer.getLastName() );
}
customer.setAccount(new CheckingAccount(871.7));
CheckingAccountBalance=CheckingAccount.getBalance();
checkingAccountObjectReference=CheckingAccount.getAccount();
System.out.println("\n\t Created Checking with OverDraft Protection FOR KOLE. TARGET HIT" );
System.out.println("New Account has been established: " + customer.getAccount() );
}
if //checking without overdraft
(AccountType == 2) {
System.out.println("\n\n\n\n Need Code to Create Checking without OverDraft Protection ");
System.out.println("\n\tCreating Checking Account -overdraft protection waived.");
}
if //savings with annual interest calculation
(AccountType == 3) {
System.out.println("\n\n\n\n Need Code to Create Savings with Annual Interest Rate");
System.out.println("\n\tCreating Savings Account. Interest is calculated annually. The current rate is 3%.");
}
}
}
}
Thank you so much for looking at my subclassing error(s). I realize that conceptually subclassing is a snap. BUT programming code for subclassing is hard for me to hammer down. I'd love seasoned reasoning that will help this click for me. Thank you much!
~Tree
Last edited by Treeware; 06-07-2012 at 12:09 PM.
Reason: insert code snippets
|