package aly; import java.util.Scanner; public class interest { public static void main(String[] args) { // Constants double rate = 0; double balance = 0; int q = 0; String m = "months"; String y = "years"; int nmonths = 0; // ask question System.out.println("Welcome to the interest calcaluter"); System.out.println("Enter in a ammount of money, an intrest rate, and a ammount of Years // or months (specify weather years or months and use a space between each number given), press Q to quit >> "); Scanner in = new Scanner(System.in); balance = in.nextInt(); rate = in.nextInt(); int nperiods = in.nextInt(); String s = in.next(); double startBalance = balance; double cumulativeInterest = 0; double tempRate = rate; // converter if (s.equalsIgnoreCase(y)) { nmonths = nperiods * 12; tempRate = rate/12; } for (int months = 1; months <= nmonths; months++) { double interest = balance * tempRate / 100; cumulativeInterest += interest; balance = balance + interest; } System.out.println("at a " + rate + " over " + nperiods + " " + s + "(s) the interest is " + cumulativeInterest); System.out.println("The starting balance was " + startBalance); System.out.println("The ending balance was " + balance); System.out.println("Thank you for using the interest calculator "); } }