Question: JAVA HELP! INSTRUCTIONS: The only things you can import are the Scanner and the File. Any extra functionality besides the default (i.e. java.lang) is disallowed.
JAVA HELP!
INSTRUCTIONS:
- The only things you can import are the Scanner and the File. Any extra functionality besides the default (i.e. java.lang) is disallowed.
- You may not use any built-in functionality for copying an array, like System.arrayCopy(), Arrays.copyOf(), Object.clone(), Arrays.stream, etc. If you want to copy an array, you should do it manually (i.e. create a new array and transfer the data).
class Junior:
An object of this class will represent a single junior student.
Fields-
-
int id : A unique id number
-
String name : A non unique name. It can be first last or just first or any other string.
-
int SAT : A numeric value between 0 and 1600.
-
you can add more as needed
Methods:
-
Junior(id, name, SAT) : A constructor that initializes the above fields.
-
getId, getName, getSAT : Getter methods
-
copy : Not a constructor, but creates and returns a non-alias copy of this object. Useful for sharing the object without allowing modification.
-
toString : Overrides the default method. Don't forget the @Override annotation. It represents a Junior in the form of id: name, e.g. 0001: Ronald Koeman
-
equals(Object other) : Overrides the default method and compares this Junior to the other Junior. Don't forget the @Override annotation. It returns true if the two juniors have the same id and name. Hint: You can start your method with the following code to check if the other object has the proper type, and then, don't forget to cast the other object before you use it.
if ( ! ( other instanceof Junior) ) { return false; } -
you can add more as needed
class JuniorList
The purpose of this class is to create a simplistic list-like structure to allow us to group Junior student values together. We will use an internal array of objects to provide functionality such as adding, removing, reading, and writing values into the sequence of Junior objects.
Fields:
- An array of Junior. You can pick any name you like. It stores all the current junior values in an array that is exactly the right length (it should never have extra spots available). When implementing methods below, we will often be creating a new array of a different length and replacing the values of this variable because arrays cannot change length.
-
you can add more as needed
Methods:
-
JuniorList() : This constructor method initializes the internal array to size zero.
-
JuniorList(String filename) : This constructor method initializes the internal array by loading data from a file. The file will contain one line per junior with id,name,SAT as in the example below:
1045,Oliver,1320 1022,Frenkie,1400 1089,De Jong,1394 1139,Virgil,1020
-
JuniorList copy() : This is not a constructor method itself; it does create a different JuniorList object (with no aliases to itself) and returns this new copy.
-
int size() : Returns how many items are currently in the list.
-
get(int index) : Returns the value at the provided index. Must throw a RuntimeException when the index is out of bounds. This can be done with the following statement in Java: throw new RuntimeException()
-
void set(int index, Student value) : Changes the value at the given index to the new value. Must throw a RuntimeException when the index is out of bounds.
-
indexOf(Student value) : Finds the given value and returns that value's index in the list. Must return -1 when the value is not found (do not throw an exception).
-
void add(Student value) : Adds the value to the end of the internal array. Since arrays can't change length, you must create a new array of the exact new required size, copy values over, and place the given value at the end. Must throw a RuntimeException if the given value is null.
-
void insert(int index, Student value) : Has the effect of inserting this value in the list so that value is the new value at index, and any values previously at that location or later have all been pushed to the right by one. Must throw a RuntimeException if the given value is null. Must throw a RuntimeException if the given index is out of bounds: It may be any index of the current array or equal to one larger than the last valid index, but no larger.
-
void remove(Student value) : Finds and removes the value from the list. All values that were after it will be shifted one spot towards the beginning of the list. Must throw a RuntimeException when the given value does not exist in the list.
-
getHighestScoreJunior: Returns the junior student that has the highest SAT score. Must throw a RuntimeException when there are no students admitted.
-
toString : Overrides the default method. Don't forget the @Override annotation. It represents a list a comma separated representations of junior students enclosed in curly braces. For example, if there were three students in the list "0001: Ronald Koeman", "92: John van Dijk", and "555: De Natalie", then we would return "{0001: Ronald Koeman, 92: John van Dijk, 555: De Natalie}".
-
you can add more as needed
Please help with these 2 classes. Comments are Appreciated. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
