|
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!
|