Link to home
Start Free TrialLog in
Avatar of pgmtkl
pgmtkl

asked on

methods

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);
}
}

SOLUTION
Avatar of appxpete
appxpete

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pgmtkl
pgmtkl

ASKER

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();
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial