{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Investment table

# Investment table - System.out.println"Enter interest...

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

/* * 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);

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

View Full Document
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

{[ snackBarMessage ]}

### Page1 / 2

Investment table - System.out.println"Enter interest...

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

View Full Document
Ask a homework question - tutors are online