# Can't seem to grasp this

• 11-10-2009, 07:07 AM
Boomer1
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?
• 11-10-2009, 07:48 AM
r035198x
Start by reading the instructions sentence by sentence and acting on the command in each of the sentences.
• 11-10-2009, 07:51 AM
Boomer1
How would you give a variable minutes the value of 3 hours 15 minutes?
• 11-10-2009, 08:19 AM
r035198x
"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.
• 11-10-2009, 08:22 AM
Boomer1
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
• 11-10-2009, 08:53 AM
Boomer1
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
• 11-10-2009, 09:47 AM
r035198x
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?