Cinema project 5/5
cinema seat map is not updated to "B" after you buy a seat.user_7283264
kotlin
a year ago
1.9 kB
1
Indexable
Never
val prnRows = println("Enter the number of rows:") val rows = readln().toInt() val prnSeats = println("Enter the number of seats in each row:") val seats = readln().toInt() var totalSeats = MutableList(rows) { MutableList(seats) {'S'} } var numTickets = 0 var percentage = 0.0 var income = 0 var totIncome = 0 fun main() { opts() } fun opts () { println("\n1. Show the seats\n" + "2. Buy a ticket\n" + "3. Statistics\n" + "0. Exit\n") var opt = readln().toInt() when(opt) { 0 -> exitProcess(0) 1 -> showSeats() 2 -> buyTicket() 3 -> stats() } return opts() } fun showSeats() { print(" ") for (i in 1..rows) print(" $i") for (n in 1..seats) print("\n$n ${totalSeats[seats - 1].joinToString(separator = " ")}") return opts() } fun stats() { var formatPercentage = "%.2f".format(percentage) println("Number of purchased tickets: $numTickets\n" + "Percentage: $formatPercentage%\n" + "Current income: $$income\n" + "Total income: $$totIncome") return opts() } fun buyTicket() { println("Enter a row number:") val rowNum = readln().toInt() println("Enter a seat number in that row:") val seatNum = readln().toInt() totalSeats[rowNum][seatNum] = 'B' var ticketPrice = if (rowNum <= 4) 10 else 8 println("Ticket price: $$ticketPrice") if (ticketPrice == 10) { numTickets++ percentage = ((numTickets * 100) / (rows * seats)).toDouble() income = 10 totIncome += 10 }else if (ticketPrice == 8) { numTickets++ percentage = ((numTickets * 100) / (rows * seats)).toDouble() income = 8 totIncome += 8 } return opts() }