Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

I had this question before but I am stuck on how to get it to output correctly. This is my assignment:

Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%

- 15 year at 5.5%

- 30 year at 5.75%

Use an array for the different loans. Display the mortgage payment amount for each loan.

Here is my code:

/*Joshua Gutierrez

PRG 420

Week 4

Individual Assignment

3/26/3011

*/

import java.io.IOException;

public class GutierrezMortgages {

//Method to Calculate Mortgage using the principal amount, the interest, and the term

static int MAX_LINECOUNT = 200;

static double[] loanTerm = {360.0,180.0,84.0}; //*30 years, 15 years, 7 years

static double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)

static int loanAmount = 200000; //*$200,000 Loan

// float myCalculatedMortgage;

float myCalculatedMortgageTwo;

float myCalculatedMortgageThree;

public double calculateMortgage (int loanAmount, double loanInterest, double loanTerm) {

double myMortgage = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));

double myMortgageTwo = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));

double myMortgageThree = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));

return myMortgage;

}

//Method to display the calculated mortgage

public void displayTheMortgage(double myCalculatedMortgage) {

System.out.println();

System.out.println("\t\tLoan Amount: $200,000.00");

System.out.println("\t\tTerm: 7 Years");

System.out.println("\t\tInterest Rate 5.35%");

System.out.printf("\t\tThe monthly payment amount is $%.2f", +myCalculatedMortgage);

System.out.println();

System.out.println("\t\tTerm: 15 Years");

System.out.println("\t\tInterest Rate 5.5%");

System.out.printf("\t\tThe monthly payment amount is $%.2f", +myCalculatedMortgageTwo);

System.out.println();

System.out.println("\t\tTerm: 30 Years");

System.out.println("\t\tInterest Rate 5.75%");

System.out.printf("\t\tThe monthly payment amount is $%.2f", +myCalculatedMortgageThree);

System.out.println();

}

//Delcare main () method created instance//

public static void main(String[] args){

// Method Variables

// double loanTerm[] = {360.0,180.0,84.0}; //*30 years, 15 years, 7 years

// double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)

// int loanAmount = 200000; //*$200,000 Loan

double myCalculatedMortgage, myCalculatedMortgageTwo, myCalculatedMortgageThree; //*Three Payment Amounts

//Array for Loan Term

int[] aloanTerm;

aloanTerm = new int[3];

aloanTerm[0] = 360;

aloanTerm[1] = 180;

aloanTerm[2] = 84;

//Array for Interest

// double loanInterest[];

loanInterest = new double[3];

loanInterest[0] = .0575;

loanInterest[1] = .0550;

loanInterest[2] = .0535;

// Create an instance of the class

GutierrezMortgages myInstance = new GutierrezMortgages ();

// Use my the class instance and the dot notation to call the method that calculates the mortgage

int index = Integer.parseInt(args[0]);

double myMortgage = myInstance.calculateMortgage (loanAmount, loanInterest[index-1], loanTerm[index-1]);

// Display the calculated mortgage

myInstance.displayTheMortgage(myMortgage);

//Display Mortgage Given Array Variables

for(int x = 0; x < loanInterest.length; x++) {

System.out.println(aloanTerm[x] + " year at " + loanInterest[x] + "%:");

myMortgage = (loanAmount*loanInterest[index-1]/12)/(1-Math.pow(1+loanInterest[index-1]/12, -loanTerm[index-1]));

System.out.println(myMortgage);

//Conditional Statement To Pause and Continue

int linecount = 0;

if (linecount == MAX_LINECOUNT) {

linecount = 1;

try {

System.in.read();

} catch (IOException e) {

e.printStackTrace();

}

}

else {

linecount++;

}

}

}

}

My Output is rather funky and I am stuck on how to display it neatly:

C:\Users\Joshua\Documents\UoPhoenix\PRG 420\Week 5>java GutierrezMortgages 1

Loan Amount: $200,000.00

Term: 7 Years

Interest Rate 5.35%

The monthly payment amount is $1167.15

Term: 15 Years

Interest Rate 5.5%

The monthly payment amount is $0.00

Term: 30 Years

Interest Rate 5.75%

The monthly payment amount is $0.00

360 year at 0.0575%:

1167.1457128870984

180 year at 0.055%:

1167.1457128870984

84 year at 0.0535%:

1167.1457128870984

Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%

- 15 year at 5.5%

- 30 year at 5.75%

Use an array for the different loans. Display the mortgage payment amount for each loan.

Here is my code:

/*Joshua Gutierrez

PRG 420

Week 4

Individual Assignment

3/26/3011

*/

import java.io.IOException;

public class GutierrezMortgages {

//Method to Calculate Mortgage using the principal amount, the interest, and the term

static int MAX_LINECOUNT = 200;

static double[] loanTerm = {360.0,180.0,84.0}; //*30 years, 15 years, 7 years

static double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)

static int loanAmount = 200000; //*$200,000 Loan

// float myCalculatedMortgage;

float myCalculatedMortgageTwo;

float myCalculatedMortgageThree;

public double calculateMortgage (int loanAmount, double loanInterest, double loanTerm) {

double myMortgage = (loanAmount*loanInterest/1

double myMortgageTwo = (loanAmount*loanInterest/1

double myMortgageThree = (loanAmount*loanInterest/1

return myMortgage;

}

//Method to display the calculated mortgage

public void displayTheMortgage(double myCalculatedMortgage) {

System.out.println();

System.out.println("\t\tLo

System.out.println("\t\tTe

System.out.println("\t\tIn

System.out.printf("\t\tThe

System.out.println();

System.out.println("\t\tTe

System.out.println("\t\tIn

System.out.printf("\t\tThe

System.out.println();

System.out.println("\t\tTe

System.out.println("\t\tIn

System.out.printf("\t\tThe

System.out.println();

}

//Delcare main () method created instance//

public static void main(String[] args){

// Method Variables

// double loanTerm[] = {360.0,180.0,84.0}; //*30 years, 15 years, 7 years

// double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)

// int loanAmount = 200000; //*$200,000 Loan

double myCalculatedMortgage, myCalculatedMortgageTwo, myCalculatedMortgageThree;

//Array for Loan Term

int[] aloanTerm;

aloanTerm = new int[3];

aloanTerm[0] = 360;

aloanTerm[1] = 180;

aloanTerm[2] = 84;

//Array for Interest

// double loanInterest[];

loanInterest = new double[3];

loanInterest[0] = .0575;

loanInterest[1] = .0550;

loanInterest[2] = .0535;

// Create an instance of the class

GutierrezMortgages myInstance = new GutierrezMortgages ();

// Use my the class instance and the dot notation to call the method that calculates the mortgage

int index = Integer.parseInt(args[0]);

double myMortgage = myInstance.calculateMortga

// Display the calculated mortgage

myInstance.displayTheMortg

//Display Mortgage Given Array Variables

for(int x = 0; x < loanInterest.length; x++) {

System.out.println(aloanTe

myMortgage = (loanAmount*loanInterest[i

System.out.println(myMortg

//Conditional Statement To Pause and Continue

int linecount = 0;

if (linecount == MAX_LINECOUNT) {

linecount = 1;

try {

System.in.read();

} catch (IOException e) {

e.printStackTrace();

}

}

else {

linecount++;

}

}

}

}

My Output is rather funky and I am stuck on how to display it neatly:

C:\Users\Joshua\Documents\

Loan Amount: $200,000.00

Term: 7 Years

Interest Rate 5.35%

The monthly payment amount is $1167.15

Term: 15 Years

Interest Rate 5.5%

The monthly payment amount is $0.00

Term: 30 Years

Interest Rate 5.75%

The monthly payment amount is $0.00

360 year at 0.0575%:

1167.1457128870984

180 year at 0.055%:

1167.1457128870984

84 year at 0.0535%:

1167.1457128870984

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

int index = Integer.parseInt(args[0]);

double myMortgage = myInstance.calculateMortga

to the following three lines:

double myMortgage = myInstance.calculateMortga

double myMortgageOne = myInstance.calculateMortga

double myMortgageTwo = myInstance.calculateMortga

and then you''ll not need any command line arguments.

Change these lines:

for(int x = 0; x < loanInterest.length; x++) {

System.out.println(aloanTe

myMortgage = (loanAmount*loanInterest[i

System.out.println(myMortg

to the following:

NumberFormat numForm = NumberFormat.getCurrencyIn

for(int x = 0; x < loanInterest.length; x++) {

System.out.println(aloanTe

myMortgage = (loanAmount*loanInterest[i

System.out.println(numForm

waht I mean by index - to select variant. If not

you want to print all of them and you don't need to read index

It produces the following output:

Loan Amount: $200000,00

Term: 30 Years Interest Rate: 5,75% The monthly payment amount is $1167,15

Term: 15 Years Interest Rate: 5,50% The monthly payment amount is $1634,17

Term: 7 Years Interest Rate: 5,35% The monthly payment amount is $2859,79

```
import java.io.IOException;
public class GutierrezMortgages {
//Method to Calculate Mortgage using the principal amount, the interest, and the term
static int[] loanTerm = {360,180,84}; //*30 years, 15 years, 7 years
static double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)
static double loanAmount = 200000; //*$200,000 Loan
public static double calculateMortgage (double loanAmount, double loanInterest, int loanTerm) {
double myMortgage = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));
return myMortgage;
}
//Method to display the calculated mortgage
public static void displayTheMortgages() {
System.out.println();
System.out.printf("\t\tLoan Amount: $%.2f\n", loanAmount);
for (int i = 0; i < loanTerm.length; i++) {
System.out.printf("\t\tTerm: %d Years", loanTerm [i] / 12);
System.out.printf("\t\tInterest Rate: %.2f%%", loanInterest[i] * 100);
System.out.printf("\t\tThe monthly payment amount is $%.2f", calculateMortgage (loanAmount, loanInterest[i], loanTerm[i]));
System.out.println();
}
}
public static void main(String[] args){
displayTheMortgages();
}
}
```

I added index argument because I saw that you in fact calculate only one variant.

If you want to calculate for all cases it will also make

sense to make array out of myMortgage, myMortGagaOn2, myMortgageTwo - why not to have double myMortGage[3];

- it will simplify code

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial```
Loan Amount: $200000.00
Term: 30 Years Interest Rate: 5.75% The monthly payment amount is $1167.15
Term: 15 Years Interest Rate: 5.50% The monthly payment amount is $1634.17
Term: 7 Years Interest Rate: 5.35% The monthly payment amount is $2859.79
```

Java

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

What is it in particular that you are talking about - do you mean it is format of numbers 1167.1457128870984

with many decimals that you don't like, or you are talking abouyrt numbers themsaelves?