commercial airline

commercial airline

Page 1 of 1

5 Replies - 5189 Views - Last Post: 24 July 2010 - 07:27 PM Rate Topic: -----

#1 Guest_krisgarver*


Reputation:

commercial airline

Posted 23 July 2010 - 08:10 AM

help guyz..I have an assignment in our programming subject(were in multi dim. arrays). Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows and w/ 6 seats in each row. Rows 1 and 2 are first class, remaining rows are economy class. Rows 1 through 7 are nonsmoking.
the program must prompt the user to enter the following information:
Ticket type(1st class or economy class)
For economy class, the non-smoking or smoking
Desired Seat
Output the seating plan in the ff: format
| A | B | C | D | E | F |
Row1 | * | * | * | * | * | * |
Row2 | * | * | X | * | * | * |
Row3 | * | * | * | * | * | * |
Row4 | * | * | * | * | * | * |
Row5 | * | * | * | * | X | * |
Row6 | * | * | * | * | * | * |
Row7 | * | * | * | X | * | * |
Row8 | * | * | X | * | * | * |
Row9 | * | X | * | * | * | * |
Row10 | * | * | * | * | * | * |
Row11 | * | * | * | * | * | X |
Row12 | * | * | * | * | * | * |
Row13 | * | * | * | * | * | * |
NOTE:
* - indicates the seat is available
X - the seat has been assigned
Make this a menu driven program. Show the user's choice and allow the user to make appropriate choices


Here is my approach guyz
import java.util.*;
public class Multidim{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
			char array[][] = new char[14][7];
		
			int row=1;
			int k=1;;
			int r=0,c=0;
			int O=0;
			
			
			
			System.out.println("Welcome to Java Airlines!");
		
			row=1;
			System.out.println("       | A | B | C | D | E | F |" );
			for(int i=0;i<13;i++){
				for(int j=0;j<6;j++){
				
					array[i][j]='*';
					if(j==0){
						if(row<=9)
						System.out.print("Row"+row+"  ");
						else
							System.out.print("Row"+row+" ");	
						
					}
					
					System.out.print(" | "+array[i][j]);
				}
				System.out.print(" |");
				System.out.println();
				row++;
				
				
			}
			for(O=0;O<13;O++){ //just playing it out to enter another ticket
			array[r][c]='X';
			System.out.print("Please Select your ticket type[1]First Class[2]Economy Class");
				
			int m = sc.nextInt();
			switch(m){
				case 1: System.out.println("Please Enter Desired Seat");
						  System.out.print("Enter Row[1-2]:");
						  r = sc.nextInt();
						  System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
						  c = sc.nextInt();
						  break;
				case 2:System.out.print("Smoking(1) or Non-smoking(2)");
						 int sn = sc.nextInt();
						  if(sn==1){
						  	System.out.print("Enter Row[3-7]:");
						  	r = sc.nextInt();
						  	System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
						  	c=sc.nextInt();
						  }
						  else if(sn==2){
						  	System.out.print("Enter Row[8-13]:");
						  	r = sc.nextInt();
						  	System.out.print("Enter Column[1=A|2=B|3=C|4=D|5=E|6=F]:");
						  	c=sc.nextInt();
						  	
						  }
						  break;
				default:  System.out.print("Invalid!");
						  break;
			}
			
			System.out.println("       | A | B | C | D | E | F |" );
			row=1;
			r=r-1;
			c=c-1;
			for(int i=0;i<13;i++){
				for(int j=0;j<6;j++){
					if(r==i && c==j ){
						array[i][j]='X';
					}
					else{
					
						array[i][j]='*';}
					if(j==0){
						if(row<=9)
						System.out.print("Row"+row+"  ");
						else
							System.out.print("Row"+row+" ");	
						
					}
					
					System.out.print(" | "+array[i][j]);
					}
			
			System.out.print(" |");
				System.out.println();
				row++;
			
			}
			
		
			
			}
		
		
	}
}



whenever i input another ticket it does not incorporate the result of my first input
plus i need to know how to tell if i have chosen a reserved seat(X)

Is This A Good Question/Topic? 0

Replies To: commercial airline

#2 Guest_krisgarver*


Reputation:

Re: commercial airline

Posted 23 July 2010 - 08:14 AM

I forgot to tell you that we are not allow to use some sort of any methods other than the main method^_^
in other words just make it simple for beginners
Was This Post Helpful? 0

#3 NoobKnight   User is offline

  • D.I.C Head

Reputation: 49
  • View blog
  • Posts: 238
  • Joined: 14-July 09

Re: commercial airline

Posted 23 July 2010 - 08:48 AM

I believe your logic error is here.
for(int i=0;i<13;i++){
	for(int j=0;j<6;j++){
		if(r==i && c==j ){
		     array[i][j]='X';
		}
	        else{
		     array[i][j]='*';}   // <--- Your problem


You keep resetting it to empty if it isn't 'X', so you clear it
Just delete the else statement.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_krisgarver*


Reputation:

Re: commercial airline

Posted 24 July 2010 - 04:56 PM

It worked..thanks Noobknight..but how to tell if I have chosen a reserved seat ^_^
Was This Post Helpful? 0

#5 b0ng01   User is offline

  • D.I.C Head
  • member icon

Reputation: 38
  • View blog
  • Posts: 169
  • Joined: 16-July 10

Re: commercial airline

Posted 24 July 2010 - 05:37 PM

The easiest way to check for a reserved seat IMHO would be to add all the reserved seats to an array and before you choose a seat you check to see if that seat is in an array.
Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: commercial airline

Posted 24 July 2010 - 07:27 PM

Or make a Map. The keys could be the seats. When one is reserved, change that value to 1.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1