0

Until now, i can't figure out how to tag a seat as taken per movie, since I just have one arraylist for the seats. As I said before, I must tag the seat selected as taken per movie. I'm a beginner in Python, so I don't know a lot of it. The program must be done using Object-oriented programming.

Right now i have this in my code:

Classes:

class movie:
    def __init__(self, title, duration, minimum_age, director):
        self.title = title
        self.duration = duration
        self.minimum_age = minimum_age
        self.director = director

class cinema(movie):
    def __init__(self, title, duration, minimum_age, director, price, hour):
        pelicula.__init__(self, title, duration, minimum_age, director)
        self.price = price
        self.hour = hour

    def getMovieData(self):
        print(f"Title: {self.title}\nDuration: {self.duration}\nMinimum age: {self.minimum_age}\nDirector: {self.director}\nPrice: {self.price}\nHour: {self.hour}")
    
class seat():
    def __init__(self, position, state, title, hour):
        self.position = position
        self.state = state
        self.title = title
        self.hour = hour

    def getSeatData(self):
        print(f"Title: {self.title}\nHour: {self.hour}\nSeat: {self.position}\n")

Array with the position of the seats:

seats = [['8A', '8B', '8C', '8D', '8E', '8F', '8G', '8H', '8I'],
        ['7A', '7B', '7C', '7D', '7E', '7F', '7G', '7H', '7I'],
        ['6A', '6B', '6C', '6D', '6E', '6F', '6G', '6H', '6I'],
        ['5A', '5B', '5C', '5D', '5E', '5F', '5G', '5H', '5I'],
        ['4A', '4B', '4C', '4D', '4E', '4F', '4G', '4H', '4I'],
        ['3A', '3B', '3C', '3D', '3E', '3F', '3G', '3H', '3I'],
        ['2A', '2B', '2C', '2D', '2E', '2F', '2G', '2H', '2I'],
        ['1A', '1B', '1C', '1D', '1E', '1F', '1G', '1H', '1I']]

An actual assignment of info for a movie:

m= randint(0, 7)
j = randint(0, 8)
print(m, j)

seats[m][j] = seat(seats[m][j], movie_list[0].title, movie_list[0].hour, True)

How I thought the replacement would work:

print(seats[m][j].getSeatData()) #Verify the state of the seat
print(seats[m][j])#Show nothing but what I thing is a memory position
seats[m][j] = 'XX' #The replacement of the seat must be shown per movie
for i in range (0, 8):
    for k in range (1, 9):
        print(seats[i][k], end=" ")
    print()

print(seats[m][j].getSeatData()) #Here it loses the state
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Firstly, you should take at look at this [answer](https://stackoverflow.com/a/7664904/13997884). – aasoo Sep 28 '20 at 18:38
  • Apart from that, `seats[m][j] = 'XX'` replaces the entire object instance with a string, which is why your last statement `seats[m][j].getSeatData()` fails. There simply is no `seat` instance left to call. You probably want something along the lines of `seats[m][j].state = 'XX'` – aasoo Sep 28 '20 at 18:42
  • I have in mind trying to save the necessary info of the seat in another arraylist but still missing the part that show the seat as taken for the specific movie. – Brandol Cortez Sep 28 '20 at 18:55

0 Answers0