Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    /* Title:		Java Programming Assignment 3a
       Programer:	Teel Hughes
       Start Date:	11/22/13
       File Name:	TeelsApplet1.java
       Purpose:		Programe is to calculate the total property tax paid.
     
     */
     
     import java.applet.*;
     import java.awt.*;
     import java.awt.event.*;
     
     public class TeelsApplet1 extends Applet implements ActionListener
    {
     		// declare variables
     		int taxpmt1, taxpmt2;
     		int result = taxpmt1 + taxpmt2;
     
     
     
     		//construct components
     		Label companyLabel = new Label("TOTAL PROPERTY TAX ");
     		Label taxpmt1Label = new Label("Enter your tax payment for December. Do not include decimal point or dollar sign.:");
     			TextField taxpmt1Field = new TextField(10);
     		Label taxpmt2Label = new Label("Enter your tax payment for April. Do not include decimal point or dollar sign.: ");
     			TextField taxpmt2Field = new TextField(10);
     		Button calcButton = new Button("Calculate");
     		Label outputLabel = new Label("Click the Calculate button to see your total property tax paid.");
     
     		public void init()
     		{
    			setForeground(Color.blue);
    			add(companyLabel);
    			add(taxpmt1Label);
    			add(taxpmt1Field);
    			add(taxpmt2Label);
    			add(taxpmt2Field);
    			add(calcButton);
    			calcButton.addActionListener(this);
    			add(outputLabel);
     
    		}
     
    		public void actionPerformed(ActionEvent e)
    		{
     
    			taxpmt1 = Integer.parseInt(taxpmt1Field.getText());
    			taxpmt2 = Integer.parseInt(taxpmt2Field.getText());
     
     
    			outputLabel.setText("YOUR TOTAL TAX PAID IS" + result );
    		}
    }
    Last edited by Norm; December 1st, 2013 at 07:25 PM. Reason: Added []s to code tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    Where does the code add together the user's input?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    Isn't that addressed under declare variables?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    that addressed under declare variables?
    I'm not sure I understand what that means. What is the "that" you are talking about?
    Can you post the line(s) of code where the input is obtained from the user and added together and then displayed?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    int result = taxpmt1 + taxpmt2;

    This line is under //declare variables (the line above is what I meant by that, sorry, will try to be more explicit)

    and outputLabel.setText("YOUR TOTAL TAX PAID IS" + result ); is the last line.

    I just fixed it!! I added the line "result = taxpmt1 + taxpmt2;" under the line (Action event e)

    Thanks for making me think!!

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: applet works, no errors. Addition of taxpmt1 and taxpmt2 returns a 0. Please what am i doing wrong?

    Glad you got it working.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    TeelH (December 1st, 2013)

Similar Threads

  1. Replies: 9
    Last Post: September 15th, 2013, 02:48 PM
  2. Replies: 2
    Last Post: September 2nd, 2012, 02:06 PM
  3. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  4. LDAP Sort 2 attributes returns NO results. Works fine if sorted on one.
    By funnyguy in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 30th, 2011, 01:31 AM
  5. getTimeInMillis() from the Calendar class returns wrong values
    By 16mydream in forum Java Theory & Questions
    Replies: 2
    Last Post: February 16th, 2011, 01:29 PM