|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Seat problem in an Airplane
The problem is described as follows:
Quote:
Code:
public class Seat {
private boolean visible;
private String name;
public Seat(String name) {
visible=true;
this.name=name;
}
public void setVisible(boolean b){
visible=b;
}
public String getName(){
return name;
}
public boolean getVisible(){
return visible;
}
public String toString(){
if(visible)
return name;
else
name="X";
return name;
}
}
Code:
import java.util.*;
public class Airplane {
public static void main (String[] args) {
Scanner scan=new Scanner(System.in);
Seat[][]array=new Seat[7][4];
Seat desiredSeat;
int count=0;
int row;
String name;
for (int i = 0; i<7; i++){
array[i][0]=new Seat("A");
array[i][1]=new Seat("B");
array[i][2]=new Seat("C");
array[i][3]=new Seat("D");
}
do{
do{
printArray(array);
System.out.println("Which place do you want to take: ");
row=scan.nextInt();
name=scan.next();
}while(row>7);
for(int i=0;i<4;i++){
if(array[row-1][i].getName().equalsIgnoreCase(name)){
if(array[row-1][i].getVisible()==false){
System.out.println("The seat is already taken, please select another one.");
}
else{
array[row-1][i].setVisible(false);
count++;
}
}
}
}while(count!=28);
printArray(array);
System.out.println("All seats have been sold!!!");
}
public static void printArray(Seat[][] a){
for(int i=0;i<7;i++){
System.out.print(i+1+" ");
for(int j=0;j<4;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Win7] Problem Steps Recorder | Termana | Tutorials | 1 | 04-14-2009 10:24 AM |
| JNLP saveFileDialog problem | d98tp | Java Help | 0 | 03-04-2009 06:10 AM |
| Peculiar UI Problem Needs Tackling | adriyel | C# Programming | 2 | 04-06-2008 08:46 AM |
| Problem read pwd protected Access2K dbase - CR9 & VB6 | mrbar | Visual Basic Programming | 2 | 03-10-2008 05:50 AM |
| How to tackle a programming problem? | TcM | General Programming | 10 | 01-07-2008 12:29 PM |
All times are GMT -5. The time now is 09:26 AM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc