| | |
Design a class named BankAccount to hold the following data for a bank account:
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
| View Poll Results: Use Bluej Software.....to do this question... | |||
| Plz help me out....... | | 1 | 33.33% |
| I have to submit this within 2 days | | 3 | 100.00% |
| Multiple Choice Poll. Voters: 3. You may not vote on this poll | |||
![]() |
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
1)Design a class named BankAccount to hold the following data for a bank account:
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method,and then sets the variables that hold
the number of withdrawls,number of deposits,and monthly services to zero.
Next,design a SavingAccount class that extends the BankAccount class.
The SavingsAccount class should have a status field to represent an acctive or inactive account.
If the balance of a savings account falls below $25,it becomes inactive.
(The status field could be a boolean variable.)No more withdrawals may be made until the balance is raised above $25,at which time the account becomes active again.
The savings account class should have the following methods:
withdraw: A method that determines whether the account is inactive before a withdrawal is made.
(No withdrawal will be allowed if the account is not active.)A withdrawal is then made by calling the superclass version of the method.
deposit : A method that deterines whether the account is inactive before a deposit is made.If the account is inactive and the deposit brings the balance abovee $25,the account becomes active agian.
A deposit is then made by calling the superclass version of the method.
monthlyProcess: Before the superclass method is called,this method checks the number of withdrawals.If the number of withdrawals for the month is more than 4,a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges.
(Don't forget to check the account balance after the service charge is taken.If the balance falls below $25,the account becomes inactive.)
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method,and then sets the variables that hold
the number of withdrawls,number of deposits,and monthly services to zero.
Next,design a SavingAccount class that extends the BankAccount class.
The SavingsAccount class should have a status field to represent an acctive or inactive account.
If the balance of a savings account falls below $25,it becomes inactive.
(The status field could be a boolean variable.)No more withdrawals may be made until the balance is raised above $25,at which time the account becomes active again.
The savings account class should have the following methods:
withdraw: A method that determines whether the account is inactive before a withdrawal is made.
(No withdrawal will be allowed if the account is not active.)A withdrawal is then made by calling the superclass version of the method.
deposit : A method that deterines whether the account is inactive before a deposit is made.If the account is inactive and the deposit brings the balance abovee $25,the account becomes active agian.
A deposit is then made by calling the superclass version of the method.
monthlyProcess: Before the superclass method is called,this method checks the number of withdrawals.If the number of withdrawals for the month is more than 4,a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges.
(Don't forget to check the account balance after the service charge is taken.If the balance falls below $25,the account becomes inactive.)
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
Re: Design a class named BankAccount to hold the following data for a bank account:
0
#2 Jul 15th, 2009
This is a cut and paste of the assignment specification. What is the question?
http://www.daniweb.com/forums/announcement9-2.html
http://www.daniweb.com/forums/announcement9-2.html
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
Re: Design a class named BankAccount to hold the following data for a bank account:
0
#3 Jul 15th, 2009
*/
class is BankAccount
*/
public class BankAccount
{
private static int nextAccountNumber = 10000;
private static double currentInterestRate = 0.05;
public static void setCurrentRate(double newRate)
{
currentInterestRate = newRate;
}
private int accountNumber;
private double balance;
private double rate;
public Account(double initialBalance)
{
accountNumber = nextAccountNumber++;
balance = initialBalance;
rate = currentInterestRate;
}
public int getAccountNumber()
{
return accountNumber;
}
public double getBalance()
{
return balance;
}
public double getRate()
{
return rate;
}
public double getCurrentRate()
{
return currentInterestRate;
}
public void deposit(double amount)
{
balance += amount;
}
public boolean withdraw(double amount)
{
if (amount > balance) // refuse to let account be overdrawn
return false;
else
{
balance -= amount;
return true;
}
}
public void updateRate()
{
rate = currentInterestRate;
}
public void elapse(int numberOfDays)
{
for (int day = 1; day <= numberOfDays; ++day)
{
balance += balance*rate/12;
}
}
}
class is BankAccount
*/
public class BankAccount
{
private static int nextAccountNumber = 10000;
private static double currentInterestRate = 0.05;
public static void setCurrentRate(double newRate)
{
currentInterestRate = newRate;
}
private int accountNumber;
private double balance;
private double rate;
public Account(double initialBalance)
{
accountNumber = nextAccountNumber++;
balance = initialBalance;
rate = currentInterestRate;
}
public int getAccountNumber()
{
return accountNumber;
}
public double getBalance()
{
return balance;
}
public double getRate()
{
return rate;
}
public double getCurrentRate()
{
return currentInterestRate;
}
public void deposit(double amount)
{
balance += amount;
}
public boolean withdraw(double amount)
{
if (amount > balance) // refuse to let account be overdrawn
return false;
else
{
balance -= amount;
return true;
}
}
public void updateRate()
{
rate = currentInterestRate;
}
public void elapse(int numberOfDays)
{
for (int day = 1; day <= numberOfDays; ++day)
{
balance += balance*rate/12;
}
}
}
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
Re: Design a class named BankAccount to hold the following data for a bank account:
0
#4 Jul 15th, 2009
Code tags and formatting please. Otherwise it is impossible to read. I formatted your code in NetBeans. Indentation is a must.
[code=JAVA]
// paste code here
[/code]
Here's your code:
Watch your spelling. Is it Account or BankAccount? Is it SavingAccount or SavingsAcount? Everything much match. Constructor name needs to match class name. Constructors should be INSIDE the class. Check your brackets. Also, describe what the problems are and please ask a specific question. NetBeans did its best to format SavingsAccount, but got confused due to brackets problems. Please repost corrected, formatted code in code tags, along with a particular question, including line numbers. Thanks.
[code=JAVA]
// paste code here
[/code]
Here's your code:
JAVA Syntax (Toggle Plain Text)
public class BankAccount { private static int nextAccountNumber = 10000; private static double currentInterestRate = 0.05; public static void setCurrentRate(double newRate) { currentInterestRate = newRate; } private int accountNumber; private double balance; private double rate; public Account(double initialBalance) { accountNumber = nextAccountNumber++; balance = initialBalance; rate = currentInterestRate; } public int getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double getRate() { return rate; } public double getCurrentRate() { return currentInterestRate; } public void deposit(double amount) { balance += amount; } public boolean withdraw(double amount) { if (amount > balance) // refuse to let account be overdrawn { return false; } else { balance -= amount; return true; } } public void updateRate() { rate = currentInterestRate; } public void elapse(int numberOfDays) { for (int day = 1; day <= numberOfDays; ++day) { balance += balance * rate / 12; } } }
JAVA Syntax (Toggle Plain Text)
public class SavingAccount extends BankAccount { public boolean withdraw(double amount) { if (getbalance() >= amount + minAmount) { super.withdraw(amount); return true; } else { return false; } } private double minAmount; } private intnumberOfWithdrawals; public SavingsAccount () { balance = 0; numberOfWithdrawals = 0; } public voidwithdraw (intamount ) { if (numberOfWithdrawals > 4) { throw newRuntimeException (“If the withdrawls >4 a service charge of 1$ is charged”); } else { balance = balance –amount; numberOfWithdrawals++; } } public voidresetNumOfWithdrawals () {…} }
Watch your spelling. Is it Account or BankAccount? Is it SavingAccount or SavingsAcount? Everything much match. Constructor name needs to match class name. Constructors should be INSIDE the class. Check your brackets. Also, describe what the problems are and please ask a specific question. NetBeans did its best to format SavingsAccount, but got confused due to brackets problems. Please repost corrected, formatted code in code tags, along with a particular question, including line numbers. Thanks.
Re: Design a class named BankAccount to hold the following data for a bank account:
-1
#5 Jul 15th, 2009
@jvd401
- Go to nearest bookshop
- Find IT section
- Look-up programming section
- Find one of Java-How to Program, by Deitel, book
- By the book
- Start reading
- While at break have look on following forum rule
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
Re: Design a class named BankAccount to hold the following data for a bank account:
0
#6 Jul 19th, 2009
Note: This is not my Homework or Assignment.....This is a Question for our research about java that lecturer gave us to learn more about Java....but he didn't tell the answer..told us to find out ourself...But i have tried it do this...Our Java class was only about theory....So i didn't learn about Programming in Java yet...So itz like a difficult question for me because we are only learning theory.....So it will be great if someone can help me with this...i will be grateful to u...Thnkx
__________________________________________________________________
Here is wat i did so far
I created new class called BankAccount.I did till withdraw (method) of BankAccount...but after that i have no clue how to do calcInterest and after on.....SavingsAccount
__________________________________________________________________
Question is ::
Create a class called BankAccount in Java to hold
-Balance
-Number of deposits this month.
-Number of withdrawals.
-Annual Interest rate.
-Monthly charges.
The class should have following methods.
-Constructor (should accept arguments for balance and annual interest rate)
-deposit
-withdraw
-calcInterest(Formulas are Monthly Interest Rate=Annual Interest Rate/12 ,Monthly Interest = Balance * Monthly Interest Rate , Balance = Balance + Monthly Interest)
-monthlyProcess.(method that subtracts monthly service charge from balance,calls calcInterest method and sets the variable that hols number of withdrawals,number of deposits & monthly service charges to 0.
Next,design a SavingsAccount class that extends the BankAccount class. This account should have a status field which represents an active or inactive account.If the balance of saving account falls below $25 account becomes inactive.(No withdrawals allowed until balance is above $25 at which the account becomes active when balance is above $25)
Savings Account should have following methods.
-withdraw (A method that determines whether account is active or inactive.No withdrawal allowed if account is inactive.A withdrawal is then made by calling the superclass version of the method)
-deposit ( Method which checks account is active or inactive..If balance greater than $25 account becomes active.A deposit is then made by calling superclass version of method)
-monthlyProcess (This method checks the number of withdrawals.If the number of withdrawals for the month is greater than 4,a service charge of 1$ for each withdrawal above 4 is added to superclass field that holds the monthly service charges.)
________________________
_________________________
__________________________________________________________________
Here is wat i did so far
I created new class called BankAccount.I did till withdraw (method) of BankAccount...but after that i have no clue how to do calcInterest and after on.....SavingsAccount
__________________________________________________________________
Question is ::
Create a class called BankAccount in Java to hold
-Balance
-Number of deposits this month.
-Number of withdrawals.
-Annual Interest rate.
-Monthly charges.
The class should have following methods.
-Constructor (should accept arguments for balance and annual interest rate)
-deposit
-withdraw
-calcInterest(Formulas are Monthly Interest Rate=Annual Interest Rate/12 ,Monthly Interest = Balance * Monthly Interest Rate , Balance = Balance + Monthly Interest)
-monthlyProcess.(method that subtracts monthly service charge from balance,calls calcInterest method and sets the variable that hols number of withdrawals,number of deposits & monthly service charges to 0.
Next,design a SavingsAccount class that extends the BankAccount class. This account should have a status field which represents an active or inactive account.If the balance of saving account falls below $25 account becomes inactive.(No withdrawals allowed until balance is above $25 at which the account becomes active when balance is above $25)
Savings Account should have following methods.
-withdraw (A method that determines whether account is active or inactive.No withdrawal allowed if account is inactive.A withdrawal is then made by calling the superclass version of the method)
-deposit ( Method which checks account is active or inactive..If balance greater than $25 account becomes active.A deposit is then made by calling superclass version of method)
-monthlyProcess (This method checks the number of withdrawals.If the number of withdrawals for the month is greater than 4,a service charge of 1$ for each withdrawal above 4 is added to superclass field that holds the monthly service charges.)
________________________
Java Syntax (Toggle Plain Text)
________________________ ///////////Main//////////// import java.util.*; import java.text.DecimalFormat; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { double startBalance = 0; double interest; int months; double deposit; double withdraw; Scanner key = new Scanner(System.in); //create an object that accepts the starting balance BankAccount account = new BankAccount(startBalance); DecimalFormat dollar = new DecimalFormat("#,###.00"); System.out.println("Please enter the anual interest rate "); interest=key.nextDouble(); account.setInterest(interest); System.out.println("Please enter the starting balance"); startBalance=key.nextDouble(); System.out.println("Please enter how many months has passed since the account creation "); months=key.nextInt(); for (int i=1; i<=months; i++) { System.out.println("Please enter the amount deposited in the account during the month "+i); deposit = key.nextDouble(); account.deposit(deposit); System.out.println("Please enter the amount to be withdraw during this month "+i); withdraw=key.nextDouble(); account.withdraw(withdraw); //account.addmonthInt(input); //here i think there is the error account.addmonthInt(interest); } System.out.println("Account Balance $"+dollar.format(account.getBalance())); System.out.println("Total withdraws $"+account.totalwithdraw); System.out.println("Total deposits $"+account.totaldeposit); System.out.println("Total Interest Earned $"+account.earnedInt); System.out.println("Anual int"+account.getInt()); } }
Java Syntax (Toggle Plain Text)
class BankAccount { private double balance; double anualInterest; double monthInt; double totaldeposit; double totalwithdraw; double earnedInt; public BankAccount(double startBalance) //Constructor accepting the starting balance { balance = startBalance; } public void deposit(double amount) { balance += amount; totaldeposit += amount; } public void withdraw(double amount) { balance -= amount; totalwithdraw += amount; } public void addmonthInt(double monthlyInterest) { monthInt = (anualInterest / 12); balance += monthInt * balance; earnedInt += monthInt; } public void setInterest(double i) //set your interest rate { monthInt = i; } public double getBalance() { return balance; } public double getInt() { return anualInterest; } }
![]() |
Similar Threads
- Another Bank Account class (C++)
- Bank Account class (C++)
- Help Needed With OOP Bank Account..VB.Net (VB.NET)
- Bank Account ===>Need help >.< Thk (C++)
- Unable to view yahoo mail or online bank account etc (Viruses, Spyware and other Nasties)
- Using Global Low-Level Hooks Without Using A Dll (Computer Science)
- Bank account class (C++)
- Objects (C)
Other Threads in the Java Forum
- Previous Thread: Help on logging values that chance from the forms input ....
- Next Thread: java using looping
Views: 798 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






