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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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);

}
}

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
Transcribed Image Text: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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Hiring Problem
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education