Question: IN JAVA > Posse -DEFAULT SIZE : int = 100 -size : int -members : Student] +Posse(maxSize : int) +Posse() +add(student : Student) : boolean

IN JAVA

> Posse -DEFAULT SIZE : int = 100 -size : int -members : Student] +Posse(maxSize : int) +Posse() +add(student : Student) : boolean +contains(student : Student) : boolean +get(index : int) : Student +get(name : String) : Student +getMaxSize(): int +getSize() : int Detailed Specifications Constructors As usual, the constructors must appropriately initialize each of the instance variables. The default constructor must initialize the Posse to have a maxSize of DEFAULT_SIZE . (Note: As always, you must avoid code duplication.) The get() Methods Both get() methods must return either (a reference to) a Student that is in the owning object's Posse or null. The version that is passed an int must return the Student at the given index of the members array if the index is valid and must return null otherwise. The version that is passed a String must return the Student with the given name if that Student is in the members array and must return null otherwise (including when the parameter is null ). You may assume that the parameter name is unique. The get() methods must not contain duplicate code and must not duplicate code in any other methods. contains() The contains() method must return true if the given Student is in the owning Posse and must return false otherwise (including when the parameter is null ). It must not duplicate code that is in the get() methods (i.e., it should call one of the get() methods and/or call a private helper method.) add() The add() method must add the given Student to the end of the owning Posse if and only if it is not already in the Posse and the Posse is not full. It must return false if the Posse was full and true if either the Student was added or if it was already in the Posse. getSize() The getSize() method must return the number of Student objects that are currently in the Posse (not the maximum size of the Posse). getMaxSize() The getMaxSize() method must return the maximum size of the Posse (not the number of Student objects that are currently in it). The Student class The Student class must conform to the following detailed class diagram. > Student -seat: int[] -friends: Posse -name: String . +Student(name : String) +Student(name : String, row : int, column : int) +addFriend(friend : Student) +equals(other : Object) : boolean +getColumn() : int +getName() : String +getRow() : int +setColumn(column: int) +setRow(row : int) +unhappiness() : double You are free to add additional private helper methods, but the public methods must match the UML specification exactly. Detailed Specifications Attributes The role of the name attribute and Posse attributes should be apparent from the UML diagrams. The seat attribute must have a length of 2 and must contain the row and column (in that order) of the Student object's seat. Parameter Validation All methods that change the row and/or column must (directly or indirectly) validate the parameters they are passed. Specifically, if the parameter is less than 0 then the corresponding instance variable must be set to 0. Constructors As usual, the constructors must appropriately initialize each of the instance variables. The single-argument constructor must initialize both the row and the column values to 0. (Note: As always, you must avoid code duplication. In this case, one constructor should probably call the other, which itself should call setRow() and setColumn(). Accessors and Mutators Getters and setters must perform the appropriate operations (accounting for parameter validation as discussed above). addFriend) This method must add the provided Student object to the Posse named friends. However, it must not add a Student object to her/his own Posse. equals() This method must return true if and only if the name of the owning Student object is the same as the name of the given Student object. (Note that, this product assumes that names are unique.) unhappiness() A student's unhappiness is defined to be the summed Euclidean distance from the student to each of the student's friends. More formally, the unhappiness of student g is defined to be: dl, f) fer (2) where F denotes the set of friends of student g, denotes the seat of student g, f denotes the seat of student f, and d denotes the Euclidean distance function. If the student has no friends then this method must return 0.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
