Is there a way to subtract string input?
I have to input time of login and log out, then subtract the 2. to get total amount used.
just testing i tried this but gave me the error can't do it, so was thinking there might beanother way.
any help would be appreciated greatly
-dale
(example: book gives ann.easyio, so replace with your keyboard input and would be good)
import ann.easyio.*;
class Main extends Object
{
static Keyboard myKeyboard = new Keyboard();
public static void main(String args[])
{
String time_start,
time_end;
int time_work;
System.out.println("Please enter the login time: ");
time_start = myKeyboard.readWord();
System.out.println("Please enter the logout time: ");
time_end = myKeyboard.readWord();
time_work = time_end - time_start;
}//////////////
}//END OF class
Andrew Thompson - 03 May 2004 16:25 GMT
> Is there a way to subtract string input?
>
> I have to input time of login and log out, then
> subtract the 2. to get total amount used.
> just testing i tried this but gave me the error can't do it,
Is that a CannotDoItException?
<http://www.physci.org/codes/javafaq.jsp#exact>
>...so was thinking there might beanother way.
> any help would be appreciated greatly
....
> (example: book gives ann.easyio, so replace
> with your keyboard input and would be good)
Think about this.
The change takes two(?) minutes.
It would take you two minutes to change it,
whereas it would take three people helping
you 6 minutes (in total) to change it.
Is your time three times as valuable as
those helping you? Because that is what
your comment seems to imply.
Also, you have failed to specify in what
form the time is input. Is it a long?
A fully formatted date? What?
I suggest you redo your example and hard
code the two times. (This example does
_not_ require I/O!)
For tips on preparing an example for others, check..
<http://www.physci.org/codes/sscce.jsp>

Signature
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Roedy Green - 03 May 2004 22:22 GMT
>I have to input time of login and log out, then subtract the 2. to get total amount used.
>just testing i tried this but gave me the error can't do it, so was thinking there might beanother way.
>any help would be appreciated greatly
you must convert to a timestamp. See SimpleDateFormat, then subtract
to get the time in millis.
See http://mindprod.com/jgloss/Calendar.html
You were expecting Java to be at least 100 times smarter than it is.
How was it to know your string contained a date? How was it to know
the format? How was it to know what language you were using and which
calendar. How was it to know what unit you wanted for the difference.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Chris Smith - 04 May 2004 20:12 GMT
> System.out.println("Please enter the login time: ");
> time_start = myKeyboard.readWord();
> System.out.println("Please enter the logout time: ");
> time_end = myKeyboard.readWord();
> time_work = time_end - time_start;
What are you expecting as input? You treat times as integers in a few
places; is that what you want? Or do want actual times?
For the former, see java.lang.Integer.parseInt. For the latter, see
java.text.SimpleDateFormat.

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Roedy Green - 04 May 2004 20:46 GMT
>What are you expecting as input? You treat times as integers in a few
>places; is that what you want? Or do want actual times?
give an example of what you want to type in. e.g.
5000
14:20
2004-05-04 14:20:40
Depending on why you expect, you will need quite different code
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.