Is this program working? Please help.

Hello everybody :-)

If you have a free minute, could you please check and see if this program works? This supposed to be a tax calculator and it runs as a desktop application, not an applet.

This is really important for me.

I am looking forward for your feedback. If there is an error please post the error message.

I appreciate all your help and thanks in advance.

The program consists of 2 classes:

StateTaxComputationTeamB.java This file carries main() method

And

StateTaxComputationUITeamB.java - this files carries user interface and makes the calculation.

Thanks.

/**

*Week 2 TEAM B Programming Exercise

*Filename: StateTaxComputationTeamB.java

*Purpose: Calculate States Tax

*

*@author TEAM B

*@since June 04 2007

*

*/

import javax.swing.*;

publicclass StateTaxComputationTeamB{

publicstaticvoid main(String [] args){

// Create User Inteface Object

StateTaxComputationUITeamB UI =new StateTaxComputationUITeamB("State Tax Calculator", 275, 210,false);

// Setup default behaviour when user closes the application

UI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Show user interface frame

UI.show();

}

}

// END of file StateTaxComputationTeamB.java

/**

*Week 2 TEAM B Programming Exercise

*Filename: StateTaxComputationUITeamB.java

*Purpose: This class creates Tax Calculator User Interface and Calculates the tax

*

*@author TEAM B

*@since June 04 2007

*

*/

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

import java.util.*;

import java.text.*;

publicclass StateTaxComputationUITeamBextends JFrameimplements ActionListener{

privatestaticfinaldouble INDEX = 0.03;

privatestaticfinalint MIN_INCOME = 600;

private JLabel resultLabel =new JLabel();

private JButton computeBtn =new JButton("Compute");

private JTextField incomeTxt =new JTextField(10);

private JTextField dependentTxt =new JTextField(10);

/**

* Default constructor

*/

public StateTaxComputationUITeamB(String title,int width,int height,boolean isResizable){

// Set frame size

setTitle(title);

setSize(width, height);

// Is frame resizable?

this.setResizable(isResizable);

Container cont = getContentPane();

GridLayout layout =new GridLayout(0,1);

cont.setLayout(layout);

// Create elements, set up layouts and add to the main frame

// Header message label

JPanel headerPanel =new JPanel(new FlowLayout());

JLabel headerLabel =new JLabel("State Tax Computation Program");

headerPanel.add(headerLabel, BorderLayout.CENTER);

// Income text field and label.

SpringLayout incomeLayout =new SpringLayout();

JPanel incomePanel =new JPanel(incomeLayout);

JLabel incomeLabel =new JLabel("Income: ");

incomePanel.add(incomeLabel);

incomePanel.add(incomeTxt);

incomeLayout.putConstraint(SpringLayout.WEST, incomeLabel, 95, SpringLayout.WEST, incomePanel);

incomeLayout.putConstraint(SpringLayout.NORTH, incomeLabel, 5, SpringLayout.NORTH, incomePanel);

incomeLayout.putConstraint(SpringLayout.WEST, incomeTxt, 5, SpringLayout.EAST, incomeLabel);

incomeLayout.putConstraint(SpringLayout.NORTH, incomeTxt, 5, SpringLayout.NORTH, incomePanel);

// Number of Dependents text field and label

SpringLayout dependentLayout =new SpringLayout();

JPanel dependentPanel =new JPanel(dependentLayout);

JLabel dependentLabel =new JLabel("Number of Dependents: ");

dependentPanel.add(dependentLabel);

dependentPanel.add(dependentTxt);

dependentLayout.putConstraint(SpringLayout.WEST, dependentLabel, 8, SpringLayout.WEST, dependentPanel);

dependentLayout.putConstraint(SpringLayout.NORTH, dependentLabel, 5, SpringLayout.NORTH, dependentPanel);

dependentLayout.putConstraint(SpringLayout.WEST, dependentTxt, 5, SpringLayout.EAST, dependentLabel);

dependentLayout.putConstraint(SpringLayout.NORTH, dependentTxt, 5, SpringLayout.NORTH, dependentPanel);

// Compute button

SpringLayout buttonLayout =new SpringLayout();

JPanel buttonPanel =new JPanel(buttonLayout);

computeBtn.addActionListener(this);

buttonPanel.add(computeBtn);

buttonLayout.putConstraint(SpringLayout.WEST, computeBtn, 177, SpringLayout.WEST, buttonPanel);

buttonLayout.putConstraint(SpringLayout.NORTH, computeBtn, 5, SpringLayout.NORTH, buttonPanel);

// Result label

JPanel resultPanel =new JPanel();

resultPanel.add(resultLabel);

// Add all components to the main container

cont.add(headerPanel);

cont.add(new JSeparator(JSeparator.HORIZONTAL));

cont.add(incomePanel);

cont.add(dependentPanel);

cont.add(buttonPanel);

cont.add(resultPanel);

}

/**

* Calculate result. Incldes error checking.

*

* @return void

*/

private String computeResult(){

double income;

long numDependents;

String msg;

Locale locale = Locale.US;

// Catch number format exceptions.

try{

income = Double.parseDouble(incomeTxt.getText());

}

catch(NumberFormatException e){

msg ="ERROR: Please correct value of Income.";

return msg;

}

try{

numDependents = Integer.parseInt(dependentTxt.getText());

}

catch(NumberFormatException e){

msg ="ERROR: Please correct value of Dependents";

return msg;

}

// Income cant't be negative

if(income < 0){

msg ="ERROR: Please correct value of Income.";

return msg;

}

// Number of Dependents can't be negative

elseif(numDependents < 0){

msg ="ERROR: Please correct value of Dependents.";

return msg;

}

// Income must be greater then Number of Dependents * Minimum Income

elseif(income < (MIN_INCOME * numDependents)){

msg ="State Tax is " + NumberFormat.getCurrencyInstance(locale).format(0);

return msg;

}

// If we are here then calculate the tax, format it as US currency and return the string.

msg ="State Tax is " + NumberFormat.getCurrencyInstance(locale).format(INDEX * (income - (MIN_INCOME * numDependents)));

return msg;

}

/**

* Implements actionPerformed method of ActionListener interface

*

* @param ActionEvent e

* @return void

*/

publicvoid actionPerformed(ActionEvent e){

resultLabel.setText(computeResult());

}

}

//END of file StateTaxComputationUITeamB.java

[10945 byte] By [ArthurJina] at [2007-11-27 11:05:52]
# 1

This is not a service where we run your programs and tell you if there are errors. That's not the way it works around here. We are volunteers who all work other jobs and help people with specific problems with their code. If you want help from us, your job is to make our job as easy as possible. That means that it is your responsibility to find errors and ask specific questions not ours. Otherwise you are being very disrespectful of us and our time, and I for one resent this.

petes1234a at 2007-7-29 13:11:34 > top of Java-index,Java Essentials,New To Java...
# 2

Thank for your reply.

I understand that you guys busy. And I am sorry to disturb you.

But if it was not so important for me I would not post it here.

I am learning Java, and thought that this forum called "New to Java" would be perfect for this. I guess I made a mistake.

All I needed is to check if this program works, cause it works on 5 computers, but it does not run on the one that is most important :(

In any case, if this is wrong place to post this I am really sorry. Please remove this thread.

ArthurJina at 2007-7-29 13:11:34 > top of Java-index,Java Essentials,New To Java...
# 3

> All I needed is to check if this program works,

> cause it works on 5 computers, but it does not run

> on the one that is most important :(

Why did you leave that information out of your original post? We can't read minds you know. Is java even loaded on that other computer?

My take on all of this is, if your program works on 5 computers but not on one, then the program is probably ok. The computer that it didn't run on is not however. You need to check that computer to see why the java code is not running.

Message was edited by:

petes1234

petes1234a at 2007-7-29 13:11:34 > top of Java-index,Java Essentials,New To Java...
# 4

Thank you for your help.

I agree, you are absolutely right, the only way of solving this is personally running it on that machine. I am sure that my online Java instructor has the latest JVM, but I do not have access to it.

In any case, I really appreciate your help and sorry for any confusion. I did not mean to disturb any one. If this post is annoying please remove it.

Thanks.

ArthurJina at 2007-7-29 13:11:34 > top of Java-index,Java Essentials,New To Java...