Posted by: SAJHACOP July 18, 2008
Login in to Rate this Post:
0
?
Score, if you can not translate above code in Java, you are wasting your time on Java for sure. I don't even know Java and here is my take.
I might be wrong though, but it compiles.
package ticket;
import java.io.IOException;
import java.util.Scanner;
import java.util.Arrays;
public class BP2 {
public static void main(String[] args) throws IOException {
final int SEATS = 11;
int passenger = 0;
int coach = 6;
int firstClass = 1;
int choice;
char response;
boolean[] flight = new boolean[SEATS];
Arrays.fill(flight, false);
Scanner sc = new Scanner(System.in);
while (passenger < 10)
{
System.out.println("Press 1 for \"The Creamy Front Seats\"\n"
+ "Press 2 for \"Old and Dirty Back Seats\"\n");
choice = sc.nextInt();
if (choice == 1)
{
if(!flight[firstClass] && firstClass <= 5)
{
System.out.println("Your seat is " + firstClass
+ " in the Super Sweet Front Section.");
flight[firstClass++] = true;
passenger++;
}
else if (firstClass > 5 && coach <= 10)
{
System.out.println("The Ultra Kewl People section is full.\n"+
"Would you like to sit With the Animals (Y or N)?");
response = (char)System.in.read();
if (response == 'Y' || response == 'y')
{
System.out.println("Your seat is " + coach +
" in the Back Half of The Plane.\n");
flight[coach++] = true;
passenger++;
}
else
{
System.out.println("Next Flight in 3 hours so you'd better hurry up.");
}
}
else
System.out.println("Next flight in 3 hours this means you.");
}
else
{
if(!flight[coach] && coach <= 10)
{
System.out.println("Your seat is " + coach +
" in the crappy part of town.");
flight[coach++] = true;
passenger++;
}
else if (firstClass <= 5)
{
System.out.println("The poor people section is full.\n" +
"Would you like to sit in the upperclass section ( Y or N)?");
response = (char)System.in.read();
if (response == 'Y' || response == 'y')
{
System.out.println("Your seat is " + firstClass +
" in the rich part of town.\n");
passenger++;
}
else
{
System.out.println("Next flight in 3 hours you'd better hurry up.");
}
}
else
{
System.out.println("Next flight in 3 hours put a rush on that.");
}
}
}
System.out.println("All of the seats are gone, sorry but you suck.");
}
}
I might be wrong though, but it compiles.
Last edited: 18-Jul-08 01:13 PM