Results 1 to 2 of 2
Thread: Help with Beginner exercise.
 07102008, 04:59 AM #1Member
 Join Date
 Jul 2008
 Posts
 1
 Rep Power
 0
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!
 07102008, 06:40 AM #2
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 25
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?
Java Code:double t = 114;
For the second part, what did you get. Is that you get the wrong value there.
Similar Threads

Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02152008, 07:11 PM 
Problems with Calendar exercise
By Jude in forum New To JavaReplies: 1Last Post: 11202007, 08:30 PM 
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10282007, 05:48 PM 
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09252007, 11:14 AM 
help with an exercise calcuting tax
By e_as're in forum New To JavaReplies: 7Last Post: 08012007, 04:17 AM
Bookmarks