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

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




Arrays

 
Reply to this topicStart new topic

Arrays

armydud
17 Sep, 2007 - 08:24 AM
Post #1

New D.I.C Head
*

Joined: 17 Sep, 2007
Posts: 1


My Contributions
First off thank you in advance for any and all help that you can give me.. What I'm trying to do is to use an array for a mortgage calculator that displays the months payment for 3 different loans without it scrolling off the screen. When I compile it I get the following error
"(C:\Documents and Settings\new one\Desktop\POS407\MacApplet46.java:18: '(' expected
{
^
C:\Documents and Settings\new one\Desktop\POS407\MacApplet46.java:118: '}' expected
^
2 errors

Tool completed with exit code 1"

for the life of me I can't figure out where I went wrong. I believe it should work the way I have it set up or am I completely wrong?


[applet code]
CODE

<HTML>
<APPLET CODE = "MacApplet46" Width = 410 Height = 410>
</APPLET>
</HTML>


[Main App code]
CODE

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import java.text.DecimalFormat;




public class MacApplet46 extends Applet implements ActionListener
{

    public void calculateFormulas
    {
    //declare variables

     int payment_frequency = 12; // The use of this variable allows us to change the frequency only in one place.
             int number_of_payments[]={7*payment_frequency,15*payment_frequency,30*payment_frequency}; // or the following
             //    int number_of_payments[]={84,180,360};

             double [] interest_rate = {5.35/100,5.5/100,5.75/100}; // Need to divide by 100
             double [] principal = {100000.00,200000.00,300000.00};
             double [] pp = new double[3];

                 pp[0]=1.4;

             double monthly_interest;

        double [] monthly_payment =new double[3];
    DecimalFormat myVar =new DecimalFormat("####0.00");


    //construct components
    Label companyLabel = new Label("Welcome to Macs Mortgage Calculator");
    Label loanAmountLabel = new Label("Please enter your loan amount");
        TextField loanAmountField = new TextField(10);
    Label loanTermLabel = new Label("Please enter loan term length");
        TextField loanTermField = new TextField(10);
    Label interestLabel = new Label(" Please enter your interest rate");
        TextField interestField = new TextField(10);
    Button calcButton = new Button("Calculate");
    Label loanAmounterrorLabel = new Label("                              ");
        TextField loanAmounterrorField = new TextField(0);
    Label loanInteresterrorLabel = new Label("                              ");
        TextField loanInteresterrorField = new TextField(0);
    Label loanTermerrorLabel = new Label("                              ");
        TextField loanTermerrorField = new TextField(0);
    Label loanPaymentsLabel = new Label ("                      ");
        TextField loanPaymentsField = new TextField(0);

    Label outputLabel = new Label(
        "Click Calculate to find out how much your payments will be");

    public void init()
    {
            setBackground(Color.green);
            setForeground(Color.black);
            add(companyLabel);
            add(loanAmountLabel);
            add(loanAmountField);
            add(loanTermLabel);
            add(loanTermField);
            add(interestLabel);
            add(interestField);
            add(calcButton);
            add(loanPaymentsField);
            add(loanPaymentsLabel);
            add(loanAmounterrorLabel);
            loanAmounterrorLabel.setForeground(Color.red);
            add(loanTermerrorLabel);
            add(loanInteresterrorLabel);
            calcButton.addActionListener(this);


            add(outputLabel);


    }


    public void actionPerformed(ActionEvent e)

{
        loanAmount = Integer.parseInt(loanAmountField.getText());

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

            output = AmountFormat.format(principal[x]);
            loanAmountLabel.set.Text("Principal \t: " + output);



            monthly_interest = interest_rate[x] / payment_frequency;

            temp= Math.pow(1 + monthly_interest,(-1* number_of_payments[x]));

            monthly_payment[x] = principal[x] * monthly_interest / (1 - (temp));
            // Could have used a singular variable like payment, for monthly payment instead of an array

            output = NumberFormat.format(interest_rate[x]*100);
            loanInterestLabel.set.Text("Interest Rate \t: " + output + " %");

            loanPaymentsLabel.set.Text("# of payments \t: " + number_of_payments[x]);

            output = AmountFormat.format(monthly_payment[x]);
            // instead of monthly+payment[x], could have used payment as indicated above.

            outputLabel.setText("Monthly payment : " + output + "\n");



}}

[end of code]

*1lacca: added code tags

This post has been edited by 1lacca: 17 Sep, 2007 - 09:30 AM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Arrays
17 Sep, 2007 - 09:36 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
1st error:
The compiler thinks that you wanted to declare public void calculateFormulasas a function, so it is looking for the declaration of parameters that is between (type1 name1, type2 name2, ...). In case of no arguments it still has to be written like this ()

2nd error:
you have more { than } so one closing is missing. If you indent your code correctly, it will be obvious which bracket is not closed.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:29AM

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