new to Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: new to Java

  1. #1
    Join Date
    Oct 2006
    Location
    ohio/ Long Beach, CA
    Posts
    9

    Smile 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 .

  2. #2
    Join Date
    Dec 2005
    Posts
    97
    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.

  3. #3
    Join Date
    Nov 2006
    Posts
    9
    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!

  4. #4
    Join Date
    Oct 2006
    Location
    ohio/ Long Beach, CA
    Posts
    9
    Quote Originally Posted by Lord Squallop
    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();
    }
    }

  5. #5
    Join Date
    May 2005
    Location
    Ontario, Canada
    Posts
    173
    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();
    }
    }

  6. #6
    Join Date
    Feb 2007
    Posts
    1

    hey

    Hi Sjalle,
    Came across your Forum while browsing around…cool stuff u have going on here. Also I thought I’d tell u about something I came across, thought u might find it useful, bcoz ur in IT…it’s this site called Myndnet…u should check it out..the link is here http://www.myndnet.com/login.jsp?ref...a83&channel=79

    It’s this cool place where u get paid for responding to queries…very cool stuff!! http://www.myndnet.com/login.jsp?ref...a83&channel=79
    Sign up n lemme know what u think…my mail id is barot.alpa@gmail.com

    Cheers
    Alpa

  7. #7
    Join Date
    Oct 2006
    Location
    ohio/ Long Beach, CA
    Posts
    9
    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 .

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center