Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
The Investment class: Write a class called Investment with the following specification: Class: Investment Attributes: - balance...Asked by anonymous
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?
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?
Answers
Answered by
oobleck
yeah - java can do that for you, right?
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.