The CS self-placement is intended to evaluate the skills necessary for you to succeed in Data Structures (COMP 229). Newcomers to computer science should enroll in Fundamentals of 计算机科学 (COMP 131), which is designed for students with no CS experience.

The self-placement should be completed using the Java programming language. If you are unfamiliar with Java, or are 否则 not fluent in the language, we strongly recommend some studying before attempting this self-placement.

The self-placement consists of two programming questions in Java. The first question looks at general problem solving 和 control flow, while the second question requires object oriented programming. 我们提供了 test case for each question, but be aware that they do not comprehensively check your code for bugs. We highly encourage you to write additional test cases, 和 in particular determine what (if any) edge cases exist 和 making sure that your code h和les them appropriately.

The self-placement is designed to take two hours, with open notes. This means you are allowed to use notes from your previous classes, also use the internet to look up syntax 和 remind yourself of programming concepts. directly search for solutions to these questions, nor give the questions to GPT. Keep in mind that the goal this self-placement is to determine whether you are ready for Data Structures; submitting code you do not underst和 will only set you up for failure in the course. We trust you to be honest with both the time limit 和 the open notes policy.

When you are done with the self-placement, please email Professor 贾斯汀•李 (justinnhli@tbc007.net)和你的代码. You will be asked to set up a meeting to talk ab出 your solution, at which point we will determine whether you can be placed into Data Structures.

启动代码可在 http://www.dropbox.com/s/znxqyw7eyialkbo/starter-code.zip?dl=1.


  1. 写一个函数 降雨(int []) 它接受一个int类型的数组, which represent the daily rainfall amounts as measured by field instrument. The data may contain negative numbers, which are errors in the instrument, 和 should be ignored. The number -999 indicates the end of the data of interest. The function should return the average (as a double) of the non-negative values in the list up to the first -999 (if it shows up).

    例子:

    int[] data = {1, 5, 7, -2, 1, -999, 4};
    系统.出.println(降雨(数据));
    

    The code above should print 出 3.5, because (1 + 5 + 7 + 1) / 4 = 3.5. The -2 is ignored, 和 since we get to -999 before the final number, it is ignored as well.

  2. Congratulations on your new job as a programmer for Red Woof Inn, the country's leading pet hotel! Alright, so the chain only has one location, but every business has to start somewhere. Red Woof Inn has asked you to create their check-in/check-出 system, which will keep track of where the animal guests are staying 和 which rooms are available. With your help, Red Woof Inn will be the top dog in the animal hostel business in no time.

    You need to create four classes in total: three which represent animals, 和 one which represents the hotel. The rooms in the pet hotels are simply numbered 0, 1, 2, 和 so on, up to however many rooms exist. 宠物可以 签入结帐 of the hotel, 和 staff can also look up who occupies which room 和 which pet is staying where.

    You must implement the following public methods in the 宠物 类:

    • 宠物(String species, String name) -构造函数. The two arguments are the species 和 name of the pet, respectively.

    • 字符串getSpecies () ——返回 the species of the pet.

    • 字符串getName () -返回宠物的名字.

    • 空白makeSound () ——打印 “我喜欢海滩男孩!".

    • 布尔值= (宠物 other) ——返回 真正的 如果两个宠物是相同的,或者 否则. For the purpose of this problem, two pets are the same if they are the same species 和 have the same name.

    Additionally, you must create two subclasses of 宠物: . 他们的物种应该是 “鸭子”“鹅” respectively, 和 have constructors with only one argument (鸭子(字符串名称)鹅(字符串名称)). 它们也应该覆盖 makeSound () 打印功能 “庸医!"“嘎!".

    Finally, you must implement the following public methods in the 宠物Hotel 类:

    • 宠物Hotel (int大小) -构造函数. The single argument is a non-negative integer that represents the total number of rooms in this hotel.

    • int numRoomsAvailable () - Gets the number of unoccupied rooms in this hotel.

    • 签入(宠物宠物) -入住宠物. A pet will always get the empty room with the lowest room number. 这个函数返回 真正的 if there is an empty room for the pet, 和 returns 否则.

    • boolean 结帐(宠物) -检查宠物. The room that was occupied by this pet becomes empty. 这个函数返回 真正的 if the pet is staying at the hotel (和 so can successfully check 出), 和 returns 否则.

    • 宠物 getOccupantOf(int roomNumber) - Gets the occupant of a particular room. 如果无效 roomNumber is given, this function should return .

    • int gettroomof(宠物宠物) - Gets the room of a specific pet. If the pet is not staying at this hotel, this function should return -1.

    You should add member variables to these classes as necessary to store data. 我们提供了 main () 函数中的 宠物Hotel class that demonstrates how these methods might be used. A correct implementation of these classes should give the return values provided in the comments.

联系计算机科学
天鹅厅B101