Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6787863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:25:00+00:00 2026-05-26T17:25:00+00:00

This program allows a user to calculate to enter sales and calculate sales taxes

  • 0

This program allows a user to calculate to enter sales and calculate sales taxes per state.
The program is giving errors when it gets to reading the double word states (eg New Jersey).I need helo with part.

    import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.nio.CharBuffer;
import java.awt.*;
//import java.awt.event.*;
import javax.lang.model.type.ArrayType;
import javax.swing.*;
import javax.swing.event.*;
public class PJ5 extends JFrame implements ListSelectionListener
{String []States = new String[100];
    double []statetax = new double[100];
double sales;
JPanel p1;
JList  StateList;



JTextField salesField;
private JTextField taxField;
public static void main(String []args)    
  {
  PJ5  x = new PJ5();
  x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  x.setTitle("Sales tax calculator");
  x.setSize(350, 250);
  x.setVisible(true);

  } // main

public PJ5() // constructor
{
String s;
StringTokenizer st;
int k=0;
try 
{
BufferedReader inFile = new BufferedReader(new FileReader("C:\\Users\\Owner\\Documents\\taxrates.txt"));
    while ((s= inFile.readLine()) != null)
    {


st = new StringTokenizer(s);
        States[k]=(st.nextToken());

    statetax[k] = Double.valueOf(st.nextToken());

    ++k;
    } // while not EOF
  inFile.close();
} catch (Exception e) { System.err.println(e); }



JPanel p1 =new JPanel();

 p1.setLayout(new GridLayout(2,1));

p1.add(new JLabel("Sales amount:"));
salesField= new JTextField(5);
salesField.setEditable(true);
p1.add(salesField);


p1.add(new JLabel("tax:"));
taxField= new JTextField(4);
taxField.setEditable(false);
p1.add(taxField);


add(p1,BorderLayout.NORTH);
pack();
setVisible(true);

JPanel p = new JPanel();
StateList = new JList(States);  // create a JList object
StateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
JScrollPane sp = new JScrollPane(StateList);  // adding scrolling capability
p.add(sp);
getContentPane().add(p, BorderLayout.SOUTH);
// Event registration
StateList.addListSelectionListener(this);
} // constructor

// Event handling
public void valueChanged(ListSelectionEvent event)
     {
    DecimalFormat dollar = new DecimalFormat("0.00");   
    double tax;
     sales=Double.parseDouble(salesField.getText());

tax=sales* (statetax[StateList.getSelectedIndex()]/100);
     taxField.setText("$"+dollar.format(tax));

     } // valueChanged
}

here is the text file with the states en their tax rates.

Alabama 4.0
Alaska 0.
Arizona 5.6
Arkansas 6.0
California 8.25
Colorado 2.9
Connecticut 6.0
Delaware  2.07
Florida 6.0
Georgia 4.0
Hawaii 4.0
Idaho 6.0
Illinois 6.25
Indiana 7.0
Iowa    6.0
Kansas  5.3
Kentucky    6.0
Louisian,   4.0
Maine   5.0
Maryland    6.0
Massachusetts   6.25
Michigan    6.0
Minnesota   6.875
Mississippi 7.0
Missouri    4.225
Montana 0.
Nebraska    5.5
Nevada  6.85
New Hampshire 0.0
New Jersey  7.0
New Mexico  5.375
New York    4.0
North Carolina  4.5
North Dakota    5.0
Ohio    5.5
Oklahoma    4.5
Oregon  0.
Pennsylvania    6.0
Rhode Island    7.0
South Carolina  6.0
South Dakota    4.0
Tennessee   7.0
Texas   6.25
Utah    5.95
Vermont     6.0
Virginia    5.0
West Virginia   6.0
Wisconsin   5.0
Washington  6.5
Washington DC   5.75
Wyoming 4.0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:25:01+00:00Added an answer on May 26, 2026 at 5:25 pm

    Its because, the tokenizer parses New as a string then the next code parses Hampshire as a double, you may need to restructure your code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently my program allows the user to enter 5 integers which are used to
I am making a program that allows user to custom keyboard shortcuts, for this
Bassicly im creating a program that allows the user to enter values and if
I have a C++ program that allows a user to single step through processor
Backgorund I am currently writing a program that allows a user to select a
I have created the output for a program that allows a user to input
I have a program that allows a user to type java code into a
I am creating a program that allows the user to select a drive letter
I'm writing a program that allows a user to perform arithmetic operations with big
My program allows the user to specify a file which is read as input,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.