Friday, October 16, 2015

ComputeCDValue 5.31

Compute CD Value

This was a pretty easy problem. It was nice to practice formatting!

import java.util.Scanner;
public class ComputCDValue
{
   public static void main(String[] args)
   {
   int end;
   //do while loop allows user to rerun program with different inputs
   do
   {
   //create scanner and input numbers
      Scanner input = new Scanner(System.in);
      System.out.print("Enter the initial deposit amount: ");
      double deposit = input.nextDouble();
      System.out.print("Enter annual percetage yield: ");
      double yield = input.nextDouble();
      System.out.print("Enter maturity period (number of months): ");
      int months = input.nextInt();
   //print headers
      System.out.println("Month   CD Value");
   //loop calculates cd value for each month
      for (int i = 1; i <= months; i++)
      {
         deposit= deposit + deposit * yield / 1200;
         System.out.print(i + "\t");
         System.out.printf("$%8.2f\n", deposit);
      }
      //Prints results
      System.out.println("New calculation? (0 to end): ");
      end = input.nextInt();
      }  
   while (end != 0);
   }
}

No comments:

Post a Comment