File tree Expand file tree Collapse file tree 5 files changed +110
-0
lines changed
Expand file tree Collapse file tree 5 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ /.project
2+ /.classpath
Original file line number Diff line number Diff line change 1+
2+ public class Assento {
3+ private int fila ;
4+ private char assento ;
5+ private boolean livre = true ;
6+
7+ public Assento (int f , char a ) {
8+ fila = f ;
9+ assento = a ;
10+ }
11+
12+ public boolean getEstado () {
13+ return livre ;
14+ }
15+
16+ public void reserva () {
17+ livre = !livre ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+
2+ public class EX0403 {
3+
4+ public static void main (String [] args ) {
5+ Voo v = new Voo (10 , 4 );
6+
7+ v .reserva (1 , 'A' );
8+ v .reserva (1 , 'B' );
9+ v .reserva (4 , 'C' );
10+ v .reserva (4 , 'D' );
11+
12+ v .imprimeMapa ();
13+ }
14+ }
Original file line number Diff line number Diff line change 1+
2+ public class Voo {
3+ private Assento assentos [][];
4+ private int nFila ;
5+ private int nAssentos ;
6+
7+ public Voo (int nf , int na ) {
8+ if (nf <= 0 || na <= 0 )
9+ return ;
10+
11+ char as ;
12+ nFila = nf ;
13+ nAssentos = na ;
14+ assentos = new Assento [nFila ][nAssentos ];
15+
16+ for (int i = 0 ; i < nf ; i ++) {
17+ for (int j = 0 ; j < na ; j ++) {
18+ as = (char )(j + 'A' );
19+ assentos [i ][j ] = new Assento (i + 1 , as );
20+ }
21+ }
22+ }
23+
24+ public boolean reserva (int f , char a ) {
25+ int pos = a - 'A' ;
26+
27+ if (assentos == null ||
28+ assentos .length <= (f - 1 ) ||
29+ assentos [f - 1 ].length <= pos )
30+ return false ;
31+
32+ Assento assento = assentos [f - 1 ][pos ];
33+ if (assento == null )
34+ return false ;
35+
36+ boolean condicaoRetorno = assento .getEstado ();
37+
38+ if (condicaoRetorno )
39+ assento .reserva ();
40+
41+ return condicaoRetorno ;
42+ }
43+
44+ public void imprimeMapa () {
45+ if (assentos == null )
46+ return ;
47+
48+ Assento assento ;
49+ String estadoAssento ;
50+
51+ System .out .print (" " );
52+
53+ for (int cont = 0 ; cont < nAssentos ; cont ++) {
54+ System .out .printf ("%c " , (char )(cont + 'A' ));
55+ }
56+
57+ System .out .println ();
58+
59+ for (int i = 0 ; i < nFila ; i ++) {
60+ System .out .print (String .format ("%02d" , i + 1 ) + " - " );
61+
62+ for (int j = 0 ; j < nAssentos ; j ++) {
63+ assento = assentos [i ][j ];
64+ if (assento == null )
65+ return ;
66+
67+ estadoAssento = assento .getEstado () ? "L" : "X" ;
68+
69+ System .out .print (estadoAssento + " " );
70+ }
71+
72+ System .out .println ();
73+ }
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments