50000.0 9.5 20 466.07 25 436.85 30 420.43 10.0 20 482.51 25 454.35 30 438.79 10.5 20 499.19 25 472.09 30 457.37 11.0 20 516.09 25 490.06 30 476.16 11.5 20 533.21 Principal Monthly-Paynent Interest Rate Duration 20.0 466.07 50800.0 9.50 25.0 436.85 30.0 420.43 10.00 20.0 482.51 25.0 454.35 30.0 438.79 10.50 20.0 499.19 25.0 472.09 30.0 457.37 11.00 20.0 516.09 25.0 490.06 30.0 476.16 11.50 20.0 533.21
Hello! I am new to Java and have nearly finished up a project involving a mortgage table, and everything is working properly, but I am running into problems with formatting. I have attached an example below comparing how my result appears compared to a friend's result looking closer to the intention. How could I make it look more like this?
I can see it is due to my spacing being placed within loops, but I cannot figure out how to equalize the spacing with the principal and term printing.
---------------------------------------------------------------
import java.util.Scanner;
public class mortgageTest {
public static void main(String args[]){
Scanner inKey = new Scanner(System.in);
double payment = 0;
System.out.print("Enter Name: ");
String name = inKey.nextLine();
System.out.print("Enter Minimum Principal: ");
double principal = inKey.nextDouble();
System.out.print("Enter Maximum Principal: ");
double endPrincipal = inKey.nextDouble();
System.out.print("Enter Minimum Yearly Interest Rate: ");
double rate = inKey.nextDouble();
double baseRate = rate;
double useRate = rate/100/12;
System.out.print("Enter Maximum Yearly Interest Rate: ");
double endRate = inKey.nextDouble();
double useEndRate = endRate/100/12;
System.out.print("Enter Minimum Term (years): ");
int term = inKey.nextInt();
int baseTerm = term;
int useTerm = term * 12;
System.out.print("Enter Maximum Term (years): ");
int endTerm = inKey.nextInt();
int useEndTerm = endTerm * 12;
System.out.println("\t\t\t\tMortgage Payment Plan\n\t\t\t\t\t"+name+"\nPrincipal \tInterest Rate \tDuration \tMonthly Payment\n");
//----
//PRINCIPAL
while (principal <= endPrincipal) {
System.out.print(principal);
//RATE
while (rate<=endRate) {
System.out.print("\t\t\t"+rate);
//PERIOD
while (term<=endTerm) {
useTerm = term * 12;
useRate = rate/100/12;
payment = (principal * useRate) / (1 - Math.pow(1 + useRate, -useTerm));
payment = (double) Math.round(payment * 100) / 100;
System.out.print("\t\t\t " + term + "\t\t\t" + payment+"\n");
term += 5;
}
System.out.println();
rate += .5;
term = baseTerm;
}
rate = baseRate;
principal += 10000;
}
//----
System.out.println("\nPayment: " + payment);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images