Skip to content
ExamSpine

Lesson 6.9 · Write it

Seat finder

A whole programPython or Java8 tests, 6 of them hidden

On a phone? Put the lines in order instead

The seating plan for an exam hall is saved in seats.csv. Each line of the file is one row of desks, from the front, and holds the names of the students in that row, from the left, with a comma between each name. Write a program that reads a name typed in and says where that student sits.

  1. Read the name, then read the file into a list of rows, each row a list of its names.
  2. If the name is in the plan, print Row and the row number, then , seat and the seat number, such as Row 2, seat 3. The front row is row 1, and the leftmost seat is seat 1.
  3. If the name is not in the plan, print Not seated, once.
  4. Rows can have different numbers of seats. An empty seat is an empty field, such as the middle of Ana,,Cy. A name appears at most once, has no commas, and never starts or ends with a space. The name typed in is never empty.
  5. The last line may or may not end with a line end. There is no header line.

Your program is run several times, each time in a folder that holds only the files shown for that run.

Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.

Examples

Your program is run 8 times: the 2 examples below, and 6 hidden ones that check the rules above. Only what it prints is checked. Each run starts in an empty folder that holds only the files shown for it.

  • Hu is in the middle of the third row (rule 2)

    You type

    1. typed: Hu

    It prints

    Row 3, seat 2

    Files in its folder

    seats.csv
    Ana,Bo,Cy
    Dee,Eli,Fay
    Gil,Hu,Ivo
  • Fay is the last name on that line (rule 2)

    You type

    1. typed: Fay

    It prints

    Row 2, seat 3

    Files in its folder

    seats.csv
    Ana,Bo,Cy
    Dee,Eli,Fay
solution.pySolution.java

Report a problem with this page