/**
A savings account has a balance that can be changed by
deposits and withdrawals. It has an interest rate.
Fill in the "todo" locations.
*/
public class SavingsAccount
{
private double balance;
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 1
[b]THIS IS LINE 13. WHAT AM I SUPPOSED TO PUT IN IT?[/b]
//----------------------End here. Do not remove this comment.
/**
Constructs a savings account with a zero balance
and zero interest rate.
*/
public SavingsAccount()
{
balance = 0;
interestRate = 0 ;
}
/**
Constructs a savings account with a given balance and interest rate.
@param initialBalance the initial balance
@param rate the interest rate in percent
*/
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 5
public SavingsAccount(double initialBalance , double interestRate)
{
balance = initialBalance;
double rate = interestRate(rate/100);
}
//----------------------End here. Do not remove this comment.
/**
Deposits money into the savings account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the savings account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
/**
Adds interest to the savings account.
*/
public void addInterest()
{
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 2
double interest = balance * (interestRate/100);
balance = balance + interest;
//----------------------End here. Do not remove this comment.
}
/**
Gets the current balance of the savings account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
Need help with a SavingsAccount.java
Page 1 of 12 Replies - 1089 Views - Last Post: 30 September 2012 - 04:38 PM
#1
Need help with a SavingsAccount.java
Posted 30 September 2012 - 04:02 PM
Hi, i need some help figuring out what i need to do with line 13. I've read the assigned chapter and I haven't found anything that can help me. I've bolded the line and I hope someone out there can help me out.
Replies To: Need help with a SavingsAccount.java
#2
Re: Need help with a SavingsAccount.java
Posted 30 September 2012 - 04:12 PM
Probably:
You set the interestRate variable in your constructor, so you need to have it decleared somewhere.
Also your variable "rate" on line 38 isn't being used or saved anywhere, in essence making it pointless.
private double interestRate;
You set the interestRate variable in your constructor, so you need to have it decleared somewhere.
Also your variable "rate" on line 38 isn't being used or saved anywhere, in essence making it pointless.
This post has been edited by Kakerergodt: 30 September 2012 - 04:18 PM
#3
Re: Need help with a SavingsAccount.java
Posted 30 September 2012 - 04:38 PM
Fixed. Thanks a lot for the speedy and helpful response.
I've edited the code as follows:
I've edited the code as follows:
/**
A savings account has a balance that can be changed by
deposits and withdrawals. It has an interest rate.
Fill in the "todo" locations.
*/
public class SavingsAccount
{
private double balance;
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 1
private double interestRate;
//----------------------End here. Do not remove this comment.
/**
Constructs a savings account with a zero balance
and zero interest rate.
*/
public SavingsAccount()
{
balance = 0;
interestRate = 0 ;
}
/**
Constructs a savings account with a given balance and interest rate.
@param initialBalance the initial balance
@param rate the interest rate in percent
*/
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 5
public SavingsAccount(double initialBalance , double rate)
{
balance = initialBalance;
interestRate = rate;
}
//----------------------End here. Do not remove this comment.
/**
Deposits money into the savings account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the savings account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
/**
Adds interest to the savings account.
*/
public void addInterest()
{
//Reminder: do not write or change code outside of the todo regions.
//----------------------Start here. Do not remove this comment.
// todo
// approximate lines of code required: 2
double interest = balance * interestRate / 100;
balance = balance + interest;
//----------------------End here. Do not remove this comment.
}
/**
Gets the current balance of the savings account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
Page 1 of 1

New Topic/Question
Reply


MultiQuote


|