?
Solved

methods

Posted on 2006-05-25
3
Medium Priority
?
234 Views
Last Modified: 2013-11-23
I am still working on the below program that calls another program. The other program runs fine and i run into a compile issue with actionPerformed section below. it says it is missing symbols, but they are declared in that section. AM i missing something or have the order of this program wrong???




import java.awt.event.*;
import java.text.*;
import java.lang.*;
import java.io.*;
import java.awt.*;


public class ThursdaySupportWeek3 implements ItemListener,ActionListener
{

ThursdayMortgageWeek3GUI gui;
double amount = 0;
double term = 0;
double intrst = 0;
double moIn = 0;
double moTrm = 0;
double prin = 0;
double payment = 0;
double termArray[] = { 7, 15, 30 };
double intrstArray[] = { 5.35, 5.50, 5.75 };

//to format payment amounts
DecimalFormat df = new DecimalFormat("$#,###.00");

public ThursdaySupportWeek3(ThursdayMortgageWeek3GUI  in)
{
gui=in;
}
public static void main(String []  args)
{
}
//

public void itemStateChanged(ItemEvent arg0) {

Object button = gui.options.getSelectedItem();
String buttonPress = button.toString();

Object source = arg0.getSource();

if (buttonPress == gui.calButton.getActionCommand()) {
startCalculations();

}
if (buttonPress == gui.resetButton.getActionCommand()) {
reset();

}
if (buttonPress == gui.endButton.getActionCommand()) {
end();

}
}

public void actionPerformed(ActionEvent event)
{
      String buttonClicked = event.getActionCommand();
      if (buttonClicked == "Select Option")
            setNull();
      if (buttonClicked == "Select Option" && !gui.options.isSelected())
            clearResults();
            
      if (buttonClicked =="Calculate" && gui.options.isSelected())
            {
            try
            {
            amount = Double.parseDouble(loanField.getText());
                  } catch (NumberFormatException e) {
                  clearResults();
                  gui.textField.append("Please Do Not Use Commas.Invalid Entry");
                  loanField.setText(null);

}

termArray[0]=Double.parseDouble(txtYears);
intrstArray[0]=Double.parseDouble(txtIntRate);
array=0;
clearResults();
funcCalculate();
setNull();
}

if (buttonClicked =="Calculate")
{
      clearResults();
      funcCalculate();
      }
if (buttonClicked == "Clear")
      setNull();
if (buttonClicked =="Exit")
      System.exit(0);
}
      
void startCalculations() {

do
{
            NumberFormat fmt = NumberFormat.getInstance();
            fmt.setGroupingUsed (true);
            fmt.setMaximumFractionDigits(2);
            fmt.setMinimumFractionDigits(2);
            String txtInitialAmount = gui.txtAmount.getText();
            gui.options.setEnabled(true);
            gui.calButton.setEnabled(true);

double newPrin = amount;
double newIn = moIn * newPrin;
double reduction = payment - newIn;
newPrin = newPrin - reduction;


for (int i = 0; i < options[Array]; i++) {
options.addItem(optionsArray[i]);
}
}
while (c<=options[Array]);

int index = options.getSelectedIndex();
term = termArray[index];
intrst = intrstArray[index];

if (amount > 0) {
amount = Double.parseDouble(loanField.getText());
moIn = (intrst / 12) / 100;
moTrm = term * 12;
payment = amount * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

paymtField.setText("" + df.format(payment));

textField.append("Payment#"+"\t");
textField.append(" ");
textField.append("Amount"+"\t");
textField.append(" ");
textField.append("Interest"+ "\t");
textField.append(" ");
textField.append("Principle"+"\t");
textField.append(" ");
textField.append("Balance"+"\t");
textField.append(" \n");



for (int i = 1; i <= moTrm; i++) {


textField.append(" " + + i);
textField.append(" " + "\t"+ df.format(payment));
textField.append(" " +"\t"+ df.format(newIn));
textField.append(" " + "\t"+ df.format(reduct));
textField.append(" " +"\t"+ df.format(newPrin) + "\n");

}

}
if (amount < 0) {
JOptionPane.showMessageDialog(null, "Please Enter Valid Amount",
"Message Dialog", JOptionPane.PLAIN_MESSAGE);
loanField.setText(null);
}
}

void reset() {

loanField.setText(null);
paymtField.setText(null);

}

void end() {
System.exit(0);
}
}

0
Comment
Question by:pgmtkl
3 Comments
 
LVL 2

Assisted Solution

by:appxpete
appxpete earned 1000 total points
ID: 16764250
The following objects are referenced by actionPerformed() but are not defined in your code.

setNull()
clearResults()
loanField
txtYears
txtIntRate
array
funcCalculate()
0
 

Author Comment

by:pgmtkl
ID: 16764814
Is the below section defining them? I thought that was doing so.  If not where do i need to put them??  


public void actionPerformed(ActionEvent event)
{
     String buttonClicked = event.getActionCommand();
     if (buttonClicked == "Select Option")
          setNull();
     if (buttonClicked == "Select Option" && !gui.options.isSelected())
          clearResults();
         
     if (buttonClicked =="Calculate" && gui.options.isSelected())
          {
          try
          {
          amount = Double.parseDouble(loanField.getText());
               } catch (NumberFormatException e) {
               clearResults();
               gui.textField.append("Please Do Not Use Commas.Invalid Entry");
               loanField.setText(null);

}

termArray[0]=Double.parseDouble(txtYears);
intrstArray[0]=Double.parseDouble(txtIntRate);
array=0;
clearResults();
funcCalculate();
setNull();
}
0
 
LVL 6

Accepted Solution

by:
phuocnh earned 1000 total points
ID: 16765606
To access loanField,txtYears,txtIntRate you must use gui  object because they are belong to it
gui.loanField
gui.txtYears
gui.txtIntRate
You must implement the folowing method:
setNull();
clearResults();
funcCalculate();
take example:
public void setNull(){
//Your code here.
}
I think you are C programmer. You use its syntax for Java many times.
Note that array<>Array.
Phuoc H. Nguyen
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question