/*
Author: Shannon Green
Date: April 23, 2007
Goal: To determine different superannuation products by the users specific input.
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"); // Formats the decimal format, "twoDecimal" to "0.00",
// Declare the following variables as doubles.
double balance = 0; // 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 medBalance = 0; // The medium balance.
double upLimit = 0; // The upper limit of the median.
double yearReturn = 0; // 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; // 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 23, 2007 *");
System.out.println("*****************************************");
System.out.println(" ");
System.out.println(" ");
// User inputs the following variables.
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.
// Sets the medium blanace to the balance inputted by the user.
medBalance = balance;
// Prints out the headings for each variable.
System.out.println("Strategy Name Lower Limit Median Upper Limit");
// Following variables are imported from inFile.dat.
while (inFile.hasNextDouble()) // While the inFile has another line.
{
option = inFile.nextInt(); // The strategy option.
yearReturn = inFile.nextDouble(); // The year return percentage.
firstName = inFile.next(); // First word of the strategy name.
if (!inFile.hasNextDouble()) // If the file doesn't have next double.
{
secondName = inFile.next(); // Second name will be printed (eg: Cautious, Busters)
}
else
{
secondName = ""; // Else, print a space.
}
// Calculate the superannuation for the amount of years to retire.
while (retire > i) // While the inputted retire age is higher than the counter.
{
interest = medBalance * (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.
medBalance = medBalance + median; // The median when the balance is added on.
i++; // The counter goes up by one.
}
// Calculate the lower and upper limits.
lowLimit = medBalance - (medBalance * 0.10); // Minus 10% of the median from the median to result in lower limit.
upLimit = medBalance + (medBalance * 0.10); // Add 10% of the median from the median to result in upper limit.
// Output the results.
System.out.println(option + "\t" + firstName + " " + secondName + "\t" + "$" + twoDecimal.format (lowLimit) + "\t" + "$" + twoDecimal.format (medBalance) + "\t" + "$" + twoDecimal.format (upLimit));
i = 0; // Sets the counter back to 0, so while loop is able to run with retired loops.
medBalance = balance; // Med balance is set back to original inputted balance.
}
inFile.close(); // Closes inFile.dat.
}
}