Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class RetirementCalculator {
- public static void main(String[] args) {
- double averageInterest, amountInvested, endTotal;
- int yearsWait;
- Scanner keyboard = new Scanner(System.in);
- System.out.println("How much did you invest?");
- amountInvested = keyboard.nextDouble();
- while (amountInvested < 1) {
- System.out.println("Amount cannot be negative.");
- System.out.println("How much did you invest? ");
- amountInvested = keyboard.nextDouble();
- }
- System.out.println("How many years do you plan to wait before drawing from your account?");
- yearsWait = keyboard.nextInt();
- while (yearsWait < 1) {
- System.out.println("Years cannot be negative.");
- System.out.println("How many years do you plan to wait before drawing from your account?");
- yearsWait = keyboard.nextInt();
- }
- System.out.println("What is the average expected rate of interest?");
- averageInterest = keyboard.nextDouble();
- while (averageInterest < 0) {
- System.out.println("Average interest cannot be negative.");
- System.out.println("What is the average expected rate of interest?");
- averageInterest = keyboard.nextDouble();
- }
- endTotal = amountInvested * Math.pow((1 + averageInterest), yearsWait);
- System.out.printf("After waiting %,d years, your investment will yield $%,2f.", yearsWait
- , endTotal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement