The Investment class: Write a class called Investment with the following specification:
Class: Investment
Attributes:
-balance : double
- interestRate : double
Methods:
+ Investment()
+ Investment(balance : double, rate : double)
+ getBalance() : double
+ getInterestRate() : double
+ setBalance(balance : double) : void
+ setInterestRate(rate : double) : void
+ totalInterest() : double
+ totalInvestment(periods : int) : double
+ toString() : String
Your class definition must contain all of the members listed in the specification exactly as they are defined.
public class Investment {
private double balance;
private double interestRate;
private double rate;
private double year=0;
public Investment(double Balance, double Rate) {
balance = Balance;
rate = Rate;
}
public double getBalance()
{
return balance;
}
public double getInterestRate(){ return interestRate; }
public void setBalance(double balance){
this.balance = balance;
}
public void setInterestRate(double rate){
this.rate = rate;
}
public double totalInterest(){
year++;
double interest = balance * rate / 100;
balance = balance *interest;
return interestRate;
}
public double totalInvestment(int periods) {
Math.pow((balance*(1+rate/100)), periods);
return 0;
}
public String toString(){
return "Investment Information\nCurrent balance: "+balance+"\nInterest Rate: "+rate;
}
}
can someone check if this code is correct?
1 answer