Hello, I am in a Java Course and my instructor said my first 2 loans the calculations are wrong. and that I need to have this in an ARRAY also.
Any help would be appreciated.

import java.text.*;           
import java.io.IOException;

class javamortgage     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //just as it reads for each to select from
      System.out.println("2-Interest rate of 5.55% for 15 years?");
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");

      answer = (char)System.in.read();

      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 8;
        secondIterate = 24;
        totalMo = 180;
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)


    for(int x = 0; x < 25; x++)System.out.println();
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

Hello, I am in a Java Course and my instructor said my first 2 loans the calculations are wrong. and that I need to have this in an ARRAY also.
Any help would be appreciated.

What did your instructor say was wrong about the numbers? The program seems to run and gives, at first glance, reasonable looking numbers. However, these lines look wrong to me:

amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);

You are charging interest on the full loan for every month. Most loans, if not all loans, only charge interest on the outstanding balance, which would be the full amount for the first month, but less in future months. I imagine that is what your professor is talking about.

In the future, please elaborate beyond "the calculations are wrong". Keep in mind that we are not in this class, so we don't know what the assignment is. For an assignment like this, it's fairly easy to make an educated guess, but you are more likely to get help if you give a more in depth explanation.

This is the comment the instructor made,

"Great work, the numbers were a little off on the 1st and 2nd loans. Next time
try putting the values you displayed in an array."

Any help would be appreciated on the code I posted previously

I do think it is the formula as you have stated ,..but what would be the correct way to calculate the intrest on the balance after each payment is made.

Also what is the best way to add it to an array as the instructor mentioned.

the last 2 asignments read as follows:


Modify the mortgage program to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%. Use an array for the different loans (the array will be needed in the next course). Display the mortgage payment amount for each loan. Do not use a graphical user interface. Insert comments in the program to document the program.

And
Modify the mortgage program to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%. Use an array for the different loans. Display the mortgage payment amount for each loan. Then, list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. Do not use a graphical user interface. Insert comments in the program to document the program.

This is the comment the instructor made,

"Great work, the numbers were a little off on the 1st and 2nd loans. Next time
try putting the values you displayed in an array."

Any help would be appreciated on the code I posted previously

I do think it is the formula as you have stated ,..but what would be the correct way to calculate the intrest on the balance after each payment is made.

Also what is the best way to add it to an array as the instructor mentioned.

Sounds like your instructor didn't explain how to calculate the monthly payment, which is necessary for everything else. I googled the web for a good math link on how to calculate monthly payment and I actually had to go through quite a few links that just did it for you (which probably wouldn't help you here since you have to derive it yourself), but I think I found one.

http://mortgage-x.com/library/answers/amortization.asp

This is an iterative process. You obviously need to end up with an ending balance of 0 at the end. The beginning balance is the loan amount. The number of payments is the number of years of the loan times 12 (# of months in a year). Your monthly interest rate is the annual interest rate divided by 12. The monthly interest is the monthly interest rate times the balance. The new balance is the old balance plus the monthly interest minus the monthly payment. The balance obviously needs to decrease each month.

So if you have an annual interest rate of 12%, or 0.12, your monthly interest rate is one twelfth of that, or 1%, or 0.01. Let's say you have a current balance of $100,000 and a monthly payment of $2,000.

This month's interest payment is 1% of $100,000, or $1,000.
The principal payment is the monthly payment minus the interest payment, or $2,000 minus $1,000, which is $1,000.

The new loan balance is $100,000 minus the principal payment, or $100,000 - $1,000 = $99,000.

For the next month, the interest payment is 1% of $99,000, or $990. The principal payment is the monthly payment ($2,000) minus $990 = $1,010. The new balance therefore is $99,000 minus $1,010 = $97,990.

The next interest payment is 1% of $97,990, or $979.90. The principal payment is $2,000 minus $979.90 = $1,020.10. The new balance is $97,990 - $1,020.10 = $96,969.90. Keep going with this process. Like I said, if the balance does not equal 0 after the final payment, something is wrong.

So from a code point of view, do this:

double monthlyPayment;
int numPayments;
double startBalance;
double monthlyInterestRate;
// code to calculate these values.
double balance[] = new double[numPayments+1];
balance[0] = startBalance;
for (int i = 1; i <= numPayments; i++)
{
     // calculate balance[i] from balance[i-1] using above algorithm
}
// balance[numPayments] should equal 0.
commented: Helpful posts. +8

Do I need to revise my full code?

Do I need to revise my full code?

Not necessarily. That's up to you. You have a program now that works, but gives inaccurate results. You can either start from scratch or you can use what you have already as a skeleton and add in the new code. You don't have an array or arrays, so you'll have to add that. Throw out your old code that calculates the monthly payment and the interest. Add a function that calculates the correct monthly payment. Add a loop that calculates the payments, balance, etc. and places them into an array or arrays. Either have a second loop afterwards that displays that information or have the display code be part of that loop. If it was me, I would have two separate loops. Since your teacher wants an array, having a separate loop demonstrates that you filled in the array(s) properly, but that's up to you. You'll have to decide whether you want to create functions to do the work or have it all in one big function like you do now. I'd break it up into functions.

I say "array or arrays" because you may want to have one array or you may want to have more than one array. Personally, I'd have three arrays: one for outstanding balance, one for interest paid that month, one for principal paid that month, and display all three for each month. I'd calculate them all and store them all in the first for-loop, then display them all in the second for-loop.

Could you guide me with the corrections?

I am not going for java programming, it is just a course I am being made to take.

I have only been attempting this 4 weeks.
Any guidance with code and placement would help me.

Could you guide me with the corrections?

I am not going for java programming, it is just a course I am being made to take.

I have only been attempting this 4 weeks.
Any guidance with code and placement would help me.

Happy to help try to guide you, but give what I suggested a shot and come back with a more specific question about what you don't understand/are stuck on. Break your code into separate tasks, and add a few comments and blank lines in your code to make it clear which task a certain block of code refers to. Right now it kind of runs together, which makes it hard for both the reader and you to follow the logic. Right now your display code works, but your calculation code does not. I would try to get the calculation code working BEFORE worrying about the array. Tackle one problem at a time. You need to get the numbers right and you need to stick those numbers in an array and you need to display those numbers. Those tasks are fairly independent of each other, so make life easier and don't try to do them at the same time. If you get stuck, post the revised code here, along with a detailed description of the problem.

ok I fixed my 15 year loan portion

how would I display the values to the user in an array?????

for all three each loans

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgage     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //just as it reads for each to select from
      System.out.println("2-Interest rate of 5.55% for 15 years?");
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents....DAMN ME
        totalMo = 180;
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
    for(int x = 0; x < 25; x++)System.out.println();
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

This looks the same to me as the last time except that you now correctly calculate for 180 months instead of 192 like you did before. The $0.40 is round-off error. You are still calculating the interest and monthly payment incorrectly. It's somewhat involved mathematically. Reread my post, check out the link I linked to, and check out this link too. This calculates the monthly payment and displays the balances after each month. It doesn't have the best presentation in the world IMO, but plug in your numbers and see the results. In particular, look at how the balance reduces by very little the first months, and reduces more and more each month after that. That's because less money goes to interest each month and more to principal.

http://www.bankrate.com/brm/mortgage-calculator.asp

You need to format and comment your code, break this into separate tasks, and ask a more specific question. Here's a revised skeleton from what I posted before. Use three arrays:

double monthlyPayment;
int numPayments;
double startBalance;
double monthlyInterestRate;
// code to calculate these values.
double balance[] = new double[numPayments+1];
double interest[] = new double[numPayments+1];
double principal[] = new double[numPayments + 1];
balance[0] = startBalance;
interest[0] = 0.0; // no payment for month 0
principal[0] = 0.0; // no payment for month 0
for (int i = 1; i <= numPayments; i++)
{
     // calcualate interest[i] from balance[i-1]
     principal[i] = monthlyPayment - interest[i];
     // calculate balance[i] 
}
// balance[numPayments] should equal 0.

Go to that link I just posted and plug in your numbers to get the correct monthly payment and hard-code the number in for now. You can put monthlyPayment in that switch statement where you calculate numPayments and startBalance (you call them different names, but it's the same thing). Ditto for monthlyInterestRate.

That gets your calculations into the arrays. Set up another for-loop to display the three arrays.

Correction from last post. I incorrectly referred to the code below as a switch statement. In my opinion, you should make it one. Put the code to fill in the variables I referred to in this block of code (again, this could be made into a switch statement):

if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents....DAMN ME
        totalMo = 180;
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }

I say "array or arrays" because you may want to have one array or you may want to have more than one array. Personally, I'd have three arrays: one for outstanding balance, one for interest paid that month, one for principal paid that month, and display all three for each month. I'd calculate them all and store them all in the first for-loop, then display them all in the second for-loop

I like that way that you mentioned...I have one day to correct my code.
Here is my code as of now.

I am very new and we have a class a week for 5 weeks...I got this far in 4 weeks...could you help me for my last and final week of this course

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgage     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //The interest rate per each 3 loans , per line
      System.out.println("2-Interest rate of 5.55% for 15 years?");      //each number is the seletion that a user can select on the keyboard
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents
        totalMo = 180;
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
    for(int x = 0; x < 25; x++)System.out.println();
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

This code still looks the same. Did you change anything? Have you tried my suggestions?

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgage     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //The interest rate per each 3 loans , per line
      System.out.println("2-Interest rate of 5.55% for 15 years?");      //each number is the seletion that a user can select on the keyboard
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
        // hard code moPay value from link I linked to.
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents
        totalMo = 180;
        // hard code moPay from link I linked to.
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
        // hard code moPay from link I linked to.
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
    for(int x = 0; x < 25; x++)System.out.println();
    
    
    
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] )); // delete this line
    moPay = (amount / totalMo);  // delete this line
    totalInt = (principal * rate[ratePlace] * term[ratePlace]); // delete this line
    
    // declare three arrays here
    
    // first for-loop -> put values in arrays
    
    
    
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

Lines 32, 40, 48 - put in the value of moPay. Go to the link I gave you and hard-code the monthly payment that they calculate into the code. Change it later if you have time.

Delete lines 67 through 69. They are incorrect. Look at my previous posts and implement them in lines 71 and 73.

Once you do that, you'll have the information you need in the arrays. If you want to display total interest and total payments, you can, but they are not the calculations from lines 67 through 69. Your display code seems fairly OK, but I'd change the for-loop to something like:

for (int i = 0; i <= moPay; i++)
{
     // display ith element of each array.
     // put code for user pause here if you wish
}

Give this a try. If you don't succeed, that's fine. Repost, but you need to post different code next time so we know what you have tried, and you need to explain more thoroughly what you've tried, what worked, what didn't. etc. No one's going to do it all for you. Finally, to repeat, you need to put some spaces in between the different tasks so the code reads better.

Correction from last post. The display code loop should be:

for (int i = 0; i <= totalMo; i++)
{
     // display ith element of each array.
     // put code for user pause here if you wish
}

The loop control variable is the number of months, not the monthly payment.

ok I am taking a few small steps at a time As you will see....
after a few of your suggestions...I have an error at line
63
i is already defined in main
(int i = 0; i <= totalMo; i++)

I will start with this edited code one at a time...I will not edit any more yet
( do not want to cuase more confusion)

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgageweek5try_ggg     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //The interest rate per each 3 loans , per line
      System.out.println("2-Interest rate of 5.55% for 15 years?");      //each number is the seletion that a user can select on the keyboard
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
        // hard code moPay value from link I linked to.
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents
        totalMo = 180;
        // hard code moPay from link I linked to.
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
        // hard code moPay from link I linked to.
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
 for (int i = 0; i <= totalMo; i++) ///as right now the i is defined already and giving an error when compiling
{
     // display ith element of each array.
     // I could put code for user pause here 
}
    
    // declare three arrays here
    
    // first for-loop -> put values in arrays
    
    
    
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

with the above post as suggested ...the following quote I edited in RED what I did or did not yet do

I DID NOT YET DO --->>>Lines 32, 40, 48 - put in the value of moPay. Go to the link I gave you and hard-code the monthly payment that they calculate into the code. Change it later if you have time.

I DID---->>>Delete lines 67 through 69. They are incorrect. Look at my previous posts and I DID NOT DO -->>>implement them in lines 71 and 73.

ok I am taking a few small steps at a time As you will see....
after a few of your suggestions...I have an error at line
63
i is already defined in main
(int i = 0; i <= totalMo; i++)

If you are using i somewhere and need to retain its value, change i to some other variable name you haven't used. Or you can delete int if i has already been declared as an integer.

delete that full line # 63?

I need sleep for work tomorrow,..but appreciating all the help...I am staying connected but going to bed...I have tomorrow after work to figure this out....the next day I must turn in this asignmnet.
Thank you for guiding and helping me thus far.

delete that full line # 63?

No, just delete the int . Change from this:

for (int i = 0; i <= totalMo; i++)

to this:

for (i = 0; i <= totalMo; i++)

I don't see you using the variable i anywhere, so the above should make it work. Like I said before, if you ARE using the i variable somewhere and need to save its value, rename the variable in the loop above to something you haven't used yet (in this case, keep the word int in the code) like k, m, n, p, or whatever.

Ok that part is done.
I re-compiled it and have errors on line 77, 78, and 80.
Below is my new code ...the error states ...variables may not have been initialized...I made these words red in color for the line errors

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgageweek5try_ggg     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //The interest rate per each 3 loans , per line
      System.out.println("2-Interest rate of 5.55% for 15 years?");      //each number is the seletion that a user can select on the keyboard
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
        // hard code moPay value from link I linked to.
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents
        totalMo = 180;
        // hard code moPay from link I linked to.
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
        // hard code moPay from link I linked to.
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
 for (i = 0; i <= totalMo; i++)
{
     // display ith element of each array.
     // I could put code for user pause here 
}
    
    // declare three arrays here
    
    // first for-loop -> put values in arrays
    
    
    
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }
}

I told you to delete the lines that calculated those values because they were incorrect. You deleted them, but you didn't replace them, so you can't display them. You either need to replace them with the correct values or comment out the code that displays them. I would comment out all of your display code because it's either going to display jibberish or give you an error. My comments are still in the code you just displayed. You need to start replacing those comments with code, and certain things need to be done before others. You can't display the arrays before you declare them and fill them in. You can't calculate total payment and total interest until you calculate the values for the monthly payments. You can't calculate the array values till you get a value for monthly payment. Go to the site I linked and get the monthly payments and fill them in, then declare your arrays and get the calculation code working. If you delete something, you need to comment out or delete anything that relies on it.

that site had only a yearly interest rate,...and it made the payments like 16,000 a payment

that site had only a yearly interest rate,...and it made the payments like 16,000 a payment

Nope, try it again. It's supposed to have a yearly interest rate. That's what your data is.

double rate [ ] = {.0535, .055, .0575};

Your data also has terms that are done in years (7, 15, and 30 years if I recall)
Type in the annual interest rate, type in the number of years, and type in the principal. For 7 years, 5.35%, with a principal of $200,000, it gives a monthly payment of $2859.79. Click the "Show/Recalculate Amortization Table" button and you'll get a month by month layout of the payments, interest, etc. Check your calculations against that.

ok..I forgot to click Show Table

I have
7 yr at 5.35% = 2859.79
15 yr at 5.55% = 1639.48
30 yr at 5.75% = 1167.15

so would it be like
moPay = 1167.15;

or
moPay = $1167.15;

ok..I forgot to click Show Table

I have
7 yr at 5.35% = 2859.79
15 yr at 5.55% = 1639.48
30 yr at 5.75% = 1167.15

so would it be like
moPay = 1167.15;

or
moPay = $1167.15;

moPay is a double, so no dollar sign is allowed. if you want to output the dollar sign, do that in the display code, but not in any type of assignment line or calculation code.

Ok...I am editing small sections at a time...so I do not get even more lost

here is what I have as of now.

import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
 
class memortgage     //program class name
{
  public static void main(String[] args) throws IOException
  {
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character 
    do
    {
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //The interest rate per each 3 loans , per line
      System.out.println("2-Interest rate of 5.55% for 15 years?");      //each number is the seletion that a user can select on the keyboard
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
 
      answer = (char)System.in.read();
 
      if (answer == '1')  //7 yr loan at 5.35%
      {
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
        moPay = 2859.79;  // hard code yr loan moPay to the actual payment precalculated.
      }
      else if (answer == '2') //15 yr loan at 5.55%
      {
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents
        totalMo = 180;
        moPay = 1639.48;  // hard code 15yr moPay to the actual payment precalculated.
      }
      else if (answer == '3') //30 yr loan at 5.75%
      {
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
        moPay = 1167.15;  // hard code 30 yr moPay to the actual payment precalculated.
      }
      else if (answer == '4') //exit or quit
      {
        System.exit(0);
      }
      else
      {
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
      }
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)

 
    for(int x = 0; x < 25; x++)System.out.println();
    
    
    
    //amount = (principal + (principal * rate[ratePlace] * term[ratePlace] )); // delete this line
    //moPay = (amount / totalMo);  // delete this line
   // totalInt = (principal * rate[ratePlace] * term[ratePlace]); // delete this line
    
    // declare three arrays here
    
    // first for-loop -> put values in arrays
    
    
    
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
//working on maybe deleting this --"% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
//working on maybe deleting this --System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n")));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
    {
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
      {
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
        {
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        }
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
      }
    }
  }

You should initialize your variables moPay and amount to zero and see if the program runs for you.

Not saying that is what the values should be, but if you at least initialize them you can run the program and fix the mathematical errors.

Edit: Whoops nevermind, you're calculating the interest for the amount you're paying for, not the amount you're paying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.