

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Quiz 1 for intro to object-oriented programming class practice quiz
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CMSC133, Fall 2021, QUIZ #1 (DURATION: 20 MINUTES)
STUDENT ID (e.g. 123456789):
Provide answers in the rectangular areas provided. You will be penalized if your code is not efficient. On the reverse side you will see a driver and expected output that relies on the class you are expected to implement. You can ignore it if you know what to implement. The driver relies on a method (getCount()) that you don’t need to implement.
Define a class called Room based on the specifications below. The class defines the following private variables:
private String id; /* Represents the room ’s id / private int beds; / Specifies the number of beds in the room / private double cost; / Daily cost of the room in dollars / private String guests; / String with the names of guests / private static int count; / Keeps track of the number of Room objects created */
Driver / Expected Output (Feel free to ignore)
Driver
String id = "Room1"; int beds = 2; double cost = 50.75;
Room room = new Room(id, beds, cost); Room copy = new Room(room); copy.addGuest("Mary").addGuest("Peter");
System.out.println("***** Original Room *****"); System.out.println(room);
System.out.println("***** Room copy info *****"); System.out.println(copy);
System.out.println("***** Last room *****"); System.out.println(new Room());
System.out.println("Total Number of Rooms: " + Room.getCount());
Output
***** Original Room ***** Room1, 2, 50.75, Guests: ***** Room copy info ***** Room1, 2, 50.75, Guests: MaryPeter ***** Last room ***** NONE, 2, 50.25, Guests: Total Number of Rooms: 3