
Hi. I wish to thank you for answering my last question, but I had figured it out, but the GUI was very helpful. I could use someones help again with abstracts & a demo account. I know you will be thinking how could I write the code but not get the simplest part.I'm getting a little lost with child classes, but here goes and don't know what to call. First, the code works, I just can't finish the demo application.For class, I had to create a class named Account for a bank. Included an integer field for the account number and a double field for the account balance.Also included a constructor that requires an account number and sets the balance to 0.0. I included a set method for the balance. Also included two abstract get methods-one for each field. I created two child classes of Account: Checking and Savings. Within the Checking class, the get method displays the string"Checking Account Information", the account number and the balance. Within the Savings class, added a field to hold the interest rate, and require the Savings get method to display the string "Savings Account Information", the account number, the balance, and the interest rate. I have to write an application that displays both Checkin and Savings objects. Save as Account.java, Checking.java, Savings.java. In addition, I had to write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a loop to display data, save as AccountArray.java. My code is as follows:
public Account(int an)
{
accountNumber = an;
accountBalance = 0.0;
}
public void setBalance(double bal)
{
accountBalance = bal;
}
public abstract int getNumber();
public abstract double getBalance();
public abstract void getInfo();
}
public class Checking extends Account
{
public Checking(int a)
{
super(a);
}
public void getInfo()
{
System.out.println("Checking Account Information " +
getNumber() + " $" + getBalance());
}
public int getNumber()
{
return accountNumber;
}
public double getBalance()
{
return accountBalance;
}
}
public class Savings extends Account
{
double rate;
public Savings(int a, double r){
super(a);
rate = r;
}
public void getInfo()
{
System.out.println("Savings Account Information " +
getNumber() + " $" +getBalance() + " rate " + rate);
}
public int getNumber()
{
return accountNumber;
}
public double getBalance()
{
return accountBalance;
}
}
This is the DemoAccounts application I am having problems with. I can only get the Savings to print:
public class DemoAccounts
{
public static void main(String[] args)
{
Savings mySvAcct = new Savings(2345, 0.03);
mySvAcct.getInfo();
}
}
This is the AccountArray:
public class AccountArray
{
public static void main(String[] args)
{
Account someAccts[] = new Account[10];
int i;
someAccts[0] = new Checking(101);
someAccts[1] = new Savings(201, 2.1);
someAccts[2] = new Checking(102);
someAccts[3] = new Savings(202, 2.2);
someAccts[4] = new Checking(103);
someAccts[5] = new Savings(203, 2.3);
someAccts[6] = new Checking(104);
someAccts[7] = new Savings(204, 2.4);
someAccts[8] = new Checking(105);
someAccts[9] = new Savings(205, 2.5);
for(i = 0; i <10; ++i)
someAccts[i].getInfo();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.