Java Help Please

Mortgage Calculator For Class

Page 1 of 1

7 Replies - 1007 Views - Last Post: 23 February 2010 - 06:02 AM Rate Topic: -----

#1 Guest_Teresa Skinner*


Reputation:

Java Help Please

Posted 22 February 2010 - 09:34 PM

I am having MAJOR problems with my assignment for my Java class. My instructor keeps telling to refer to my manuals; which I have done so many times I can almost quote them. I will be honest with you I have no clue what I am doing. I am sorry if I do not present this in the right way as I said I have NO idea what I am doing. Thank you for your time and help if there is any for me.


package teresasmortgagepaymentcalculator;


public class Teresa Mortgage Payment Calculator

{
    private static double DPayment;
    private static double ddate;
    private static double dmonthlyinterest;
    private static int[] dinterest;
    private static double dmonthlyprincipal;
    private static double dpayment;
    private static double dmonthlybalance;
    private static int[] iTerm;
//The main function for the mortgage calculator
public static void main(String[] args)
{
//Declaring and constructing variables
int [] iterm = {84, 180, 360};
double [] dInterest = {5.35, 5.5, 5.75};
double DPpayment, drate, damount = 200000, DMonthlyInterest,MonthlyPrincipal, DMonthlybalance;
decimalformat toDigits =  decimalformat();

//output for month to years
System.out.println();
System.out.println ();
System.out.println();
System.out.println("An 84-month loan equals a 7-year loan.");
System.out.println("A 180-month loan equals a 15-year loan.");
System.out.println("A 360-month loan equals a 30-year loan.");
System.out.println();

//Loop for the varying Mortgage Rates and Payments
int p;
for (p = 0; p <= 2; p ++)
{

//Calculation for the monthly mortgage payment
//Calculations Retrieved from http://www.1728.com/loanform.htm on 8/15/08
drate = dInterest[p] / 1200;
DPayment = (damount * ddate) / (1 - math.pow(1 / (1 + drate), iterm[p]));
dmonthlyinterest = (damount / 12) * (dinterest[p] / 100);
dmonthlyprincipal = (dpayment - dmonthlyinterest);
dmonthlybalance = (damount - dmonthlyprincipal);

// Output for the loan information and the monthly payment
int nbYear = iTerm[p] / 12;
System.out.println();
System.out.println("Your Monthly Payment for a " + nbYear +" years loan of $200,000 at " + dinterest[p]+ "% is:" + twodigits.format (dpayment));
System.out.println();
}

}

    private static decimalformat decimalformat() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
//function for the calculation of the interest into the loan payment
public double MonthlyInterest()
{
//Declaring Variables for interest on the loan
double dMonthlyInterest = 0.0;
double dAmount = 0.0;
double dInterest = 0.0;

//Calculation for monthly interest
dMonthlyInterest = (dAmount / 12) * (dInterest / 100);

return dMonthlyInterest;

}


//function for the calculation of the interest into the loan payment
public double monthlyInterest()
{
//Declaring Variables for interest on the loan
double dMonthlyInterest = 0.0;
double dAmount = 0.0;
double dInterest = 0.0;

//Calculation for monthly interest
dMonthlyInterest = (dAmount / 12) * (dInterest / 100);

return dMonthlyInterest;

}

//function of the calculation of the monthly principal for the loan payment
public static double monthlyPrincipal()
{
//Declaring Variables for monthly principal
double dMonthlyPrincipal = 0.0;
double dPayment = 0.0;
double dMonthlyInterest = 0.0;

//Calculations for monthly principal
dMonthlyPrincipal = (dPayment - dMonthlyInterest);

return dMonthlyPrincipal;

}

//function for the calculation of the monthy loan balance
public static double monthlyBalance()
{
//Declaring Variables for monthly loan balance
double dMonthlyBalance = 0.0;
double dAmount = 0.0;
double dMonthlyPrincipal = 0.0;

//Calculations for monthly loan balance
dMonthlyBalance = (dAmount - dMonthlyPrincipal);

return dMonthlyBalance;

}

}


This post has been edited by pbl: 22 February 2010 - 09:39 PM
Reason for edit:: Your first post... code tags added free of charge


Is This A Good Question/Topic? 0

Replies To: Java Help Please

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Help Please

Posted 22 February 2010 - 09:38 PM

Please :code:
One thing for sure you cannot have spaces in a Class name or variable name or method name so

public class Teresa Mortgage Payment Calculator

should be

public class TeresaMortgagePaymentCalculator

Also "Java Help Please" is kind of useless topic title in this forum
99% of the topics in this forum could have that topic title

This post has been edited by pbl: 22 February 2010 - 09:41 PM
Reason for edit:: Rule #5 Have a meaningful topic title

Was This Post Helpful? 0
  • +
  • -

#3 japanir   User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Java Help Please

Posted 22 February 2010 - 09:48 PM

also, you declare your variables as global, why do you declare them again in the main?
like here for example:
//global:
private static double DPayment;

//inside the main:
double DPpayment,//...

it is enough to do:
//global:
private static double DPayment;

//inside the main:
DPpayment = //some value


you repeat this mistake with most of your variables.

also, if you want to initiate an array by assigning the values as:
int[] arr = {1,2,3};

this code must be done in one statement.
therefore, this code is illegal:
int[] arr;
arr = {1,2,3};

Was This Post Helpful? 0
  • +
  • -

#4 Guest_Teresa Skinner*


Reputation:

Re: Java Help Please

Posted 22 February 2010 - 10:12 PM

View Postpbl, on 22 February 2010 - 08:38 PM, said:

Please :code:
One thing for sure you cannot have spaces in a Class name or variable name or method name so

public class Teresa Mortgage Payment Calculator

should be

public class TeresaMortgagePaymentCalculator

Also "Java Help Please" is kind of useless topic title in this forum
99% of the topics in this forum could have that topic title

Was This Post Helpful? 0

#5 Guest_Teresa Skinner*


Reputation:

Re: Java Help Please

Posted 22 February 2010 - 10:21 PM

View PostTeresa Skinner, on 22 February 2010 - 09:12 PM, said:

View Postpbl, on 22 February 2010 - 08:38 PM, said:

Please :code:
One thing for sure you cannot have spaces in a Class name or variable name or method name so

public class Teresa Mortgage Payment Calculator

should be

public class TeresaMortgagePaymentCalculator

Also "Java Help Please" is kind of useless topic title in this forum
99% of the topics in this forum could have that topic title




I am very sorry for the general title of my post. I did not have any idea as to what type of help I needed. I thought that the the public class needed to be together and tried that but still did not change any thing so I put it back. Thank you for your help. I still do not understand what else needs to be fixed to get this to work and I am to the point of giving up. But then I will not pass and have to take this class again.

There is another post that has tried to help but I do not get what they mean by the variables as global. I am sorry to sound stupid at this but I am. I still can not get it to work.
Was This Post Helpful? 0

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Help Please

Posted 22 February 2010 - 10:22 PM

Thanks for quoting my post
And your question is ?
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Teresa Skinner*


Reputation:

Re: Java Help Please

Posted 22 February 2010 - 10:32 PM

View Postpbl, on 22 February 2010 - 09:22 PM, said:

Thanks for quoting my post
And your question is ?


Your welcome.


Some one else posted:

also, you declare your variables as global, why do you declare them again in the main?

like here for example:

//global:
private static double DPayment;

//inside the main:
double DPpayment,//...

it is enough to do:


//global:
private static double DPayment;

//inside the main:
DPpayment = //some value


I am not understanding what they mean. I have gone back and read my code and do not see anything that says gloabal or private. I see public. Can you explain what they mean?
Was This Post Helpful? 0

#8 japanir   User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Java Help Please

Posted 23 February 2010 - 06:02 AM

take this code for example: (this code is wrong, it will give an error if compiled, it is just to show the problem i mentioned):
public class A {
       
       //global variable 
       private int globalVariable;
       
       //a method
       public int getNum(){
            //here is the mistake.
            //globalVariable was already declared. there is no need to
            //declare it agian here.
            //to fix it, just remove the data type.
            int globalVariable = 10;
            return globalVariable;
       }
}   



after reading my comments in the upper code, you may understand that the correct form of it should look like:
public class A {
       
       //global variable 
       private int globalVariable;
       
       //a method
       public int getNum(){
            //just assigning the global variable a value.
            //without declaring it again.
            globalVariable = 10;
            return globalVariable;
       }
}   

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1