import java.util.Scanner;
import java.text.*;
public class CertificateofDeposit5
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
double contribution=0;
double Apr=0;
do
{
System.out.println("Please enter what your able to contribute. ");
contribution = console.nextFloat();
if (contribution <= 99)
{
System.out.println("Current banking rules don't allow this amount. ");
}
}while(contribution <= 99);
do
{
System.out.println("Current Market Annual Interest Rate. ");
Apr = console.nextFloat();
if(Apr <= 0.0 || Apr >= 10)
{
System.out.println("Input not accepted, please enter amount greater that 0% and less than 10%. ");
}
}while(Apr <= 0.0 || Apr >= 10);
System.out.println("Number of Years Planned Investment. ");
int years = console.nextInt();
System.out.println();
printTables(years, contribution, Apr);
System.out.println();
}
public static double calcInt
(double balance, double rate)
{
double xRate = (rate / 100);
double interestTotals = balance * xRate;
balance = balance + interestTotals;
return interestTotals;
}
public static void printTables(int numberRows, double balance, double rate)
{
double compondInterest=0;
System.out.println("Year#\tCash\t\tInterest\tTotalCash");
System.out.println("----- \t----\t\t-------- \t----------");
for (char i = 1; i <= numberRows; i++)
{
compondInterest = calcInt(balance, rate);
printRow(i, balance, compondInterest);
balance = balance + compondInterest;
}
}
public static void printRow(char rowNum, double bal, double interest)
{
double newBalance = bal + interest;
String StringBal = roundTo2Dec(bal);
String StringInt = roundTo2Dec(interest);
String StringNewBal = roundTo2Dec(newBalance);
System.out.println(rowNum + "\t" + StringBal + "\t" + StringInt + "\t\t" + StringNewBal);
}
public static String roundTo2Dec(double value)
{
DecimalFormat Currency = new DecimalFormat("$#,###.0#");
String exactFormat = Currency.format(value);
return exactFormat;}
}
This post has been edited by pbl: 27 March 2011 - 03:22 PM

New Topic/Question
Reply



MultiQuote








|