Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

new to Java

Hi My name is Michelle, I need help with the following program:

Iam to write a program that calculates and prints the monthly paycheck for an employee. The net pay is to be calculated after taking the following deductions,

federal income tax 15%
state tax 3.5 %
social security tax 5.75%
medicare/medicaid tax 2.75%
pension plan 5%
health insurance $75.00

the program need to prompt the user to input the employee name and the gross amount.The output should be stored in a file. The output also needs to be formatted using 2 decimal places.

T=hanks for any help .
[619 byte] By [obie] at [2007-11-11 10:25:02]
# 1 Re: new to Java
ok, well have you attempted to write this program at all? if you have post your code otherwise, i would take a look at the Scanner, File, and the BufferedWriter classes. im not sure about the formatting though.
anubis at 2007-11-11 22:31:34 >
# 2 Re: new to Java
For the formatting, you could use the NumberFormat (java.text.NumberFormat) class. It's fairly straightforward to use. Check out the getCurrencyInstance and format methods. http://java.sun.com/javase/6/docs/api/
Good luck!
Lord Squallop at 2007-11-11 22:32:30 >
# 3 Re: new to Java
For the formatting, you could use the NumberFormat (java.text.NumberFormat) class. It's fairly straightforward to use. Check out the getCurrencyInstance and format methods. http://java.sun.com/javase/6/docs/api/
Good luck!

okay now it wont print out any **** output, the enter name works then i enter gross amount then, theres no display of deductions......

import java.io.*;
import java.util.*;

public class Ch3_PrExercise6
{
static Scanner console = new Scanner(System.in);

static final double FEDERAL_TAX_RATE = 0.15;
static final double STATE_TAX_RATE = 0.035;
static final double SOCIAL_SECURITY_TAX_RATE = 0.0575;
static final double MEDICARE_MEDICATE_TAX_RATE = 0.0275;
static final double PENSION_PLAN_RATE = 0.05;
static final double HEALTH_INSURANECE = 75.00;

public static void main (String[] args) throws IOException
{
String name;

double grossAmount;
double federalTax;
double stateTax;
double socialSecurityTax;
double medicareMedicaidTax;
double pensionContribution;
double netPay;

PrintWriter outFile = new
PrintWriter(new FileWriter("c:\\.txt"));

System.out.print("Enter employee name: ");
System.out.flush();
name = console.nextLine();
System.out.println();

System.out.println(name);

System.out.print("Enter gross amount: ");
System.out.flush();
grossAmount = console.nextDouble();
System.out.println();

federalTax = grossAmount * FEDERAL_TAX_RATE;
stateTax = grossAmount * STATE_TAX_RATE;
socialSecurityTax = grossAmount * SOCIAL_SECURITY_TAX_RATE;
medicareMedicaidTax = grossAmount * MEDICARE_MEDICATE_TAX_RATE;
pensionContribution = grossAmount * PENSION_PLAN_RATE;
netPay = grossAmount - federalTax - stateTax
- socialSecurityTax - medicareMedicaidTax
- pensionContribution - HEALTH_INSURANECE;

outFile.println(name);
outFile.printf("Gross Amount: $%8.2f %n", grossAmount);
outFile.printf("Federal Tax: $%8.2f %n", federalTax);
outFile.printf("State Tax: $%8.2f %n", stateTax);
outFile.printf("Social Security Tax: $%8.2f %n", socialSecurityTax);
outFile.printf("Medicare/Medicaid Tax: $%8.2f %n", medicareMedicaidTax);
outFile.printf("Pension Plan: $%8.2f %n", pensionContribution);
outFile.printf("Health Insurance: $%8.2f %n", HEALTH_INSURANECE);
outFile.printf("Net Pay: $%8.2f %n", netPay);

outFile.close();
}
}
obie at 2007-11-11 22:33:39 >
# 4 Re: new to Java
Try this one.
What is the diference?
Hope it helps.

/**
* Write a description of class aaaaaaaaa here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.io.*;
import java.util.*;

public class Ch3_PrExercise6
{
static Scanner console = new Scanner(System.in);

static final double FEDERAL_TAX_RATE = 0.15;
static final double STATE_TAX_RATE = 0.035;
static final double SOCIAL_SECURITY_TAX_RATE = 0.0575;
static final double MEDICARE_MEDICATE_TAX_RATE = 0.0275;
static final double PENSION_PLAN_RATE = 0.05;
static final double HEALTH_INSURANECE = 75.00;

public static void main (String[] args) throws IOException
{
String name;

double grossAmount;
double federalTax;
double stateTax;
double socialSecurityTax;
double medicareMedicaidTax;
double pensionContribution;
double netPay;

PrintWriter outFile = new
PrintWriter(new FileWriter("c:\\.txt"));

System.out.print("Enter employee name: ");
System.out.flush();
name = console.nextLine();
System.out.println("*****************");

System.out.println(name);
System.out.println("*****************");

System.out.print("Enter gross amount: ");
System.out.flush();
grossAmount = console.nextDouble();
System.out.println();

System.out.println("*****************");

System.out.println(grossAmount);
System.out.println("*****************");

federalTax = grossAmount * FEDERAL_TAX_RATE;
stateTax = grossAmount * STATE_TAX_RATE;
socialSecurityTax = grossAmount * SOCIAL_SECURITY_TAX_RATE;
medicareMedicaidTax = grossAmount * MEDICARE_MEDICATE_TAX_RATE;
pensionContribution = grossAmount * PENSION_PLAN_RATE;
netPay = grossAmount - federalTax - stateTax
- socialSecurityTax - medicareMedicaidTax
- pensionContribution - HEALTH_INSURANECE;

outFile.println(name);
outFile.printf("Gross Amount: $%8.2f %n", grossAmount);
outFile.printf("Federal Tax: $%8.2f %n", federalTax);
outFile.printf("State Tax: $%8.2f %n", stateTax);
outFile.printf("Social Security Tax: $%8.2f %n", socialSecurityTax);
outFile.printf("Medicare/Medicaid Tax: $%8.2f %n", medicareMedicaidTax);
outFile.printf("Pension Plan: $%8.2f %n", pensionContribution);
outFile.printf("Health Insurance: $%8.2f %n", HEALTH_INSURANECE);
outFile.printf("Net Pay: $%8.2f %n", netPay);

outFile.close();
}
}
Kinda Electroni at 2007-11-11 22:34:39 >
# 5 Re: new to Java
Hi Sjalle,
Came across your Forum while browsing aroundcool stuff u have going on here. Also I thought Id tell u about something I came across, thought u might find it useful, bcoz ur in ITits this site called Myndnetu should check it out..the link is here http://www.myndnet.com/login.jsp?referral=alpa83&channel=79

Its this cool place where u get paid for responding to queriesvery cool stuff!! http://www.myndnet.com/login.jsp?referral=alpa83&channel=79
Sign up n lemme know what u thinkmy mail id is barot.alpa@gmail.com

Cheers :)
Alpa
alpa at 2007-11-11 22:35:32 >
# 6 Re: new to Java
well thanks anyway , i have a great several assignments due and really no time to do them, if anyone would like to help out email me at my private address mcontres84@yahoo.com. I can mail them to you .
obie at 2007-11-11 22:36:36 >