Java代写:Social Networking for SitRite3K

java代写:这是一个java相关的代写,涉及基本的图等方面的知识
Social Networking for SitRite3K

Introduction

Welcome to EduCorp, The nation’s leading purveyor of educational support software! You will be joining the team tasked with developing EduCorp’s latest classroom support product, SitRite3K.

For this assignment, you must implement three classes, a class named Student that encapsulates information about individual students, a class named Posse class that manages an individual Student object’s friends, and a utility class named Social that contains methods for performing calculations involving social networks.

At a high level of abstraction, the relationships between these classes can be modeled using the following UML class diagram.

The details of each class in this diagram are provided below.

1. The Social Class

The Social class must conform to the following detailed class diagram.

Detailed Specifications

distance()

The distance() method must calculate the Euclidean distance between two seats, s and t, as follows:

d(s,t)=(s0−t0)2+(s1−t1)2−−−−−−−−−−−−−−−−−√

where element 0 contains the row and element 1 contains the column. For simplicity, it assumes that the seats are arranged in a uniform grid with one meter of separation between adjacent seats.

2. The Student Class

The Student class must conform to the following detailed class diagram.

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

With the exception of the getUnhappiness() method, which is discussed below, the getters and setters must perform the obvious 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.)

getUnhappiness()

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:

∑f∈Fd(g^,f^)

where F denotes the set of friends of student g, 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.

3. The Posse Class

The Posse class must conform to the following UML diagram:

You are free to add additional private helper methods, but the public methods must match the UML specification exactly.

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).

4. Implementation Advice

You should work on one class at a time and, within each class, one method at a time. After you complete each method you should test it. You may use a test harness (e.g., JUnit) if you are familiar with one, or you may write simple drivers. (Note: You must not submit your tests.)

You should consider implementing the classes/methods in the following order:

1. The distance() method in ths Social() class.

2. The constructors, setters, and simple getters in the Student class.

3. The equals() method in the Student class.

4. The constructors in the Posse class.

5. The add() method in the Posse class.

6. The getSize() method in the Posse class.

7. The get() methods in the Posse class.

8. The contains() methods in the Posse class.

9. The add() method in the Student class.

10. The getUnhappiness() method in the Student class.

Don’t delete the tests when you finish a method! You may be able to reuse them if you need to modify the method later. They also provide a useful reference if you need to get help.

发表评论

电子邮件地址不会被公开。 必填项已用*标注