Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Write a description of class Project2 here.
- * Kailey McNeal
- * 10-9-14
- * Project #2
- */
- public class Project2
- {
- public static void main (String[] args)
- {
- Scanner console=new Scanner (System.in);
- System.out.print("Interest Rate: ");
- double percent=console.nextDouble();
- System.out.print("Initial Deposit: ");
- double initial=console.nextDouble();
- System.out.print("Time(Years) : ");
- int years=console.nextInt();
- System.out.print("Yearly Deposit: ");
- double extra=console.nextDouble();
- System.out.println();
- header();
- for (int i=1; i<=years; i++) //year
- {
- double rate=(percent/100);
- double interest = (initial*rate);
- interest=Math.round(interest*100);
- interest=interest/100;
- double balance=interest + initial;
- balance=Math.round(balance*100);
- balance=balance/100;
- double newbalance=balance+extra;
- String ival=String.valueOf(i);
- String initialval=String.valueOf(initial);
- String interestval=String.valueOf(interest);
- String balanceval=String.valueOf(balance);
- String extraval=String.valueOf(extra);
- String newbalanceval=String.valueOf(newbalance);
- System.out.print("|" + i);
- spaces(ival.length());
- System.out.print("|$" + initial);
- spaces(initialval.length());
- System.out.print("|$" + interest);
- spaces(interestval.length());
- System.out.print("|$" + balance);
- spaces(balanceval.length());
- System.out.print("|$" + extra);
- spaces(extraval.length());
- System.out.print("|$" + newbalance);
- spaces(newbalanceval.length());
- System.out.println("|");
- initial=newbalance;
- }
- }
- public static void header()
- {
- System.out.println("| Years | Initial | Interest | Balance | Deposit |New Balance|");
- }
- public static void spaces(int length)
- {
- for (int i=1; i<11-length; i++)
- {
- System.out.print(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement