Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,285 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,392 people online right now. Registration is fast and FREE... Join Now!




Trying to figure this out?!

 
Reply to this topicStart new topic

Trying to figure this out?!, Mortgage Calculator 12 errors Can you assist?

rettah1
1 Sep, 2008 - 12:23 PM
Post #1

New D.I.C Head
*

Joined: 25 Jul, 2008
Posts: 17


My Contributions
CODE

package week2;

public class Main {

    public static void main(String[] args) {
        // TODO code application logic here
    }
    
import java.applet.Applet;
import java.awt.*;
public class MortgageApp extends Applet
{   TextField balField;
    TextField intField;
    TextField nyrField;
    Button OK;
    TextArea msgArea;

// Convert double to dollars and cents
    static String format(double dollars)
    {   String numString = Double.toString(dollars);
        int dotpos = numString.indexOf(`.');
        if (dotpos < 0)  // Check if whole number
            return numString;
        // Check for excess fraction digits
        else if (dotpos < numString.length() - 2)
            return numString.substring(0, dotpos + 3); // `.'+ 2 digits
        else return numString + "0"; // Assume only 1 fraction digit
    }
public void init()
    {   balField = new TextField("", 15);
        intField = new TextField("", 5);
        nyrField = new TextField("", 5);
        OK = new Button("Compute");
        msgArea = new TextArea("", 15, 60);
        msgArea.setEditable(false);
        add(new Label("Enter principal"));
        add(balField);
        add(new Label("Enter annual interest rate"));
        add(intField);
        add(new Label("Enter number of years"));
        add(nyrField);
        add(OK);
        add(msgArea);
    }
public boolean action(Event evt, Object arg)
    {   if (evt.target == OK) {
            this.update();
            return true;
        }
        else return false;
    }

void update()
    {   String balString = balField.getText();
        String intString = intField.getText();
        String nyrString = nyrField.getText();
        if (balString.trim().length() == 0)
            msgArea.setText("Principal amount missing");
        else if (intString.trim().length() == 0)
            msgArea.setText("Interest rate missing");
        else if (nyrString.trim().length() == 0)
            msgArea.setText("Number of years missing");
        else {
            double bal = new Double(balString).doubleValue();
            double intyr = new Double(intString).doubleValue() / 100.;
            short nyears = (short) new Integer(nyrString).intValue();
StringBuffer msg = new StringBuffer();
            msg.append("\nprincipal=" + bal + "  interest=" + intyr
                     + "  years=" + nyears + "\n");
            double intmo = intyr / 12.;
            int npmts = nyears * 12;
            double pmt = bal * (intmo / (1.- Math.pow(1.+ intmo,-npmts)));
            msg.append("payment\ttotal\tinterest\tprincipal\tbalance\n");
            msg.append("number\tpayment\tpayment\tpayment\n");
            msg.append("\t\t\t\t" + bal + "\n");
for (short mo = 1; mo <= npmts; ++mo) {
                double prinpmt, intpmt = bal * intmo;
                if (mo < npmts)
                    prinpmt = pmt - intpmt;
                else prinpmt = bal;
                bal -= prinpmt;
                msg.append(mo + "\t" + format(intpmt + prinpmt)
                    + "\t" + format(intpmt)
                    + "\t" + format(prinpmt)
                    + "\t" + format(bal) + "\n");
            }
            msgArea.setText(msg.toString());
        }
    }
}


User is offlineProfile CardPM
+Quote Post

thenovices
RE: Trying To Figure This Out?!
1 Sep, 2008 - 12:47 PM
Post #2

D.I.C Head
**

Joined: 18 Jan, 2008
Posts: 73



Thanked: 7 times
My Contributions
it helps a lot if you could post the errors you're getting, and any steps you've taken to try to resolve them.
User is offlineProfile CardPM
+Quote Post

rettah1
RE: Trying To Figure This Out?!
1 Sep, 2008 - 01:08 PM
Post #3

New D.I.C Head
*

Joined: 25 Jul, 2008
Posts: 17


My Contributions
CODE
Here are the errors I have gotten and I keep on looking for the answers and I know I am not doing them right.

init:
deps-jar:
Compiling 1 source file to \build\classes
1.     Main.java:9: illegal start of type import java.applet.Applet;
2.     Main.java:9: ';' expected import java.applet.Applet;
3.     Main.java:9: illegal start of type import java.applet.Applet;
4.    Main.java:9: ';' expected import java.applet.Applet;
5.    Main.java:9: <identifier> expected import java.applet.Applet;
6.    Main.java:10: illegal start of type import java.awt.*;
7.    Main.java:10: ';' expected import java.awt.*;
8.    Main.java:10: illegal start of type import java.awt.*;
9.    Main.java:10: ';' expected import java.awt.*;
10.    Main.java:21: illegal character: \96         int dotpos = numString.indexOf(`.');
11.    Main.java:21: unclosed character literal   int dotpos = numString.indexOf(`.');
12.    Main.java:90: reached end of file while parsing
}
12 errors
BUILD FAILED (total time: 0 seconds)


Sorry I cut and pasted because my full name is on this. I have books but I have tried to put codes as asked and I am doing them wrong I am sure.

Thank you,
Rettah1


User is offlineProfile CardPM
+Quote Post

pbl
RE: Trying To Figure This Out?!
1 Sep, 2008 - 03:15 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
The import statements should follow the package statement they cannot be after any variable definition or class definition.

An inner class (like MortgageApp which is an inner class of Main) cannot have static method. You'll have to move your static method which does not access any member of MortgageApp into main.
User is offlineProfile CardPM
+Quote Post

Unknown Hero
RE: Trying To Figure This Out?!
1 Sep, 2008 - 06:32 PM
Post #5

New D.I.C Head
Group Icon

Joined: 4 Sep, 2007
Posts: 37



Thanked: 7 times
Dream Kudos: 50
My Contributions
1. Move your imports right under package declaration (before anything else).
2. Insert another } at the end of the class to complete class body.
3. Remove "static" from your method format()
4. Replace ` with '
5. Put some code in your main method in class Main. (This is where your program begins executing.)
6. If you need to access format() method in a static way, create a new class and cut-paste complete MortgageApp class there. Now you can have static methods.



Was this post helpfull? =>
User is offlineProfile CardPM
+Quote Post

rettah1
RE: Trying To Figure This Out?!
2 Sep, 2008 - 03:36 AM
Post #6

New D.I.C Head
*

Joined: 25 Jul, 2008
Posts: 17


My Contributions
QUOTE
After fooling around with this I came down to two errors last night. Error one I have put the '{' but it still wants the same, can't figure this out. #2 I am dummfounded about this one.

init:
deps-jar:
Compiling 1 source file to C:\Week2\build\classes
1. C:\week2\Main.java:9: '{' expected class Main week2 java.applet.Applet '{'
2. C:\week2\Main.java:93: reached end of file while parsing }//end of running


Thank you,
Loretta




User is offlineProfile CardPM
+Quote Post

pbl
RE: Trying To Figure This Out?!
2 Sep, 2008 - 04:21 PM
Post #7

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(rettah1 @ 2 Sep, 2008 - 04:36 AM) *

QUOTE
After fooling around with this I came down to two errors last night. Error one I have put the '{' but it still wants the same, can't figure this out. #2 I am dummfounded about this one.

init:
deps-jar:
Compiling 1 source file to C:\Week2\build\classes
1. C:\week2\Main.java:9: '{' expected class Main week2 java.applet.Applet '{'
2. C:\week2\Main.java:93: reached end of file while parsing }//end of running


Thank you,
Loretta




You'll have to re-post your corrected code
Obviously you have unBalanced {}
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:36AM

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