Java代写:CS12J Round Robin Lineup

代写Java作业,练习OOP和数据结构的基础知识。

Goals

  • Practice with general concepts of OOP in Java, e.g. constructors, fields, accessors, and mutators.
  • Implement a relatively simpledata structureas an instantiable class.

Prerequisites

This assignment requires knowledge of the material presented in class throughweek 08 and/or through the introductory OOP material of the textbooks.

Assignment

You shall complete the definition of a class namedLineup. An instance of classLineuprepresents a fixed-length list of strings, where some element is always the “current” element of the lineup. Accessor and mutator methods are available to inspect the current element, move to the next element (i.e., “iterate”), rename the current element, etc. Unlike a normal list or array, iterating past the last element of a lineup will return to the beginning of the lineup. A lineup is thus infinitely iterable, never-ending, etc.

Starter Code

Your class must implement exactly the following methods, exactly as described. Please use this code as a starting point for the assignment.
Lineup.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Class Lineup implements a fixed-length list of strings, where some element is always the
* "current" element of the lineup. Accessor and mutator methods are available to inspect the
* current element, move to the next element (i.e., "iterate"), rename the current element, etc.
* Unlike a normal list or array, iterating past the last element of a lineup will return to the
* beginning of the lineup. A lineup is thus infinitely iterable, never-ending, etc.
*
* @author Someone for CS 12J
*/

public class Lineup {
// TODO: Decide on appropriate private fields
/**
* Constructs a new lineup using values from the given array, such that the elements of this
* lineup shall be the strings in the array, in the same order. The argument array shall never be
* modified by this lineup. After construction, the current element of this lineup shall be the
* first element.
*
* @param elements an array containing the elements of this lineup
*/

public Lineup(String[] elements) {
// TODO
}

/**
* Returns the number of elements in this lineup.
*
* @return the number of elements in this lineup
*/

public int size() {
// TODO
}

/**
* Returns the value of the current element in this lineup.
*
* @return the value of the current element in this lineup
*/

public String current() {
// TODO
}

/**
* Moves to the next element in the lineup. After this method completes, the current
* element will now be the element after what was previously the current. In the case that the
* current element was the last element, the current element will be the first element.
*
* @return the value of the new current element
*/

public String next() {
// TODO
}

/**
* Replaces the value of the current element of this lineup.
*
* @param replacement the new value for the current element
*/

public void replace(String replacement) {
// TODO
}

/**
* Returns a string representation of this lineup. The string representation consists of a
* list of the lineup's members in the order they will next be encountered, enclosed in
* square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and
* space).
*
* @return a string representation of this lineup
*/

public String toString() {
// TODO
}
/**
* Compares this lineup with another for equality. Returns true if and only if the other
* lineup has the same members in the same order, and the same current element as well.
*
* @param that the lineup to be compared for equality with this lineup
* @return true if the specified lineup is equal to this lineup
*/

public boolean equals(Lineup that) {
// TODO
}

}

Demonstration and Testing

See the following code and diagrams for usage of theLineupclass, expected behavior of its methods, as well as a mechanism for testing its functionality. Include this code in amainmethod in another class (e.g.LineupTest) in order to test yourLineupclass.

Note that the code below usesassertionsfor testing (see link for details). In order to test the assertions, you must include the-enableassertionsor-eaargument to the JVM:

java -enableassertions LineupTest

You can also add this flag to your run/debug configuration in Eclipse.

Requirements and Tips

  1. All fields in classLineupmust beprivateand nonstatic
  2. You must at least implement all of the specified methods in classLineup(even if they don’t behave correctly) in order to receive a grade.
  3. ClassLineupshall contain no print statements. (You may want to use some for debugging purposes, but please remove them when submitting).
  4. My solution class has two fields, of typeString[]andint.