[Assignment] Help with DATA INPUT

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 2
Reputation: nitric0 is an unknown quantity at this point 
Solved Threads: 0
nitric0 nitric0 is offline Offline
Newbie Poster

[Assignment] Help with DATA INPUT

 
0
  #1
Sep 20th, 2008
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:

  1. import java.util.Scanner;
  2.  
  3. public class AssignmentNo1
  4. {
  5. public static void main(String[] args)
  6. {
  7. int hours, minutes, seconds;
  8.  
  9. Scanner keyboard = new Scanner(System.in);
  10. System.out.println("Enter number of seconds : ");
  11. seconds = keyboard.nextInt();
  12.  
  13. hours = seconds/3600;
  14. minutes = seconds/60;
  15. seconds = seconds%3600;
  16.  
  17. System.out.println("Hours used:" + hours);
  18. System.out.println("Minutes used:" + minutes);
  19. System.out.println("Seconds used:" + seconds);
  20. }
  21. }

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
Last edited by nitric0; Sep 20th, 2008 at 11:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,836
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: [Assignment] Help with DATA INPUT

 
0
  #2
Sep 21st, 2008
Originally Posted by nitric0 View Post
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:

  1. import java.util.Scanner;
  2.  
  3. public class AssignmentNo1
  4. {
  5. public static void main(String[] args)
  6. {
  7. int hours, minutes, seconds;
  8.  
  9. Scanner keyboard = new Scanner(System.in);
  10. System.out.println("Enter number of seconds : ");
  11. seconds = keyboard.nextInt();
  12.  
  13. hours = seconds/3600;
  14. minutes = seconds/60;
  15. seconds = seconds%3600;
  16.  
  17. System.out.println("Hours used:" + hours);
  18. System.out.println("Minutes used:" + minutes);
  19. System.out.println("Seconds used:" + seconds);
  20. }
  21. }

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:
  1. seconds = seconds%3600;

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

  1. seconds = seconds % 60;

You are going to get in trouble here:
  1. 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC