All pastes #451315 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-21 12:19 UTC
rendered paste body
/*
Author: Shannon Green
Date: April, 2007
Goal: 
Comments:
*/

import java.io.*; // Imports java input/output files, allowing to input/output to external files.
import java.util.*; // Imports the appropiate java utilities.
import java.text.DecimalFormat; // Imports text to allow decimal format.


public class Assignment1
 {
  static Scanner console = new Scanner(System.in);
  
  public static void main(String[] args) throws FileNotFoundException
  {
     Scanner inFile = new Scanner(new FileReader("inFile.dat")); // Inputs the .dat file of the necessary data.
     
     DecimalFormat twoDecimal = new DecimalFormat ("0.00");
     
     // Declare the following variables as doubles.
     double balance; // The current balance of the superannuation inputted by the employee..
     double contrib = 0; // The total amount contributed thus far by the employer AND employee.
     double grossPay; // The yearly gross pay earned by the employee.
     double interest = 0; // The interest returned from the balance.
     double lowLimit = 0; // The lower limit of the median.
     double median = 0; // The median amount (before balance is added on).
     double upLimit = 0; // The upper limit of the median.
     double yearReturn; // The yearly return of the balance.
  
     // Declare the following variables as int's.
     int age; // The age of the employee.
     int employeeContrib; // The employee contribution of the gross pay.
     int employerContrib; // The employer contribution of the gross pay.
     int i = 0; // The counter used in the while loop.
     int option, option2, option3, option4, option5; // The number of the different stratgies.
     int retire; // How many years until the employee retires.
     
     // Declare the following varaibles as strings.
     String firstName;  // The first word of the strategy name.
     String secondName; // The second word of the strategy name (if applicable).
  
     // The title screen of the assignment.
     System.out.println("*****************************************");
     System.out.println("*        Programming Concepts           *");
     System.out.println("*             Assignment 1              *");
     System.out.println("*        Author: Shannon Green          *");
     System.out.println("*             April ?, 2007             *");
     System.out.println("*****************************************");
     System.out.println(" ");
     System.out.println(" ");
     
     // Following variables are imported from inFile.dat
     
     option = inFile.nextInt();
     yearReturn = inFile.nextDouble();
     firstName = inFile.next();
     secondName = inFile.next();
      
     System.out.println("Please enter your gross pay: ");
     grossPay = console.nextInt(); // Allows the user to input gross pay.
     
     System.out.println("Please enter your current age: ");
     age = console.nextInt(); // Allows the user to input age.
      
     while (age < 18 || age > 70) // While the age is less than 18 or over 70.
      {
         if (age < 18) // If the age is less than 18.
            {
               System.out.println("Age is less than 18. Age must be 18 or over and 70 or under.");
               System.out.println(" ");
               System.out.println("Please enter your current age: ");
               age = console.nextInt(); // Allows the user to input correct age.
            }
         else if (age > 70) // Else if the age is over 70.
            {
               System.out.println("Age is over 70. Age must be 18 or over and 70 or under.");
               System.out.println(" ");
               System.out.println("Please enter your current age: ");
               age = console.nextInt(); // Allows the user to input correct age.
            }
      }
            
      System.out.println("Please enter how many years to retirement: ");
      retire = console.nextInt(); // Allows the user to input years to retirement.
      
      System.out.println("Please enter your current balance: ");
      balance = console.nextInt(); // Allows the user to input their current balance.
      
      System.out.println("Please enter employer contribution (in %): ");
      employerContrib = console.nextInt(); // Allows the user to input employer contribution.
      
      System.out.println("Please enter employee contribution (in %): ");
      employeeContrib = console.nextInt(); // Allows the user to input employee contribution.
 
      while (retire > i) // While the inputted retire age is higher than the counter.
       {
          interest = balance * (yearReturn / 100); // Interest is the balance multiplied by the yearly return (divide 100 to make percentage).
          contrib = grossPay * ((employerContrib + employeeContrib) * 0.01); // Contribution is the gross
          median = interest + contrib; // Median (before balance) is interest plus total contributions.
          balance = balance + median; // The median when the balance is added on.
          i++; // The counter goes up by one.
       }
      
      // Calculate the lower and upper limits.
      lowLimit = balance - (balance * 0.10); // Minus 10% of the median from the median to result in lower limit.
      upLimit = balance + (balance * 0.10); // Add 10% of the median from the median to result in upper limit.
      
      // Output the results.
      System.out.println("Strategy     Name      Lower Limit       Median        Upper Limit");
                  System.out.println("Strategy  Name      Lower Limit       Median        Upper Limit");
      System.out.print(option + "\t" + firstName + " " + secondName + "\t" + twoDecimal.format (lowLimit) + "\t" + twoDecimal.format (balance) + "\t" + twoDecimal.format (upLimit));
      
      inFile.close(); // Closes inFile.dat.
      
     }
    }
   }