Podría darte todo el código, pero no será bueno para ti. El objetivo de los ejercicios es que trates de no pedir ayuda hasta que realmente te hayas estancado. Así es como se hace un buen programador, en base a trabajo duro. Y mira que el curso de
Programación II, donde
se supone que has pasado Métodos algorítmicos I, Métodos algorítmicos II y Programación I, y quizás Análisis de algoritmos. Es decir, en éste punto, no debería ser problema resolver el ejercicio.
Como soy buen amigo (xD), te dejaré algunas clases:
import java.util.List;
import java.util.ArrayList;
public class Session {
private List<String> schedules;
private SessionSeats sessionSeats;
public Session() {
schedules = new ArrayList<>();
}
public Session
(Byte id, List
<String
> schedules., SessionSeat sessionSeats
) { this.id = id;
this.schedules = schedules;
this.sessionSeats = sessionSeats;
}
return id;
}
public void setid
(Byte id
) { this.id = id;
}
public List<String> getSchedules() {
return schedules;
}
public void setSchedules(List<String> schedules) {
this.schedules = schedules;
}
public SessionSeats getSessionSeats() {
return sessionSeats;
}
public void setSessionSeats(SessionSeats sessionSeats) {
this.sessionSeats;
}
public void addSchedule
(String schedule
) { schedules.add(schedule);
}
shedules.remove(schedule);
return schedule;
}
}
public class SessionSeats {
this.seats = seats;
if(seats[0] == null)
fillSeatsByDefault();
}
return seats;
}
public void showSeats() {
for(short row=0; row<seats.length; row++) {
for(short col=0; col<seats[row].length; col++) {
System.
out.
println(seats
[row
][col
]); }
}
}
private void fillSeatsByDefault() {
for(short row=0; row<seats.length; row++) {
for(short col=0; col<seats[row].length; col++) {
seats[row][col] = 'O';
}
}
}
seats[row][column] = 'X';
}
}
import java.util.List;
import java.util.ArrayList;
public class Room {
private List<Session> sessions;
public Room() {
sessions = new ArrayList<>();
}
public Room
(Byte id, List
<Session
> sessions
) { this.id = id;
this.sessions = sessions;
}
return id;
}
public void setid
(Byte id
) { this.id = id;
}
public List<Session> getSessions() {
return sessions;
}
public void setSessions(List<Session> sessions) {
this.sessions = sessions;
}
public void addSession(Session session) {
sessions.add(session);
}
public Session removeSession(Session session) {
sessions.remove(session);
return session;
}
}
public class MovieTheater {
private List<Room> rooms;
private final TicketSeller ticketSeller;
public MovieTheater
(String name, List
<Room
> rooms
) { this.name = name;
this.rooms = rooms;
ticketSeller = new TicketSeller(rooms);
}
public Ticket buyTicket() {
ticketSeller.buyTicket();
}
// tus otros metodos aquí...
}
public class Ticket {
private Session sessionId;
public Ticket() {
}
this.owner = owner;
this.session = session;
this.schedule = schedule;
this.seat = seat;
}
return owner;
}
public void setOwner
(String owner
) { this.owner = owner;
}
public Session getSession() {
return sessionId;
}
public void setSessionId(Session session) {
this.session = session;
}
return schedule;
}
public void setSchedule
(String schedule
) { this.schedule = schedule;
}
return seat;
}
public void setSeat
(Integer[] seat
) { this.seat = seat;
}
}
public class SessionUtils {
private void showSchedules(List<Room> rooms) {
for(Room room : rooms) {
for(Session session : room.getSessions()) {
for(String schedule
: session.
getSchedules()) }
}
}
for(Room room : rooms) {
for(Session session : room.getSessions()) {
for(String schedule
: session.
getSchedules()) { if(schedule.equals(choosedSchedule))
id = session.getSessionId();
}
}
}
if(id == -1)
return id;
}
Session target = null;
for(Room room : rooms) {
for(Session session : room.getSessions()) {
if(session.getSessionId().equals(id))
target = session;
}
}
if(target == null)
return target;
}
}
public class TicketSeller {
private final List<Room> rooms;
public TicketSeller(List<Room> rooms) {
this.rooms = rooms;
}
public Ticket buyTicket() {
System.
out.
println("¿Cuál es su nombre?"); System.
out.
println("¿En que horario desea ver la película?"); SessionUtils.showSchedules(rooms);
Byte sessionId
= SessionUtils.
getSessionIdBySchedule(rooms, schedule
); Session session = SessionUtils.getSessionById(rooms, sessionId);
SessionSeats seats = session.getSessionSeats();
seats.showSeats(); // muestra los asientos disponibles
System.
out.
println("¿Qué asiento desea? Ingresar las coordenadas así: X-Y"); String[] coordinates
= new Scanner
(System.
in).
readLine().
split("-"); seats.reserveSeat(row, column)
Ticket ownerTicket = new Ticket(owner, session, schedule, seat);
return owerTicket;
}
}
Ya tienes por lo menos el 50%.