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,ActionListene r
{
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(Thurs dayMortgag eWeek3GUI in)
{
gui=in;
}
public static void main(String [] args)
{
}
//
public void itemStateChanged(ItemEvent arg0) {
Object button = gui.options.getSelectedIte m();
String buttonPress = button.toString();
Object source = arg0.getSource();
if (buttonPress == gui.calButton.getActionCom mand()) {
startCalculations();
}
if (buttonPress == gui.resetButton.getActionC ommand()) {
reset();
}
if (buttonPress == gui.endButton.getActionCom mand()) {
end();
}
}
public void actionPerformed(ActionEven t 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(loanFie ld.getText ());
} catch (NumberFormatException e) {
clearResults();
gui.textField.append("Plea se Do Not Use Commas.Invalid Entry");
loanField.setText(null);
}
termArray[0]=Double.parseD ouble(txtY ears);
intrstArray[0]=Double.pars eDouble(tx tIntRate);
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.setMaximumFractionDigi ts(2);
fmt.setMinimumFractionDigi ts(2);
String txtInitialAmount = gui.txtAmount.getText();
gui.options.setEnabled(tru e);
gui.calButton.setEnabled(t rue);
double newPrin = amount;
double newIn = moIn * newPrin;
double reduction = payment - newIn;
newPrin = newPrin - reduction;
for (int i = 0; i < options[Array]; i++) {
options.addItem(optionsArr ay[i]);
}
}
while (c<=options[Array]);
int index = options.getSelectedIndex() ;
term = termArray[index];
intrst = intrstArray[index];
if (amount > 0) {
amount = Double.parseDouble(loanFie ld.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("Principl e"+"\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.showMessageDia log(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);
}
}
import java.awt.event.*;
import java.text.*;
import java.lang.*;
import java.io.*;
import java.awt.*;
public class ThursdaySupportWeek3 implements ItemListener,ActionListene
{
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(Thurs
{
gui=in;
}
public static void main(String [] args)
{
}
//
public void itemStateChanged(ItemEvent
Object button = gui.options.getSelectedIte
String buttonPress = button.toString();
Object source = arg0.getSource();
if (buttonPress == gui.calButton.getActionCom
startCalculations();
}
if (buttonPress == gui.resetButton.getActionC
reset();
}
if (buttonPress == gui.endButton.getActionCom
end();
}
}
public void actionPerformed(ActionEven
{
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(loanFie
} catch (NumberFormatException e) {
clearResults();
gui.textField.append("Plea
loanField.setText(null);
}
termArray[0]=Double.parseD
intrstArray[0]=Double.pars
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.setMaximumFractionDigi
fmt.setMinimumFractionDigi
String txtInitialAmount = gui.txtAmount.getText();
gui.options.setEnabled(tru
gui.calButton.setEnabled(t
double newPrin = amount;
double newIn = moIn * newPrin;
double reduction = payment - newIn;
newPrin = newPrin - reduction;
for (int i = 0; i < options[Array]; i++) {
options.addItem(optionsArr
}
}
while (c<=options[Array]);
int index = options.getSelectedIndex()
term = termArray[index];
intrst = intrstArray[index];
if (amount > 0) {
amount = Double.parseDouble(loanFie
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#
textField.append(" ");
textField.append("Amount"+
textField.append(" ");
textField.append("Interest
textField.append(" ");
textField.append("Principl
textField.append(" ");
textField.append("Balance"
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.showMessageDia
"Message Dialog", JOptionPane.PLAIN_MESSAGE)
loanField.setText(null);
}
}
void reset() {
loanField.setText(null);
paymtField.setText(null);
}
void end() {
System.exit(0);
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
public void actionPerformed(ActionEven
{
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(loanFie
} catch (NumberFormatException e) {
clearResults();
gui.textField.append("Plea
loanField.setText(null);
}
termArray[0]=Double.parseD
intrstArray[0]=Double.pars
array=0;
clearResults();
funcCalculate();
setNull();
}