Skip to main content
留学咨询

辅导案例-CSCI 1110-Assignment 3

By May 15, 2020No Comments

1 Assignment 3: Object Objectives CSCI 1110 (Winter 2020) OVERVIEW Due Date DUE DATE: Tuesday, February 25th, 2020 @ 11 PM NOTE: All work is to be handed in using Mimir, our online code learning environment. You will learn how to access this tool in labs. Key concepts Introduction to classes and objects: • Methods • Constructors • References Background In this assignment, we are jumping feet first into object-oriented programming. You will get to develop three classes throughout this assignment, all of which will work together. First you will develop the Student class, a basic blueprint of a university student (i.e. name, student ID, etc.). Then you will develop the Room class, to simulate a room, to hold information about rooms that could be used around campus. Finally, you will put it all together. You will create a Course class. This will make use of both the Room and Student classes that you have already made. You will create the necessary instance variable and instance methods (both accessor/getter and mutator/setter methods) for all of these classes. You may find this assignment a bit shorter than the ones before. We know that we are now entering new territory and that you are nearing midterm season. We hope you enjoy this slightly softer introduction to OOP. Welcome to the world of objects! We hope you like it here! 2 UML Diagrams A common way to represent class structure is by using a UML diagram. If you are unfamiliar with this structure and haven’t yet had a chance to step through this in your lab, please take a look for supporting information about UML diagrams on our Brightspace page. Below are the UML diagram basics: • Fields/attributes (instance variables): o visibility name : type • Methods/operations(instance methods): o visibility name (parameters) : return-type • visibility: + public – private 3 GRADING Each problem on the assignment will be graded based on three criteria: Functionality “Does it work according to specifications?” This is determined in an automated fashion by running your program on a number of inputs and ensuring that the outputs match the expected outputs. The score is determined based on the number of tests that your program passes. Quality of Solution “Is it a good solution?” This considers whether the solution is correct, efficient, covers boundary conditions, does not have any obvious bugs, etc. This is determined by visual inspection of the code. Initially full marks are given to each solution and marks are deducted based on faults found in the solution. Code Clarity “Is it well written?” This considers whether the solution is properly formatted, well – documented, and follows coding style guidelines. A single code clarity score is assigned for all solutions. If your program does not compile, it is considered non -functional and of extremely poor quality, meaning you will receive 0 for the solution. Marking Scheme Problem Partial Points Points Problem 1: Student Success ▪ Functionality ▪ Code quality & code clarity 20 10 30 Problem 2: Room for More ▪ Functionality ▪ Code quality & code clarity 20 10 30 Problem 3: Course Correction ▪ Functionality ▪ Code quality & code clarity 30 10 40 TOTAL 100 100 4 PROBLEM 1: Student Success [30 points] For this first problem, you will implement a simple class: the Student class! All the information you should need can be found within the description of the Student class (to be created in the file Student.java) and in the UML diagram below. The Student class We always try to put students first! And now we are asking you to as well! Here you will construct the Student class based on the information below. Student -studentID: int -firstName: String -preferredName: String -lastName: String +Student(ID: int, firstName: String, lastName: String) +getStudentID(): int +getName(): String +setLastName(lastName: String): void +setPreferredName(preferredName: String): void +toString(): String 5 Description of methods from the Student class: +Student(ID: int, firstName: String, lastName: String) Constructs a student with designated student ID, first name and last name. Preferred name is initially set to be the same as their first name. +getStudentID(): int Returns the integer student ID. +getName(): String Returns a string containing the student’s preferred name in the form: “preferred-name last-name” +setLastName(lastName: String): void Update the last name of a student. +setPreferredName(preferredName: String): void Sets the name that the student would preferred to be called. +toString(): String Overrides the existing string representation of the object to be: getName() + ” (” + student-id + “)” 6 PROBLEM 2: Room for More [30 points] Now that you’ve got the students sorted, you need to give them a room to study in. The next task is to finish off the Building and Room classes based on the UML diagrams and descriptions below. The Building class The Building class is pretty straight forward as you can see below. You can tackle this even before you’re finished with your Student class in problem 1. Building -buildingName: String -numberFloors: int -campusLocation: String +Building(name: String, floors: int, campus: String) +getBuildingName(): String +getCampus(): String +hasMoreFloors(otherBuilding: Building): int +toString(): String 7 Description of methods from the Building class: +Building(name: String, floors: int, campus: String) Constructs a building with building name, number of floors and located on the specified campus name. +getBuildingName(): String Returns the building name. +getCampus(): String Returns a campus that a building is located on. +hasMoreFloors(otherBuilding: Building): int Compares the number of floors that the building has to another Building object. It returns the number of floors that it has more than the other one. If taller, the number is positive (i.e. returning 3 implies that it has more floors that then “other building”). If equal, the two buildings are of the same height. If negative, the other building is the taller of the two. +toString(): String Overrides the existing string representation of the object to be: building-name + ” building (” + num-floors + ” floors), ” + campus + ” campus” 8 The Room class The Room class relies on the Building class as previously created. Room -building: Building -roomNumber: int -roomCapacity: int +Room(building: Building, room: int, capacity: int) +getBuilding(): Building +getRoomCapacity(): int +setRoomCapacity(capacity: int): void +toString(): String Description of methods for the Room class: +Room(building: Building, room: int, capacity: int) Constructs a room in the designated Building, and with the specified room number and capacity. +getBuilding(): Building Returns the building in which the room is located. +getRoomCapacity(): int Returns the integer room capacity +setRoomCapacity(capacity: int): void Sets a new capacity for a room (e.g. if the room was expanded during a remodel). +toString(): String Overrides the existing string representation of the object to be: building-name + ” building, Room ” + roomNumber + ” (seats ” + capacity + “)” 9 PROBLEM 3: Course Correction [40 points] Now that we have that sorted, we are ready to connect all the dots. You will complete the Course class in this problem. All the information you should need can be found within the descriptions and UML diagram below. The Course class The Course class makes use of all of the other classes that you have made so far. In order to start this problem, you must have completed the first two problems successfully. You may then copy those files over here. Course -courseID: int -courseCode: String -courseName: String -courseCapacity: int -numberStudents: int
-room: Room -students: Student[] -waitListCount: int +Course(ID: int, code: String, name: String, room: Room) +getBuildingName(): String +getCampus(): String +getCourseID(): int +getCourseCode(): String +getNumberStudents(): int +getStudents(): Student[] (Returns array of registered students) +isInCourseAlready(student: Student): boolean +isSpaceLeftInCourse(): boolean +registerStudent(student: Student): int +toString(): String 10 Description of methods for the Course class: +Course(ID: int, code: String, name: String, room: Room) Constructs a Course object with course ID, course name and room specified. Number of students and wait list count is cleared. Course capacity is set to the capacity of the room specified. Student array is set initialized to fit capacity. +getBuildingName(): String Returns the name of the building (based on the room) in which the course is located. +getCampus(): String Returns the name of the campus (based on the room) in which the course is located. +getCourseID(): int Returns the ID of the course (e.g. the CRN for your courses) +getCourseCode(): String Returns the course code (e.g. “CSCI 1110”) +getNumberStudents(): int Returns the number of students registered for the course. +getStudents(): Student[] Returns an array of Students that are registered in the course. Note that this is a subarray of the students array. +isInCourseAlready(student: Student): boolean Returns true if student is already registered for the course, false otherwise. +isSpaceLeftInCourse(): boolean Returns true if there is space left in the course (e.g. number of students is less than the course capacity). 11 +registerStudent(student: Student): int Registers (adds) a Student to the class if possible. If the student is already in the course, the student is not added. If number of students in class is greater than the capacity of the room/course, the student is not added and the wait list count for the course by 1 (student’s number on wait list). Returns 0 if student is added to course, -1 if previously registered, or the number on the wait list if there was no space in the course and they were added to the wait list +toString(): String Overrides the existing string representation of the object. Return the following value: value = “COURSE ” + course-ID + “: \n” + course-code + ” – ” + course-name + “\n” + room.toString() + “\n” + “Current: ” + number-students + ” / ” + course-capacity + “\n” + “Wait list count: ” + wait-list-count ;

admin

Author admin

More posts by admin