hey guys new here and i'm also new to JAVA. i'm taking a class and am kind of stumped in my first assignment

i basically have to write a program that will give the total due a user using an internet cafe.

each full hour = $5.00
each m inute not part of a full hour = $0.10
each second not part of a full minute = $0.01

so far my code looks like:

import java.util.Scanner;

public class AssignmentNo1
{
	public static void main(String[] args)
	{
		int hours, minutes, seconds;
	  
	   Scanner keyboard = new Scanner(System.in);
		System.out.println("Enter number of seconds : ");
	   seconds = keyboard.nextInt();
	
		hours = seconds/3600;
		minutes = seconds/60;
	   seconds = seconds%3600;
					
		System.out.println("Hours used:" + hours);
		System.out.println("Minutes used:" + minutes);
	   System.out.println("Seconds used:" + seconds);
	}
}

I have the program running but when I insert a value, it gives me how many seconds in that hour, how many seconds in that minute and h ow many seconds in that second. i need it to be left over, not new each time.

for example this is what i have NOW:
Enter number of seconds : *enter*230
hours used: 0
minutes used: 3
seconds used: 230

i want it to do THIS:

Hours used: 0
minutes used: 3
seconds used: 50


can anyone help? THANKS A LOT

hey guys new here and i'm also new to JAVA. i'm taking a class and am kind of stumped in my first assignment

i basically have to write a program that will give the total due a user using an internet cafe.

each full hour = $5.00
each m inute not part of a full hour = $0.10
each second not part of a full minute = $0.01

so far my code looks like:

import java.util.Scanner;

public class AssignmentNo1
{
	public static void main(String[] args)
	{
		int hours, minutes, seconds;
	  
	   Scanner keyboard = new Scanner(System.in);
		System.out.println("Enter number of seconds : ");
	   seconds = keyboard.nextInt();
	
		hours = seconds/3600;
		minutes = seconds/60;
	   seconds = seconds%3600;
					
		System.out.println("Hours used:" + hours);
		System.out.println("Minutes used:" + minutes);
	   System.out.println("Seconds used:" + seconds);
	}
}

I have the program running but when I insert a value, it gives me how many seconds in that hour, how many seconds in that minute and h ow many seconds in that second. i need it to be left over, not new each time.

for example this is what i have NOW:
Enter number of seconds : *enter*230
hours used: 0
minutes used: 3
seconds used: 230

i want it to do THIS:

Hours used: 0
minutes used: 3
seconds used: 50


can anyone help? THANKS A LOT

If seconds should always be less than 60 , then you need an operation that guarantees that your result will be less than 60. This:

seconds = seconds%3600;

is going to give you a result from 0 to 3599, which you don't want, so do this:

seconds = seconds % 60;

You are going to get in trouble here:

minutes = seconds/60;

if you have more than 3600 seconds of time, because minutes have to be less than 60 eventually too, right? Hint: Do another mod operation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.