Java stand selector LEPA

Everything that has to do with the forum on a technical level. Logins, posts, formatting ...
oscar6662
Posts: 246
Joined: Thu Oct 22, 2015 4:49 pm

Java stand selector LEPA

Postby oscar6662 » Thu Sep 15, 2016 8:29 pm

Hello peypole I started learning java because programming is the future and I see a better one programmin than making 3d terminals with blender. ( I Wanna be an ATCO in Eurocontrol). So basicly what I made for the moment is a littlet beginner program that you put XXXYYY (XXX=AIRLINE YYY=ATYPE) and it basicly it gives you a random stand of the various stands thas airline can be. My second step is storing all the used stands in an array and then retruning and having a condition that the random factor will randomize but with mor variables.
Version.

Help is appreciated this is not easy at all.

BTW I will post the code when it stops telling me this stupid error thats is not true because in eclipse it works fine.
[url]Image[/url]

oscar6662
Posts: 246
Joined: Thu Oct 22, 2015 4:49 pm

Re: Java stand selector LEPA

Postby oscar6662 » Fri Sep 16, 2016 6:49 pm

Code: Select all

package little;
import java.util.Scanner;

public class Program {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      String youraircraft;
      
      Scanner OK = new Scanner(System.in);
      
      System.out.println("enter the aircraft type pelase");
      youraircraft=OK.nextLine();
      System.out.println("your slected aircraft is " + youraircraft);
      
      if(youraircraft.equals("BAW320")) {
         int m=8;int n=22;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);

      } else if(youraircraft.equals("GECX")){
         int m=306;int n=318;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("MON320")){
         int m=1;int n=6;int k=104; int f=109;
         int r=(int)((Math.random()*(n-m-k-f))+m+f);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("RYRUK738")){
         int m=100;int n=103;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("BER320")){
         int m=98;int n=60;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("TUI738")){
         int m=86;int n=80;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("NLY320")){
         int m=50;int n=44;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("VLG320")){
         int m=86;int n=98;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("EDW320")){
         int m=80;int n=84;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("AEA738")){
         int m=98;int n=90;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("BEEX")){
         int m=1;int n=12;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("GMI320")){
         int m=70;int n=66;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("GMI738")){
         int m=70;int n=66;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
   
      } else if(youraircraft.equals("CFG320")){
         int m=54;int n=50;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
   
      } else if(youraircraft.equals("CFG757")){
         int m=56;int n=58;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("AFRA320")){
         int m=38;int n=40;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("DLH320")){
         int m=40;int n=44;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("RYR738")){
         int m=158;int n=150;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("ANEX")){
         int m=153;int n=150;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
   
      } else if(youraircraft.equals("LZB320")){
         int m=108;int n=109;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("EWE320")){
         int m=68;int n=64;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("LZB320")){
         int m=108;int n=109;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("EZY320")){
         int m=108;int n=109;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("EZYUK320")){
         int m=154;int n=152;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("GWI320")){
         int m=80;int n=84;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
         
      } else if(youraircraft.equals("IBE320")){
         int m=82;int n=86;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
      } else if(youraircraft.equals("KLM738")){
         int m=82;int n=86;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);   
         
         
      } else{
         System.out.println("ashole");
               
         
      }
   }

}


...

Copright Oscar Berneguer
[url]Image[/url]

oscar6662
Posts: 246
Joined: Thu Oct 22, 2015 4:49 pm

Re: Java stand selector LEPA

Postby oscar6662 » Fri Sep 16, 2016 7:13 pm

LAST modification contains random number but only even (must of stands are only even)

Code: Select all

} else if(youraircraft.equals("TUI738")){
         Random rand = new Random();
         int randomNum = 16+rand.nextInt(56/16) *2;
         System.out.println(randomNum);
[url]Image[/url]

User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Java stand selector LEPA

Postby jwocky » Fri Sep 16, 2016 7:19 pm

Try to think about how you can keep aircraft names and stands dynamic
Free speech can never be achieved by dictatorial measures!

oscar6662
Posts: 246
Joined: Thu Oct 22, 2015 4:49 pm

Re: Java stand selector LEPA

Postby oscar6662 » Fri Sep 16, 2016 7:22 pm

Dynamic, what do you mean?
[url]Image[/url]

User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Java stand selector LEPA

Postby jwocky » Fri Sep 16, 2016 7:27 pm

You ask always for a hard coded aircraft like "TUI738"
That is a a 737-800 belonging to TUI

Now, if you split the string you got from the keyboard (look up String.substring()), into two parts, the airline and the aircraft, you can compare in a loop against an array of strings.

Code: Select all

for (int i=0; i<numberofairlines; i++) {
   if (airline.equals(airlines[i]) {
      ... next step would be look up the stands for this airline only ...
   }
}


That means, whenever you get a new airline on your airport, you only need to add this airline to a list of airlines, not add another hundred ifs.
Free speech can never be achieved by dictatorial measures!

oscar6662
Posts: 246
Joined: Thu Oct 22, 2015 4:49 pm

Re: Java stand selector LEPA

Postby oscar6662 » Fri Sep 16, 2016 7:43 pm

yeah then there isnt any way for each arline a specific group of stands, the only advantage is that you can put all the arlines toghtether that have same stands.
Am I wrong?
[url]Image[/url]

OPFOR77
Posts: 208
Joined: Wed Apr 27, 2016 7:30 pm

Re: Java stand selector LEPA

Postby OPFOR77 » Fri Sep 16, 2016 7:47 pm

Take it a step further and use a multidimensional array, so all the data is stored together and only one loop is needed. So (not a java programmer)

Code: Select all

for (int i=0; i<numberofairlines; i++) {
   if (airline.equals(airlines[i][0]) {
         int m=airlines[i][1];int n=airlines[i][2];
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
   }
}


So all you'd have to do is setup an array like:

array[x][0] = "airline"
array[x][1] = starting_gate
array[x][2] = ending_gate

You could possibly make it even faster using a map/dictionary. Not a java guy, so YMMV.
OPRF Fighter Jock and Dev

User avatar
IAHM-COL
Posts: 6452
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: Java stand selector LEPA

Postby IAHM-COL » Fri Sep 16, 2016 7:49 pm

You don't need to nest conditional with else-if statements,
It is actually less computer intensive if you use simpler conditionals; and reserve nested elseifs for those cases that you really need to (as in the first conditional must be false, in order to evaluate a second one)

So, basically, to begin with, (still not most optimized, since you could probably create a function that applies to your class, to manage that amount of returns), again, to begin with, I recommend you go the simple if way, like this:

Code: Select all

package little;
import java.util.Scanner;

public class Program {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      String youraircraft;
     
      Scanner OK = new Scanner(System.in);
     
      System.out.println("enter the aircraft type please");
      youraircraft=OK.nextLine();
      System.out.println("your slected aircraft is " + youraircraft);
     
      if(youraircraft.equals("BAW320")) {
         int m=8;int n=22;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
   }
   
      if(youraircraft.equals("GECX")){
         int m=306;int n=318;
         int r=(int)((Math.random()*(n-m))+m);
         System.out.println("Go to stand " +r);
      }
         
      if(youraircraft.equals("MON320")){
         int m=1;int n=6;int k=104; int f=109;
         int r=(int)((Math.random()*(n-m-k-f))+m+f);
         System.out.println("Go to stand " +r);
      }

   }

}
https://raw.githubusercontent.com/IAHM-COL/gpg-pubkey/master/pubkey.asc

R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it?

User avatar
jwocky
Site Admin
Posts: 1833
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Java stand selector LEPA

Postby jwocky » Fri Sep 16, 2016 7:52 pm

Lets go there step by step

OPFOR is right, you use a multidimensional array later to get all the stands per airline
but before you can do that, bring the 1 dimensional to run with all the airlines, then, when you did that, expand your program the way OPFOR suggested and you have already a pretty flexible solution. But please, for learning purposes, lets go step by step.
Free speech can never be achieved by dictatorial measures!


Return to “Technical Questions”

Who is online

Users browsing this forum: No registered users and 1 guest