wood burning stoves*
The moose likes Beginning Java and the fly likes don't know how to call method in my new version of code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "don Watch "don New topic
Author

don't know how to call method in my new version of code

Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Thanks for saying i could come back.
I better tell you the requirments then you can stop me
before i waste another week of lack of sleep.
I have to use a menu of some sort for following 4 commands
--------------------------------------------------------------
Start:
to enter current airport by name and resets journey time to zero
info:
to display current journey time so far, name of airport and
flight numbers.
fly:
ask for a fight number, if number is that of the plane flying
from current airport.It then checks where the plane is fying to and
makes that the current airport and adds the journey time to the flight
time. But if no plane matches number entered display a error message
but make no other changes.

Exit: Stops and exits program
---------------------------------------------------------------
That is the requirements above, as you can see i have done
Start: and info.
Info meets the requirements but i think it is silly they don't ask
for destination to be displayed with flight number.
Also the way i search for planes is that the right way
info[0],info[1],info[2] as suggested by teacher. As if you look at my
earlier code I got all the same information but using [i] only
We can use any array

Here is the code so far


Is my code right upto know, not asking any one to do my work
but i don't know where to start on a method to make the destination
airport current. also is it a seperate method for updating the flight time.
If it is I will try to have a go of that one myself, if not i am up a
creek with out a paddle .
Sorry if this post was long, but I wanted you to have
all the facts what i am suppose to do
Thanks
Lindsey
[ February 13, 2003: Message edited by: Marilyn de Queiroz ]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

I am still of the opinion that this

will not work as "length" will return 44 instead of 11, which is what you need.


Please ignore post, I have no idea what I am talking about.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

You don't make an instance of AoWings2.
I think it would be easyer to understand if you made AoWing2 without a "main". Instead have a public "run" method. A default constructor would be good also.
Than have another class called "TestAoWing2" which would do something like this:
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
thanks you guys,
but you have lost me, i am a total new comer to java, will have to go back to reading books before i can even understand your answers.
i know you mean well and trying to get me started
on the right track. But i guess i am not up to it
at this moment in time,
so it back to books for me.
take care all of you
Lindsey
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

One thing I can suggest is to break down the problem into smaller problems and write pseudo-code. For example:
loop
Display menu and read in a command
if command is 'start'
initialize
if command is 'info'
info
if command is 'fly'
fly
if command is 'exit'
exit loop
end loop

initialize:
... spell out what should be done here, breaking down some more if necessary

info:
...

fly:
...

Try implementing the loop pseudo-code first so you have a place to start. Then you can tackle each smaller task one by one "fill out" your program.
Since you are still trying to grasp the basic concepts, I wouldn't worry too much about being object oriented just yet.
----
(Edit) :roll: OK, I see you've already coded the menu loop. That's a good start. Now, instead of having real code in each case, make them call other methods.
e.g.

[ February 13, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Thanks again Junilar
I will attempt what you said
Lindsey
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

To expand on my post about "length". To loop though your data you want to say something like:

If instead you use "length" you can get values as large as 44 which will cause an out of bounds exception.
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Well you guys,
you can have some peace , I give up I can't expect you to take me by the hand.
But the more changes i make the more errors I get with trying to asign method to case i don't know if i am coming or going.
I know you are right in what you say but i have not got the brains to impelement it. I am digging
my self deeper and deeper in trouble.
Also i understand what you say about max(length)
but not allowed a fixed array.
I will leave you know to help people who know what their doing
take care it was fun while it lasted
Lindsey
xxxx
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Lindsey,
I'm sorry to hear you say that. I do sincerely think that if you try a little longer, you will start to see the light at the end of the tunnel (and it won't be the oncoming train either ).
I think your main problem is that you're letting yourself become overwhelmed by the whole problem. Like I said before, the best way to tackle this would be to break things down into smaller and more manageable pieces -- take baby steps. You already had the menu piece down and that was a big small step, if you know what I mean.
Anyway, if you decide to pick up on this again, we'll be more than willing to help you out.
Good luck.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

NO! We were so close.
But ya, what Junilu said, you needed to write smaller pieces of code than put them together once they were working.
Good luck.
Lindsey Ship
Greenhorn

Joined: Feb 07, 2003
Posts: 19
Hi sorry i took my time to come back after you
said it was okay.
Have gone back to step 1,
I have do my case menu in a loop as you said.
If i press 1 it ask for current airport
I type in Liverpool
I expect it to come back:
Liverpool Airport Total Flight Time 0
but where do i put current_airport = readLine in start Method
tried loads of ways or Am I going about It the Wrong way.
I will not finnish this assignment in time now as I have only
2 days to go till Monday. But I would like to learn at less to call
in methods case1 and case2.So at less i would have some understanding
for myself.
[code]
import java.io.*;
class AA
{

static String fni[][] = { {"Paris" , "418", "Rome" , "55"},
{"Liverpool" , "121", "Copenhagen", "35"},
{"Liverpool" , "418", "Paris" , "50"},
{"Liverpool" , "553", "Frankfurt" , "55"},
{"Frankfurt" , "553", "Budapest" , "50"},
{"Amsterdam" , "121", "Madrid" , "65"},
{"Amsterdam" , "418", "Paris" , "35"},
{"Madrid" , "121", "Stockholm" , "90"},
{"Budapest" , "553", "Warsaw" , "30"},
{"Copenhagen", "121", "Amsterdam" , "35"},
{"Rome" , "418", "Amsterdam" , "60"} };


public static void main (String [] args) throws IOException
{
String destination="";
String current_airport = "";
int choice;
int FlightTime = 0;

do
{
choice = menu();
switch (choice)
{

case 1: current_airport = start();break;
case 2: break;
case 3: break;
case 4: break;
default:System.out.println("You entered an invalid number");
}

}
while (choice >0 && choice < 5);

}

static int menu()throws IOException
{
System.out.println("=============================================");
System.out.println(" No Wings Airline");
System.out.println("=============================================");
System.out.println(" ");
System.out.println(" 1. Start" );
System.out.println(" 2. Info" );
System.out.println(" 3. Fly" );
System.out.println(" 4. Exit" );
System.out.println(" ");
System.out.print("Please select one of the options: ");


String line;
int choice;
BufferedReader input = new BufferedReader( new InputStreamReader(System.in));
line = input.readLine();
choice = Integer.parseInt( line );
return choice;
}
static String start()throws IOException
{
int FlightTime = 0;
System.out.print("Please enter the Current Airport: ");
String line;
BufferedReader input = new BufferedReader( new InputStreamReader(System.in));
line = input.readLine();
return line;
}
// current_airport = readLine
// System.out.print(current_airport+ "Airport" + FlightTime);
}

[\code]
thanks
if you can get me stared
Lindsey
Ps Sorry if I should have started a new thread but i was hoping
you guys were still watching for me to come back
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: don't know how to call method in my new version of code
 
Similar Threads
where is my silly mistake
Java Webservice problem (Array)
I'm lost on how to do and call 3d array
which of these 2 arrays is right
where am i calling method in wrong ??