Note that there are some explanatory texts on larger screens.

plurals
  1. POThread main stopped before call to println()?
    primarykey
    data
    text
    <p>the issue now is if your run my program at out put I should have a string output of user entry for monthly investment, interest rate, and year and it should print it in one line and the next line and after that should be the same but diffrent values if the user entred he wanted to enter another different values for monthly investment, interest rate, and year. my prible is it prints everything into just one like ex:$400 2.0% 3 $500 3.0% 2 &lt;--- this starting from $500 should be in the next line not first with the first entry?? </p> <pre><code>System.out.print("Inv/Mo.\tRate\tYears\tFuture Value\n"); for (int j = 0; j &lt; FutureValueArrayList.size(); j++) { String myArrayList = FutureValueArrayList.get(j); System.out.print(ArrayList + "\t"); System.out.println(); } </code></pre> <p>i also get this error i can't seem to figure a way to fix it "Thread main stopped before call to println()" which is the println after the print(ArrayList + "\t"); on the my for loop.</p> <pre><code>import java.util.*; import java.text.*; public class FutureValueApp { public static void main(String[] args) { // display a welcome message System.out.println("Welcome to the Future Value Calculator"); System.out.println(); ArrayList&lt;String&gt; FutureValueArrayList = new ArrayList&lt;String&gt;(); // perform 1 or more calculations Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); // calculate the future value double monthlyInterestRate = interestRate/12/100; int months = years * 12; double futureValue = calculateFutureValue( monthlyInvestment, monthlyInterestRate, months); // get the currency and percent formatters NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); percent.setMinimumFractionDigits(1); // format the result as a single string String results = "Monthly investment:\t" + currency.format(monthlyInvestment) + "\n" + "Yearly interest rate:\t" + percent.format(interestRate/100) + "\n" + "Number of years:\t" + years + "\n" + "Future value:\t\t" + currency.format(futureValue) + "\n"; // print the results System.out.println(); System.out.println("FORMATTED RESULTS"); System.out.println(results); String monthlyInvestmentFormat = currency.format(monthlyInvestment); String interestRateFormat = percent.format(interestRate/100); String futureValueFormat = currency.format(futureValue); FutureValueArrayList.add(monthlyInvestmentFormat); FutureValueArrayList.add(interestRateFormat); FutureValueArrayList.add(Integer.toString(years)); FutureValueArrayList.add(futureValueFormat); // see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } System.out.print("Inv/Mo.\tRate\tYears\tFuture Value\n"); for (int j = 0; j &lt; FutureValueArrayList.size(); j++) { String ArrayList = FutureValueArrayList.get(j); System.out.print(ArrayList + "\t"); System.out.println(); } System.out.println(); } public static double getDouble(Scanner sc, String prompt) { boolean isValid = false; double d = 0; while (isValid == false) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println("Error! Invalid decimal value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return d; } public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max) { double d = 0; boolean isValid = false; while (isValid == false) { d = getDouble(sc, prompt); if (d &lt;= min) System.out.println( "Error! Number must be greater than " + min + "."); else if (d &gt;= max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return d; } public static int getInt(Scanner sc, String prompt) { boolean isValidInt = false; int i = 0; while (isValidInt == false) { System.out.print(prompt); if (sc.hasNextInt()) { i = sc.nextInt(); isValidInt = true; } else { System.out.println("Error! Invalid integer value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return i; } public static int getIntWithinRange(Scanner sc, String prompt, int min, int max) { int i = 0; boolean isValid = false; while (isValid == false) { i = getInt(sc, prompt); if (i &lt;= min) System.out.println( "Error! Number must be greater than " + min + "."); else if (i &gt;= max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return i; } public static double calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { double futureValue = 0; for (int i = 1; i &lt;= months; i++) { futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate); } return futureValue; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload