Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2008, 05:59 AM
Member
 
Join Date: Jul 2008
Posts: 1
Trunksten is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2008, 07:40 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
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.

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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prob with an exercise jhetfield18 New To Java 4 02-15-2008 08:11 PM
Problems with Calendar exercise Jude New To Java 1 11-20-2007 09:30 PM
I/O exercise Feldom New To Java 1 10-28-2007 06:48 PM
help with exercise e_as're New To Java 3 09-25-2007 12:14 PM
help with an exercise calcuting tax e_as're New To Java 7 08-01-2007 05:17 AM


All times are GMT +3. The time now is 12:43 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org