Re: Java stand selector LEPA
Posted: Fri Sep 16, 2016 7:59 pm
yes. OPORF77 is the correct approach.
An independent forum for FlightGear users and developers
https://thejabberwocky.net/
Code: Select all
public class cacatua {
public static void main(String[] args) {
// TODO Auto-generated method stub
String youraircraft = "TUI738 BAW320 IBE320";
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(youraircraft.substring(1, 7))) {
int m=8;int n=22;
int r=(int)((Math.random()*(n-m))+m);
System.out.println("Go to stand " +r);
Code: Select all
String airline=youraircraft.substring(0,3);
Code: Select all
String aircrafttype=youraircraft.substring(3);
Code: Select all
for (int i=0; i<numberofairlines; i++) {
if (aircraft_airlines.equals(airlines[i,0])) {
// ... we search the stand in the next step, for now we just tell, we found the airline
System.out,println("Airline "+aircraft_airline+" found");
}
}
"number of airlines" that is suposed to be an INT so I basicly did this:
int numberofairlines = As many as I wrote;
then with numberofairlines I supose I need to create an Array that will make 1-DLH, 2-BAW...
BUT where is the 320?
Why making a "for loop" for a stand chooser (I want one stand not a loop of stands?)
Also why comparing 0<with a number
Code: Select all
for (int i=0; i<numberofairlines; i++) {
And then why do you want to exponentially increment the number that its not even going to make sense because airline and stand!!!
Code: Select all
package little;
import java.util.Random;
import java.util.Scanner;
public class Program {
// catalog with airlines and stands
public static HashMap<String, int[]> catalog = new HashMap<String, int[]>();
public static void addAirline (String airline, int... arrayOfGateRanges) {
catalog.put(airline, arrayOfGateRanges);
/* what
*/
}
public static int[] getGates (String airline) {
return catalog.get(airline);
}
public static void initialize () {
addAirline ("BAW", 8, 22, 32, 48); // -> catalog.put("BAW", { 8, 22, 32, 48 });
addAirline ("GECX", 306, 318);
addAirline ("MON", 2, 6);
addAirline ("RYRUK", 100, 103);
// ...
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// initialize catalog with airlines and stands
initialize ();
String airline;
Scanner OK = new Scanner(System.in);
System.out.println("enter the airline type pelase");
airline=OK.nextLine();
System.out.println("your selected airline is " + airline);
// get stands for airline from the catalog (or null)
int [] stands = getGates (airline);
if (stands != null) { // "!=" ???
// stands = { 8, 22, 32, 48} or = { 306, 318 } or ...
int sum = 0;
// stands.length = 4 or = 2 or ...
for (int i=0; i<stands.length; i+=2) {
int firstGate = stands[i];
int lastGate = stands[i+1];
sum = sum + (lastGate-firstGate);
}
Random rand = new Random();
//int randomNum = rand.nextInt(((lastGate-firstGate)+(lastehemGate-firstehemGate))/2) *2;
int randomNum = rand.nextInt(sum / 2 + 1) *2;
// done
for (int i=0; i<stands.length; i+=2) {
int firstGate = stands[i];
int lastGate = stands[i+1];
if (firstGate + randomNum <= lastGate) {
randomNum = firstGate + randomNum;
break; // exit the for-loop because the matching range is found
} else {
randomNum = randomNum - (lastGate-firstGate);
}
}
System.out.println("Go to stand " + randomNum);
} else{
System.out.println("no, no, no!");
}
}
}