Welcome to Dream.In.Code
Become a Java Expert!

Join 150,379 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,501 people online right now. Registration is fast and FREE... Join Now!




Java errors

 
Reply to this topicStart new topic

Java errors

greenhorn100
4 Feb, 2008 - 11:55 AM
Post #1

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 7

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

I keep getting errors. The first one is cannot resolve symbol: variable loan1.

CODE

import java.io.*;
import java.util.*;
import java.text.*;


public class MortgageCalculator4
{
        public static void main(String[] args)
        {

        NumberFormat nf = NumberFormat.getCurrencyInstance();
    }

            final double amount= 200000;
            final double interest;
            final double months;
    }

             String[] Array = new String[3];


            Array[0] = loan1;
            Array[1] = loan2;
            Array[2] = loan3;

    }
            interest = .0535/12;
            months = 12*7;
            String loan1 =(amount*interest)/(1-Math.pow(1 + interest, -months));

            
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan1));


            interest = .0550/12;
            months = 12*15;
            String loan2 =(amount*interest)/(1-Math.pow(1 + interest, -months));


            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan2));


            interest = .0575/12;
            months = 12*30;

            String loan3 =(amount*interest)/(1-Math.pow(1 + interest, -months));
            
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan3));


    }
}



User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: Java Errors
4 Feb, 2008 - 12:09 PM
Post #2

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
you cant name your array Array name it something else and you have to declare strings before you stick them in the array or use the actual string. loan1 is not a string its an undefined variable. "loan1" is a string. String loan1; declares a string variable. but if youre using an array you probably dont need that. you also have a few extra } <-- of those ill let you figure that out.

This post has been edited by dontKnowJava: 4 Feb, 2008 - 12:13 PM
User is offlineProfile CardPM
+Quote Post

greenhorn100
RE: Java Errors
4 Feb, 2008 - 02:49 PM
Post #3

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 7

QUOTE(dontKnowJava @ 4 Feb, 2008 - 01:09 PM) *

you cant name your array Array name it something else and you have to declare strings before you stick them in the array or use the actual string. loan1 is not a string its an undefined variable. "loan1" is a string. String loan1; declares a string variable. but if youre using an array you probably dont need that. you also have a few extra } <-- of those ill let you figure that out.


[reply]
Thanks for the help. I'm trying to get the array to show the calculated output for loan1, loan2, and loan 3. I have changed my code a bit but still get errors.
[/reply]

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

CODE

import java.io.*;
import java.util.*;
import java.text.*;

public class MortgageCalculator4
{

        public static void main(String[] args)
    {


        NumberFormat nf = NumberFormat.getCurrencyInstance();


            
            int amount= 200000;
            double[] interest={.0535,.0550,.0575};
            int[] months={7,15,30};
            int loan1;
            int loan2;
            int loan3;



            interest = .0535/12;
            months = 12*7;
            loan1 =(amount*interest)/(1-Math.pow(1 + interest, -months));


            //print out variables
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan1));


            interest = .0550/12;
            months = 12*15;
            loan2 =(amount*interest)/(1-Math.pow(1 + interest, -months));


            //print out variables
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan2));


            interest = .0575/12;
            months = 12*30;
            loan3 =(amount*interest)/(1-Math.pow(1 + interest, -months));
            //print out variables

            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan3));


    }
}




User is offlineProfile CardPM
+Quote Post

capty99
RE: Java Errors
4 Feb, 2008 - 03:12 PM
Post #4

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,259



Thanked: 16 times
Dream Kudos: 550
My Contributions
follow what the errors say and you see the issues :

CODE

  interest = .0550/12;
            months = 12*15;
            loan2 =(amount*interest)/(1-Math.pow(1 + interest, -months));



you have an array of 3 items called interest, so what are you trying to do with this .0550/12. add it to the array? then add, don't just set it equal to.

same for months
User is online!Profile CardPM
+Quote Post

dontKnowJava
RE: Java Errors
4 Feb, 2008 - 03:34 PM
Post #5

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
ok that looks a little better. heres an easier way to do it. instead of typing it up 3 times set up a for loop. heres a basic calculator that uses simple interest to calculate monthly payments. if youre gonna copy it as your own make sure your teacher was asking for simple interest and make sure that logic works out right i gotta head to class myself dont have time to check it.
CODE

import java.io.*;
import java.util.*;
import java.text.*;

class MortgageCalculator
{

        public static void main(String[] args)
    {




            int amount= 200000;
            double[] rate={.0535,.0550,.0575};
            int[] years={7,15,30};
            double interest;
            double loan[] = new double[3];//you cant store a double in an int
            //i wasnt sure what method of calculating interest you used but heres how your program should
            //work im using simple interest formula i=(p)(r)(t)

            for(int i = 0; i < 3; i++)    {
                interest = amount * rate[i] * years[i];
                loan[i] = ((interest + amount) / years[i])/12;
                System.out.println("For " + amount + " at " + rate[i] + " for " + years[i] + " years, monthly paymeny is " + loan[i]);
            }


    }

}


This post has been edited by dontKnowJava: 4 Feb, 2008 - 03:39 PM
User is offlineProfile CardPM
+Quote Post

greenhorn100
RE: Java Errors
4 Feb, 2008 - 04:20 PM
Post #6

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 7

QUOTE(capty99 @ 4 Feb, 2008 - 04:12 PM) *

follow what the errors say and you see the issues :

CODE

  interest = .0550/12;
            months = 12*15;
            loan2 =(amount*interest)/(1-Math.pow(1 + interest, -months));



you have an array of 3 items called interest, so what are you trying to do with this .0550/12. add it to the array? then add, don't just set it equal to.

same for months


[reply]
Okay, I see. What I can't seem to understand is how I would equate say the 5.35% interest rate to loan1. In addition, the 84 months to loan1. Thanks for your help!
[/reply]


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

CODE

import java.io.*;
import java.util.*;
import java.text.*;

public class MortgageCalculator4
{

        public static void main(String[] args)
    {


        NumberFormat nf = NumberFormat.getCurrencyInstance();


            //declaring and contruct variables and arrays
            int amount= 200000;
            double[] interest={5.35, 5.50, 5.75};
            int[] months={7,15,30};
            int loan1;
            int loan2;
            int loan3;




            loan1 =(amount*interest)/(1-Math.pow(1 + interest, -months));


            //print out variables
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan1));



            loan2 =(amount*interest)/(1-Math.pow(1 + interest, -months));


            //print out variables
            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan2));



            loan3 =(amount*interest)/(1-Math.pow(1 + interest, -months));
            //print out variables

            System.out.println("\t\tAmount to be financed is: " + amount);
            System.out.println("\t\tInterest Rate: " + interest);
            System.out.println("\t\tThe Term of Loan (in months): " + months);
            System.out.println("\t\tThe Monthly Payment is: " + nf.format(loan3));


    }
}




User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:20PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month