--- tags: Setup --- # Lecture 20 Setup/Prep In this lecture, we'll look at how Scala handles class hierarchies and interfaces. We will spend a few minutes at the start of class in breakouts, discussing how you would design a class hierarchy for the problem given below the line. ## Prep Look at and/or download the [starter file](https://brown-cs18-master.github.io/content/lectures/20scalatraits/Listing.scala). It shows a class definition in Scala (that is more complicated than the `Triple` example from Friday). Read over the problem that we'll work on. --- ### Our motivating problem for the day We'll do this through a concrete problem of creating class hierarchies for different kinds of hotel rooms, as they might be listed on a room-rental or travel website. A basic listing has (1) the property/hotel name, (2) a daily rate, (3) the number of people it can sleep, and (4) a list of detailed amenities (like hairdryers). We want to extend our program with`Suites`, which are listings that have multiple rooms. - `Listings` and `Suites` could be marked as *Premium* meaning that they charge extra for some feature, like a fabulous view. - `Listings` and `Suites` could also have a kitchenette (featuring a fridge and microwave) and/or a gym. Listings will support three methods: - `price`, which takes a number of nights and returns the cost of that many nights at the daily rate - `descr`, which takes no arguments and returns a description of the listing - `changeRate`, which takes a new daily rate and updates the rate in the listing In addition, `Suites` have a method `roomsAtLeast` which takes a number of rooms and returns a Boolean indicating whether the number of rooms is at least the given number.