javahopeful321
Programmer
Need someone to point me in the right direction. I'm trying to do simple inheritance with a menu interface. I don't really understand what I'm doing wrong? My code does not compile correctly.
Here is the code
Any help will be greatly appreciated.
Here is the code
Code:
public class Account extends Object
{
// Fields
private String customerName;
private String acctID;
private double balance;
// Three-parameter constructor
public Account(String name, String id, double bal)
{
setFields( name, id, bal );
}
public void setFields( String s, String ss, double b )
{
setCustomerName( s );
setAccountID( ss );
setBalance( b );
}
public void setCustomerName(String s)
{
customerName = s;
}
public void setAccountID(String s)
{
acctID = s;
}
public void setBalance(double bal)
{
balance = bal;
}
public String getCustomerName()
{
return customerName;
}
public String getAccountID()
{
return acctID;
}
public double getBalance()
{
return balance;
}
public void printBalance()
{
System.out.println("\nBalance: " + balance );
}
public String toString()
{
return "\nCustomer: " + customerName + " AcctID: " + acctID + " Balance: " + balance;
}
public void withdraw(double balance)
{
balance=balance-balance;
}
public void deposit(double balance)
{
balance=balance +balance;
}
// Display a menu and read selection from console
private int accountMenu()
{
String s = "\n1 Deposit" +
"\n2 Withdraw" +
"\n3 Balance" +
"\n4 Print toString" +
"\n5 Quit\n\nSelect from menu:";
return Console.readInt( s );
}
// manipulate the account
public void manipulate()
{
int choice = accountMenu();
while( choice != 5 )
{
switch( choice ) {
case 1: deposit(balance);
String prompt=Console.readString("Choose 1 for savings and 2 for checking");
{if(prompt=="1")
SavingsAccount.deposit(balance);
else
CheckAccount.deposit(balance);
}
break;
case 2: withdraw(balance);
String prompt=Console.readString("Choose 1 for savings and 2 for checking");
{if(prompt=="1")
SavingsAccount.withdraw(balance);
else
CheckAccount.withdraw(balance);
}
break;
case 3: printBalance();
break;
case 4: System.out.println( toString() );
break;
case 5: return;
default: System.out.println("Select from menu.");
break;
}
choice = accountMenu();
}
}
} // END OF CLASS
public SavingsAccount extends Account
{
private double intRate;
private int interest;
public SavingsAccount(String a,String b,int c)
{
super(a,b,c);
}
public void deposit(double balance)
{
double intDeposit=Console.readInt("Enter amount to deposit");
balance=balance+intDeposit;
balance=balance+interest;
}
public void addInterest()
{
intRate=Console.readDouble("Enter interest rate:);
double interest = super.getBalance() * intRate/100.0;
super.deposit(interest);
}
}//end of savings
class CheckAccount extends Account
{
private int transCount=0;
private static final int Free_Transactions=5;
private static final double Transaction_Fee=5.0;
public CheckAccount(String a, String b, int c)
{
super(a,b,c);
}
public void deposit(double amt)
{
transCount++;
super.deposit(amt);
}
public void withdraw(double amt)
{
transCount++;
super.withdraw(amt);
deductFees();
}
public void deductFees()
{
if (transCount>Free_Transactions)
{
double fees=Transaction_Fee*(transCount-Free_Transactions);
super.withdraw(fees);
}
transCount=0;
}
}//end of check account
public class TestAccount
{
public static void main( String[] args )
{
Account [] accts = new Account [ 6 ];
accts[0] = new Account( "Smith", "SMI00189", 1000 );
accts[1] = new Account( "Brooks", "BRO00524", 2000 );
accts[2]=new SavingsAccount("Millner","MIL5679", 3000);
accts[3]=new SavingsAccount("Millner","MIL5699", 6000);
accts[4]=new CheckAccount("Webber","WEb9612", 3000);
accts[5]=new CheckAccount("Bibby","Bib1489", 5000);
for( int i = 0; i < accts.length; i++ )
accts[i].manipulate();
}
} // end of class TestAccount
Any help will be greatly appreciated.