I set my program up to print to a file, which works correctly. The only issue is that, since I made this change, the program does not continue as it should after the data is ouputed to the file.

Loan.printAmortTable(name, custID, loanID, cBalance, term, cPayment);
System.out.println();
System.out.print("Would you like to print this schedule? y/n: ");
String l = input.next();
switch(l)
{
case "y": 
    try 
    {
         Loan.printSchedule(name, custID, loanID, cBalance, term, cPayment);
    } 
    catch (FileNotFoundException e) 
        {
         e.printStackTrace();
    }
    System.out.println("Printed to output.txt");
    input.next();
    break;
case "n":
    break;
}

Loan.printSchedule

public static void printSchedule(String name, int custID, int loanID, double loanAmount, int term, double payment) throws FileNotFoundException
{
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
out.println("Name " + name);
out.println("ID # " + custID);
out.println("Loan # " + loanID);
out.println("Amount Borrowed " + loanAmount);
out.println("Interest Rate 10.99%");
out.println("Term of the loan " + term);
out.println();

out.println("Payment     Payment     Interest     Principle     Outstanding");
out.println("Number      Amount      Portion      Portion       Balance  ");
double pay = Loan.amortization(loanAmount, term);
double balance = loanAmount;
int i = 0;
while (i<term*12)
{
out.printf("%3d", i + 1);
out.printf("%14.2f",pay);
double interest = balance * (interestRate);
interest = (double)Math.round(interest*100)/100;
out.printf("%11.2f", interest);
double principal = payment - interest;
principal = (double)Math.round(principal*100)/100;
out.printf("%15.2f", principal);
balance = balance - principal;   
    balance = (double) Math.round(balance*100)/100;
    out.printf("%15.2f%n", balance);
    i++;
}
out.close();
}

Is this some kind of buffer issue?

有帮助吗?

解决方案

You've switched System.out here:

System.setOut(out);

Then, you close that stream. Once you return from that method, you try to print to System.out again, which is failing. Remove the System.setOut(out); line and it should work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top