Results 1 to 2 of 2
  1. #1
    Trunksten is offline Member
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    Default Help with Beginner exercise.

    Hi,

    I have taken a summer school java programming course and am stuck on a problem. These are my first attempts so please be patient. Here is the question i am stuck on:

    Find the net pay (n) for an employee who works 40 hours (h) at 5.50 per hour (w), has 3.00 (cpp) deducted for Canada Pension Plan and must pay 14% for tax (t). Tax is calculated on the gross pay after the insurance has been deducted. Display your answer in sentence form

    What i have so far is this:

    public class NetPay
    /*
    * Net Pay Program
    *This program shows the net pay for an employee after tax and Canada Pension Plan deduction.
    */
    {
    public static void main(String[] args)
    {
    // variable declaration
    int h;
    double n, w, cpp;
    // variable intialization
    h = 40;
    cpp = 3.0;
    w = 5.50
    // calculations
    n = ((h * w) - cpp) * t;
    // output
    System.out.println("Net Pay Program");
    System.out.println("The Net Pay is " + n);
    }
    }

    Now the trouble is, i don't know how to assign t at the top as it is not a variable?? how do you do this? t is a fixed percent?


    On a side note another one of my exercises were:
    1.
    Find the area of a 5.7 by 4.8 rectangle. Note: the mathematical formula for calculating the area of a rectangle is equal to length*width. Have your program display something similar to the following on the screen:
    The width is 4.2
    The length is 5.3
    Note: For this program use memory location variables w, l, and a to represent width, length, and area. (A good habit is to use memory location variable names that represent the data you are storing.)


    public class RectangleArea
    /*
    * Rectangle Area Program
    *This program shows the area of a rectangle with width w and length l
    */
    {
    public static void main(String[] args)
    {
    // variable declaration
    double l, w, a;
    // variable intialization
    l = 5.3;
    w = 4.2;
    // calculations
    a = l * w;
    // output
    System.out.println("Rectangle Area Program");
    System.out.println("The area is " + a);
    }
    }

    Is this right?

    Thanks for your help!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Now the trouble is, i don't know how to assign t at the top as it is not a variable?? how do you do this? t is a fixed percent?
    Simply assign the value as follows.

    Java Code:
    double t = 114;
    Because according to the way you calculated the net pay t should be 114.

    For the second part, what did you get. Is that you get the wrong value there.

Similar Threads

  1. Prob with an exercise
    By jhetfield18 in forum New To Java
    Replies: 4
    Last Post: 02-15-2008, 06:11 PM
  2. Problems with Calendar exercise
    By Jude in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 07:30 PM
  3. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 04:48 PM
  4. help with exercise
    By e_as're in forum New To Java
    Replies: 3
    Last Post: 09-25-2007, 10:14 AM
  5. help with an exercise calcuting tax
    By e_as're in forum New To Java
    Replies: 7
    Last Post: 08-01-2007, 03:17 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
  •