Take this tester program: package investment; * This program computes how long i
ID: 3639970 • Letter: T
Question
Take this tester program:package investment;
*
This program computes how long it takes for an investment
to double.
*/
public class InvestmentRunner
{
public static void main(String[] args)
{
final double INITIAL_BALANCE = 10000;
final double RATE = 5;
Investment invest = new Investment(INITIAL_BALANCE, RATE);
invest.waitForBalance(2 * INITIAL_BALANCE);
int years = invest.getYears();
System.out.println("The investment doubled after "
+ years + " years");
}
}
And 1) Change the program so that the user has to enter the initial balance and the interest rate. Assume that the user will enter interest rates in whole numbers ("5" would represent an interest rate of 5%, for example). Assume that the user will enter initial balances that are numeric only - no commas. 2) Change the code to display how many years it takes an investment to triple.
Explanation / Answer
Modified Code: import java.util.Scanner; public class InvestmentRunner { public static void main(String[] args) { Scanner scan = new Scanner(System.in); final double INITIAL_BALANCE = scan.nextDouble(); final double RATE = scan.nextDouble(); Investment invest = new Investment(INITIAL_BALANCE, RATE); invest.waitForBalance(3 * INITIAL_BALANCE); int years = invest.getYears(); System.out.println("The investment tripled after " + years + " years"); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.