| | |
[Assignment] Help with DATA INPUT
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
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:
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
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:
Java Syntax (Toggle Plain Text)
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
Last edited by nitric0; Sep 20th, 2008 at 11:43 pm.
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
•
•
•
•
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:
Java Syntax (Toggle Plain Text)
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:
Java Syntax (Toggle Plain Text)
seconds = seconds%3600;
is going to give you a result from 0 to 3599, which you don't want, so do this:
Java Syntax (Toggle Plain Text)
seconds = seconds % 60;
You are going to get in trouble here:
Java Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Passing data from forms from one page to another (JavaScript / DHTML / AJAX)
- Send data on a serial port (C++)
- Getting all data from an input and output file (C++)
- handeling wrong input from user (C++)
- Lines are being skipped in the input file. (Visual Basic 4 / 5 / 6)
- transfer input.txt to output.txt help prz (C++)
- Question:: reading from an input stream. (C++)
- Multiple data being read in (C++)
Other Threads in the Java Forum
- Previous Thread: Java Paint
- Next Thread: Help with my main method
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component csv database desktop draw ebook eclipse equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions reporting rotatetext scanner screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






