aspose file tools*
The moose likes Beginning Java and the fly likes Greenhorn porgrammer needs help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Greenhorn porgrammer needs help" Watch "Greenhorn porgrammer needs help" New topic
Author

Greenhorn porgrammer needs help

Patty Edens
Greenhorn

Joined: May 20, 2004
Posts: 6
I'm working on a mortgage calculator program for school. I cannot get the Event to work properly and exhausted myself trying to figure out what I'm doing wrong - which is probably something really stupid - cause I'm feeling really stupid right now. My code is below - can someone give me an idea of what (probably everything) I'm doing wrong. I was referred to a program in "Sams, Teach Yourself Java 2 in 24 hours that is pulling a Thread - I don't think I need a thread but now don't know how to get rid of it. My double.parseDouble is not working either. Any help would be appreciated.

The code:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class MortgageEvent extends JFrame implements ActionListener {

Pattys_Mortgage gui;
Thread calculating;

public MortgageEvent(Pattys_Mortgage in) {
gui = in;
}

void startCalculating() {
calculating = new Thread(this);
calculating.start();
gui.calculate.setEnabled(false);
gui.quit.setEnabled(true);
gui.reset.setEnabled(false);
}

void stopCalculating() {
gui.quit.setEnabled(false);
gui.calculate.setEnabled(true);
gui.reset.setEnabled(true);
calculating = null;
}

void clearAllFields() {
gui.mortgage.setText(null);
gui.term.setText(null);
gui.interest.setText(null);
}

public void actionPerformed(ActionEvent calculate) {
String command = calculate.getActionCommand();
if(command == "Calculate")
startCalculating();
if(command == "Quit")
stopCalculating();
if(command == "Reset")
clearAllFields();
//declare variables
double amount = Double.parseDouble(mortgage.getText());
double term = Double.parseDouble(term.getText());
double rate = Double.parseDouble(rate.getText());
double results = Double.parseDouble(results.getText());
double noOfPayments = Double.parseDouble(noOfPayments());
}

public static double results(double amount, double noOfPayments,
double rate) {
double payment = ((amount*rate)/12/
(1-(Math.pow((1+(rate/12)),(-1*noOfPayments)))));
return payment;
//double.parseDouble(results.getText());
}

static public double parseDouble(results.getText())
{
return doubleValueOf(results);
}
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if(command == "Calculate")

should be
if(command.equals("Calculate"))

same for the others
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
are these ever used?



I've heard it takes forever to grow a woman from the ground
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
Well, you need to start by getting syntactically correct Java. I'll focus on one area. You have code:


static public double parseDouble(results.getText())
{
    return doubleValueOf(results);
}


Now in other areas you've declared methods correctly, so I assume you're OK with that stuff. So, can you see a problem with the bit in bold above? When you're declaring a method, you need to tell it the type of the parameters. You need to change the part in bold, and then make a corresponding change in the method body.

OK, so regarding the bit in italics, where is this function "doubleValueOf" defined? I think you're intending to call the function 'valueOf' on class 'Double', in which case you want something like "Double.valueOf(myStringVariable)". But this returns a Double object, not a double basic type (yup, 'Double' and 'double' are different), so you probably really want "Double.valueOf(myStringVariable).doubleValue()".

These explanations are brief, but hopefully they're enough to get you going - otherwise write back



--Tim


(Edited to use [ quote ] rather than [ code ], so the bold and italic stuff shows up. Has the UBB code changed? Stuff looks different in FireFox!)
[ May 20, 2004: Message edited by: Tim West ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
[OFF-TOPIC]

(Edited to use [ quote ] rather than [ code ], so the bold and italic stuff shows up. Has the UBB code changed? Stuff looks different in FireFox!)

Many months ago, we changed the code tag to not use a reduced size font tag. That's all that I'm aware of.

[/OFF-TOPIC]

Welcome to JavaRanch, Patty!

What does, "I cannot get the Event to work properly," mean? I'd guess that Michael's suggestion above will clear this issue, but it's not clear from your question.

Also, you might want to simply remove that whole static public double parseDouble(results.getText()) section of code.
[ May 27, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Patty Edens
Greenhorn

Joined: May 20, 2004
Posts: 6
Sorry for the confusion - I can't get the MortgageEvent program to compile. I tired the recommended changes but the program is still not working.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11230
    
  16

Can you post the specific compiler error? if you're getting more than one, just try and fix the first one - often this will fix others as well.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Patty Edens
Greenhorn

Joined: May 20, 2004
Posts: 6
Hi, I got it to work Thanks everyone for the help!! I had an abstract error and then got a exception thrown - main message. I had the main class coded incorrectely.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Greenhorn porgrammer needs help