The Artima Developer Community
Sponsored Link

Java Answers Forum
cannot resolve symbol problem

2 replies on 1 page. Most recent reply: Feb 9, 2004 5:59 AM by twc

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
bernadette

Posts: 5
Nickname: sash6
Registered: Feb, 2004

cannot resolve symbol problem Posted: Feb 8, 2004 5:03 AM
Reply to this message Reply
Advertisement
I keep getting a "cannot resolve symbol" error message for this line of code:
if (maritalStatus==s)
Here is the program. I'm trying to allow a user to enter income and S or M for their marital status. Based upon this, I have to calculate the tax return.

I'm also not sure how to error check to be sure the user enters only an S or M.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Tax extends JApplet implements ActionListener
{

double tax;
char maritalStatus;


JLabel title = new JLabel("Tax Calculator");
JLabel incomePrompt = new JLabel("Enter Income:");
JLabel statusPrompt = new JLabel("Enter S for Single, M for Married:");

JTextField incomeInput = new JTextField(10);
JTextField statusInput = new JTextField(1);


JButton computeButton = new JButton("Compute");

JLabel incomeLabel = new JLabel(" ", SwingConstants.CENTER);
JLabel statusLabel = new JLabel(" ", SwingConstants.CENTER);
JLabel taxRateLabel = new JLabel(" ", SwingConstants.CENTER);
JLabel taxAmountLabel = new JLabel(" ", SwingConstants.CENTER);

TaxReturn calc = new TaxReturn();


public void init()
{
Container con = getContentPane();
con.setLayout(null);

title.setBounds(5, 5, 300, 25);
title.setForeground(Color.blue);
incomePrompt.setBounds(5, 30, 200, 25);
incomeInput.setBounds(200, 30, 50, 25);
statusPrompt.setBounds(5, 55, 200, 25);
statusInput.setBounds(200, 55, 50, 25);
computeButton.setBounds(100, 80, 100, 25);
incomeLabel.setBounds(5, 105, 300, 25);
statusLabel.setBounds(5, 130, 300, 25);
taxRateLabel.setBounds(5, 155, 300, 25);
taxAmountLabel.setBounds(5, 180, 300, 25);




con.add(title);
con.add(incomePrompt);
con.add(incomeInput);
con.add(statusPrompt);
con.add(statusInput);
con.add(computeButton);
con.add(incomeLabel);
con.add(statusLabel);
con.add(taxRateLabel);
con.add(taxAmountLabel);
computeButton.addActionListener(this);
}


public void actionPerformed(ActionEvent e)
{

double income = Double.parseDouble(incomeInput.getText());



calc.setIncome(income);
calc.setMaritalStatus(maritalStatus);


incomeLabel.setText("Income is " + income);
statusLabel.setText("Marital Status is " + maritalStatus);




taxAmountLabel.setText("Tax Amount is $" + tax);
}

}


class TaxReturn
{

public double income;
public char maritalStatus;
public double tax;




public void setIncome(double i)
{
income = i;
}


public double getIncome()
{
return income;
}


public void setMaritalStatus(char status)
{
maritalStatus = status;
}


public char getMaritalStatus()
{
return maritalStatus;
}

public double computeTax()
{
if (maritalStatus==s)
{
if (income <= 10000)
tax = income * 0.15;

else if (income > 10000)
tax = income * 0.30;
}

else
{
if (income <= 20000)
tax = income * 0.15;

else if (income > 20000)
tax = income * 0.30;
}
return tax;
}
}


bernadette

Posts: 5
Nickname: sash6
Registered: Feb, 2004

Re: cannot resolve symbol problem Posted: Feb 8, 2004 6:04 AM
Reply to this message Reply
I just worked on this and changed it a bit. Now I need the following help. I can't get the right marital status to print. I also am not sure how to put in error checking to make sure only positive numbers are entered for the income, and only 'm' or 's' is entered for the marital status.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Tax extends JApplet implements ActionListener
{

double tax;
double income;
char maritalStatus;



JLabel title = new JLabel("Tax Calculator");
JLabel incomePrompt = new JLabel("Enter Income:");
JLabel statusPrompt = new JLabel("Enter S for Single, M for Married:");

JTextField incomeInput = new JTextField(10);
JTextField statusInput = new JTextField(1);


JButton computeButton = new JButton("Compute");

JLabel incomeLabel = new JLabel(" ", SwingConstants.CENTER);
JLabel statusLabel = new JLabel(" ", SwingConstants.CENTER);
JLabel taxAmountLabel = new JLabel(" ", SwingConstants.CENTER);

TaxReturn calc = new TaxReturn();


public void init()
{

Container con = getContentPane();
con.setLayout(null);

title.setBounds(5, 5, 300, 25);
title.setForeground(Color.blue);
incomePrompt.setBounds(5, 30, 200, 25);
incomeInput.setBounds(200, 30, 50, 25);
statusPrompt.setBounds(5, 55, 200, 25);
statusInput.setBounds(200, 55, 50, 25);
computeButton.setBounds(100, 80, 100, 25);
incomeLabel.setBounds(5, 105, 300, 25);
statusLabel.setBounds(5, 130, 300, 25);
taxAmountLabel.setBounds(5, 155, 300, 25);





con.add(title);
con.add(incomePrompt);
con.add(incomeInput);
con.add(statusPrompt);
con.add(statusInput);
con.add(computeButton);
con.add(incomeLabel);
con.add(statusLabel);
con.add(taxAmountLabel);
computeButton.addActionListener(this);
}


public void actionPerformed(ActionEvent e)
{

double income = Double.parseDouble(incomeInput.getText());



calc.setIncome(income);
calc.setMaritalStatus(maritalStatus);
double tax = calc.computeTax();


incomeLabel.setText("Income is $" + income);

if(maritalStatus == 's')
{
statusLabel.setText("Marital Status is Single");
}
else
{
statusLabel.setText("Marital Status is Married");
}



//

taxAmountLabel.setText("Tax Amount is $" + tax);
}

}


class TaxReturn
{

public double income;
public char maritalStatus;
public double tax;




public void setIncome(double i)
{
income = i;
}


public double getIncome()
{
return income;
}


public void setMaritalStatus(char status)
{
maritalStatus = status;
}


public char getMaritalStatus()
{
return maritalStatus;
}

public double computeTax()
{
if (maritalStatus=='s')
{
if (income <= 10000)
tax = income * 0.15;

else if (income > 10000)
tax = income * 0.30;
}

else
{
if (income <= 20000)
tax = income * 0.15;

else if (income > 20000)
tax = income * 0.30;
}
return tax;
}
}

twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: cannot resolve symbol problem Posted: Feb 9, 2004 5:59 AM
Reply to this message Reply
You may need to repaint components (like Label's) if the contents change.

The actionPerformed method would probably be the logical place to error checking code.

Are you doing this for a class?

Flat View: This topic has 2 replies on 1 page
Topic: Waiting Dialog Previous Topic   Next Topic Topic: Polymorphism Question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use