#java break issue

10 messages · Page 1 of 1 (latest)

untold venture
#

For some reason adding this break won't allow me to print what is above it in this if statement

         if(monthlyPrincipalPayment < 0) {
                System.out.print("Error: Impossible to payoff balance under these conditions");
                isPossible = false;
                break;
            }
valid novaBOT
#

This post has been reserved for your question.

Hey @untold venture! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fiery wagon
untold venture
#

well if I delete the break it will print

#

heres more of the code

#
    public int calculatePayoff(boolean output) {
        double monthlyInterestRate = 0;
        double monthlyInterestCharge = 0;
        double monthlyPrincipalPayment = 0;
        int monthsCount = 0;
        double tempBalance = this.balance;
        double totalRate = 0;
        double monthlyInterestTotal = 0;
        boolean isPossible = true;
        while(tempBalance > 0) {
            monthlyInterestRate = rate/12;
            monthlyInterestCharge = monthlyInterestRate*tempBalance;
            monthlyPrincipalPayment = monthlyPayment - monthlyInterestCharge;
            tempBalance = tempBalance-monthlyPrincipalPayment;
            monthsCount++;
            monthlyInterestTotal = monthlyInterestTotal + monthlyInterestCharge;
            if(monthlyPrincipalPayment < 0) {
                System.out.print("Error: Impossible to payoff balance under these conditions");
                isPossible = false;
                break;
            }
            if(output) {
                if(tempBalance < 0) {
                    System.out.printf("Payment: " + monthsCount + " - Principal: %.2f - Interest: %.2f - Remaining Balance: 0.00\n", (monthlyPrincipalPayment+tempBalance), monthlyInterestCharge);
                } else { 
                    System.out.printf("Payment: " + monthsCount + " - Principal: %.2f - Interest: %.2f - Remaining Balance: %.2f\n", monthlyPrincipalPayment, monthlyInterestCharge, tempBalance);
                }
            } 
            try{
            Thread.sleep(500);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

        if(output) {
            System.out.printf("Total Interest Paid: %.2f\n" , monthlyInterestTotal);
        }
        return monthsCount;
    }
#

Heres how I call it

#
switch(choice) {
                    case 1: output = true;
                    Card card2 = new Card(rate, balance, monthlyPayment);
                    monthsCount = card2.calculatePayoff(output);
                    if(card2.getIsPossible() == false){
                        break;
                    } else{
                        System.out.println("Months until payoff: " + monthsCount);
                        break;
                    }
fiery wagon
#

Maybe your system doesn't display text that don't include a newline, but it's not so much the break as it is that there are no sufficient lines of code to have the text displayed