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.
Write an interactive version that accepts minutes worked from a user.
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?
Start by reading the instructions sentence by sentence and acting on the command in each of the sentences.
How would you give a variable minutes the value of 3 hours 15 minutes?
"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.
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
As soon as you said arithmetic, it all clicked! Thank you very much.
//Import necessary packages
public class Time2
public static void main(String  args)
//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();
System.out.println("Time spent on job is " + minutes/60 + " hours" + minutes%60 + " minutes");//Output given in Hour : Minute format.
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?