Investment table

Investment table - } System.out.println("Enter...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * program asks the user to enter the balance, the annual interest * rate, and the period of years he/she would like to invest. * Use a for loop to print the balance of the savings account each year. */ package investmenttable; import java.util.*; /** * * @author Manuel Duenas */ public class InvestmentTable { public static void main(String[] args) { Scanner in = new Scanner(System.in); //initialization double balance = 0; double interestRate = 0; int yearsInvested = 0; //input System.out.println("Enter balance:"); if(in.hasNextDouble()) { balance = in.nextDouble(); } else { System.out.println("Wrong input, please start over."); System.exit(0);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } System.out.println("Enter interest rate:"); if (in.hasNextDouble()) { interestRate = in.nextDouble(); } else { System.out.println("Wrong input, please start over."); System.exit(0); } System.out.println("Enter number of years to invest:"); if (in.hasNextInt()) { yearsInvested = in.nextInt(); } else { System.out.println("Wrong input, please start over."); System.exit(0); } //end input System.out.println("Year"+" "+"Balance"); //loop for (int year = 1; year <= yearsInvested; year++) { balance = balance * (1+interestRate/100); System.out.printf("%4d $%,.2f\n",year, balance); //output } } }...
View Full Document

This note was uploaded on 12/07/2011 for the course BUS 350 taught by Professor Leighjin during the Fall '11 term at S.F. State.

Page1 / 2

Investment table - } System.out.println("Enter...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online