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 3234424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:23:23+00:00 2026-05-17T17:23:23+00:00

I’m new to Java. I’m taking an online class this semester. The book which

  • 0

I’m new to Java. I’m taking an online class this semester. The book which we are using isn’t the greatest. I’ve tried searching around for answers online, but I’m coming up short. Maybe one of you guys can help me out 🙂

Basically the program below is suppose to prompt the user to enter info, the program then calculates the deductions and outputs the info to a .txt file. It runs and complies without error. The dialog boxes pop up, but no data is being written to the file. The .txt file is saved in the same folder btw. Any ideas?

import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;

public class PaycheckCalculator
{

    static final double FEDERAL_TAX = .15, STATE_TAX = .035, SOCIAL_SECURITY = .0575, MEDICARE_MEDICAID = .0275,PENSION = .05;
    static final int HEALTH_INSURANCE = 75;

    public static void main (String[] args) throws FileNotFoundException
    {

        String employeeName;
        String inputStr;

        double grossPay, netPay, federal, state, social, medicare, pension;
        int healthInsurance;

        PrintWriter outFile = new PrintWriter ("paycalc.txt");


        employeeName = JOptionPane.showInputDialog ("Please enter your name: ");

        inputStr = JOptionPane.showInputDialog ("Please enter your monthly gross pay: ");
        grossPay = Double.parseDouble (inputStr);

        federal = (grossPay * FEDERAL_TAX);
        state = (grossPay * STATE_TAX);
        social = (grossPay * SOCIAL_SECURITY);
        medicare = (grossPay * MEDICARE_MEDICAID);
        pension = (grossPay * PENSION);


        netPay = (grossPay - federal - state - social - medicare - pension - HEALTH_INSURANCE);

        outFile.println (employeeName);
        outFile.printf ("Gross Amount: %.2f%n", grossPay);
        outFile.printf ("Federal Tax: %.2f%n", federal);
        outFile.printf ("State Tax: %.2f%n", state);
        outFile.printf ("Social Security Tax: %.2f%n", social);
        outFile.printf ("Medicare\\Medicaid Tax: %.2f%n", medicare);
        outFile.printf ("Pension Plan: %.2f%n", pension);
        outFile.printf ("Health Insurance: $" + HEALTH_INSURANCE);
        outFile.printf ("Net Pay: %.2f%n", netPay);


        System.exit(0);
        outFile.close();

    }
}
  • 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-17T17:23:24+00:00Added an answer on May 17, 2026 at 5:23 pm

    You have to close your PrintWriter before your application exits.

    You can either remove the System.exit(0); line (which is useless) or put it after the close() operation.

    This way the data will be flushed into your paycalc.txt file before the application exits.

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

Sidebar

Related Questions

No related questions found

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.