# Thread: Can't seem to grasp this

1. Member
Join Date
Oct 2009
Posts
20
Rep Power
0

## Can't seem to grasp this

Im new to Java, only having three sessions in my first class but I can't seem to wrap my head around these exercises.
Write a calss that declares a variable named minutes, which holds minutes worked on a job, and assign a value. Display the minutes in hours and minutes, for example. 3 hours and 27 minutes. Be sure to use a named constant where appropriate.
Part B.
Write an interactive version that accepts minutes worked from a user.

Problem 2:
Write a class that accepts a user's hourly rate of pay and number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay) and the net pay, (gross pay - withholding)

Can anyone gimme a hint or point me in the right direction please?

2. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
10
Start by reading the instructions sentence by sentence and acting on the command in each of the sentences.

3. Member
Join Date
Oct 2009
Posts
20
Rep Power
0
How would you give a variable minutes the value of 3 hours 15 minutes?

4. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
10
"variable named minutes, which holds minutes worked on a job"

You could just use an int (or long) for the minutes.
You then do the conversion to that String representation in a separate method using basic arithmetic.

5. Member
Join Date
Oct 2009
Posts
20
Rep Power
0
I think I see what you're saying...for example 120 minutes I could use the modulus or remainder operator to convert it to hours and minutes....I got ya

6. Member
Join Date
Oct 2009
Posts
20
Rep Power
0
As soon as you said arithmetic, it all clicked! Thank you very much.

//Import necessary packages
import java.util.Scanner;

public class Time2
{
public static void main(String [] args)
{

//Declare variables

int minutes;

//Create Scanner for input
Scanner inputDevice = new Scanner(System.in);

//Get user input
System.out.print("How many minutes were worked on the job?");
minutes = inputDevice.nextInt();

//Give output
System.out.println("Time spent on job is " + minutes/60 + " hours" + minutes%60 + " minutes");//Output given in Hour : Minute format.
}//End Main
}//End Class

7. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
10
There was a hint that you missed. "Be sure to use a named constant where appropriate".
A constant would be a value that does not change in the program. It's value will always be the same and it can be used on multiple locations. To declare a constant you use the modifiers
public static final
Do you spot which one should be a constant?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•