|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
Join Date: Nov 2003
Posts: 76
|
Ok Im suppose to write a "simple program" or my csci class showing flight departure and arrival time. I have typed in a few lines of code that my instructor showed us in class but Im still completely lost. It is suppose to look like one of these examples here.
Java Program Ive already done steps 1-3 its just step 4 the actual excercise Im having problems with. can someone please help? |
|
|
|
|
|
#2 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Are you having problems with the calculations or the print statements?
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Nov 2003
Posts: 76
|
both. this is what I have in notepad so far but I think most of it is wrong.
Code:
import TerminalIO.KeyboardReader;
public class cag02 {
public static void main (String [] args) {
Int beginHr
Int beginMin
Int endMin
Int totalMins
System.out.print ("Please provide four inputs about your flight: ") ;
fahrenheit = reader.readDouble () ;
System.out.print ("Enter departure hour: ") ;
beginltr=rdri readInt () ;
System.out.print ("Enter departure minute: ") ;
beginltr=rdri readInt () ;
System.out.print ("Enter arrival hour: ") ;
beginltr=rdri readInt () ;
System.out.print ("Enter arrival minute: ") ;
beginltr=rdri readInt () ;
reader.pause ();
}
}
|
|
|
|
|
|
#4 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
First off, you need to end all your variable initilization statements with a semicolan just like any other statement.
I'm not sure what your rdri statement is for. I haven't run across that before. There's something wrong with the import statement as well. Take a look here: http://www.javakb.com/Uwe/Forum.aspx...Compile-issues |
|
|
|
|
|
#5 |
|
Member (7 bit)
Join Date: Nov 2003
Posts: 76
|
Revision*
Code:
public class cag02 {
public static void main (String [] args) {
KeyBoardReader reader = new KeyBoardReader();
int beginHr;
int beginMin;
int endHr;
int endMin;
int totalMins;
System.out.println ("Please provide four inputs about your flight: ") ;
System.out.println ("Enter departure hour: ") ;
beginHr=reader.readInt() ;
System.out.println ("Enter departure minute: ") ;
beginMin=reader.readInt() ;
ln("Enter arrival hour: ") ;
endHr=reader.readInt() ;
System.out.println ("Enter arrival minute: ") ;
endHr=reader.readInt() ;
reader.pause ();
}
}
Last edited by rr spyda; 02-03-2005 at 06:36 PM. |
|
|
|
|
|
#6 |
|
Member (9 bit)
Join Date: Jan 2004
Location: Kansas City(westwood), KS
Posts: 458
|
I am unfamiliar with keyboard reader, i've only used buffer reader for text input. I know that with the buffere reader method you must add throws IO exception(i am not sure if i have the case right for that) after the public class statement. I am unsure if the Keyboard reader package needs this. Could you please tell us what kind of errors you get from your compiler? That should help us a little.
|
|
|
|
|
|
#7 |
|
Member (7 bit)
Join Date: Nov 2003
Posts: 76
|
*Revision
Code:
import TerminalIO.KeyboardReader;
public class cag02 {
public static void main (String [] args) {
int beginHr;
int beginMin;
int endHr;
int endMin;
int totalMins;
System.out.println ("Please provide four inputs about your flight: ") ;
System.out.println ("Enter departure hour: ") ;
beginHr=reader.readInt() ;
System.out.println ("Enter departure minute: ") ;
beginMin=reader.readInt() ;
System.out.println ("Enter arrival hour: ") ;
endHr=reader.readInt() ;
System.out.println ("Enter arrival minute: ") ;
endMin=reader.readInt() ;
System.out.println ("Your flight departs at: "+beginHr+":"+beginMin);
System.out.println ("Your flight arrives at: "+endHr+":"+endMin);
totalMins=endMin +beginMin;
System.out.println("flight time: "+totalMins);
}
}
Last edited by rr spyda; 02-03-2005 at 10:29 PM. |
|
|
|
|
|
#8 |
|
Member (7 bit)
Join Date: Nov 2003
Posts: 76
|
I got my program working, can someone just help me with the flight calculations now?
|
|
|
|
|
|
#9 |
|
Lest we forget
Join Date: Jun 2003
Location: Ontario, Canada
Posts: 1,870
|
you are just calculating the minutes, you also need the hours. Try this
Code:
totalMins=endMin -beginMin+(60*(endHr-beginHr));
__________________
redqueen: Antec Sonata, Pentium-D 2.5GHz, MSI G31M3-L, 2GB ram, 320 GB HDD, OpenBSD hal9000: Lenovo T61, 2GB ram, 120 GB HDD, FreeBSD |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|