代做Project | 代做Math | Assignment代写 | Java – 这是一个一般难度的java练习题目
cmps11s
assignment 06: A Utility Class for Integer Collections
Goals
Implement a utility class.
Write general-purpose methods that take advantage of interface-based polymorphism in Java.
Prerequisites
This assignment requires knowledge of the material presented in class through week 06.
Background
A utility class consists exclusively of static methods, i.e. methods that receive all necessary input/state as arguments, and produce
all output as return values.
java.lang. math [https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/Math.html] is a classic
example of a utility class in the java API. Math cannot be instantiated, but exists purely to group together methods like
Math.random() [https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/Math.html#random()]
and constants like Math.PI
[https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/Math.html#PI].
Assignment
You shall write a utility class named IntegerCollections that consists exclusively of static methods that operate on integer
collections.
IntegerCollections shall implement the methods described in this documentation
[http://jeff.cis.cabrillo.edu/datasets/docs_integercollections/IntegerCollections.html].
Feel free to start from this skeletal implementation
[http://jeff.cis.cabrillo.edu/datasets/docs_integercollections/IntegerCollections.java].
Restriction
NOTE: Do not invoke make use of any classes or interfaces in the Java API outside java.lang, with the exception of:
java.util.ArrayList
java.util.Collection
java.util.HashSet
java.util.LinkedList
java.util.List
java.util.Set
java.util.TreeSet
Testing
As with the previous assignment, you will probably want to write a main method to test your IntegerCollections methods.
Something like the following is a start:
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class IntegerCollectionsTest {
public static void main(String[] args) {
var list1 = List.of( 0 , 1 , 2 , 3 );
var list2 = List.of( 4 , 5 , 6 , 5 );
var set1 = Set.of( 3 , 2 , 1 , 0 );
var set2 = Set.of( 2 , 4 , 6 , 0 , 1 );
assert IntegerCollections.disjoint(list1, list2);
assert !IntegerCollections.disjoint(list1, set1);
var toFill = new ArrayList<>(list1);
IntegerCollections.fill(toFill, 0 );
assert toFill.equals(new ArrayList<>(List.of( 0 , 0 , 0 , 0 )));
assert IntegerCollections.frequency(toFill, 0 ) == 4 ;
assert IntegerCollections.frequency(set1, - 1 ) == 0 ;
assert IntegerCollections.isSorted(list1);
assert !IntegerCollections.isSorted(list2);
assert IntegerCollections.max(list2) == IntegerCollections.max(set2)
&& IntegerCollections.max(list2) == 6 ;
assert IntegerCollections.min(list1) == IntegerCollections.min(set2)
&& IntegerCollections.min(list1) == 0 ;
assert IntegerCollections.median(set2) == 2 ;
assert IntegerCollections.sum(set1) == 6 ;
assert IntegerCollections.mode(set2) == 0 ;
assert IntegerCollections.mode(List.of( 1 , 1 , 2 , 3 , 1 , 1 )) == 1 ;
assert IntegerCollections.mode(List.of( 1 , 2 , 2 , 1 , 2 )) == 2 ;
}
}
Submission
Submit your source-code file(s) via turnin.
Feedback Robot
This project has a feedback robot that will run some tests on your submission and provide you
with a feedback report via email within roughly one minute.
Please read the feedback carefully.
Due Date and Point Value
Due at 23:59:59 on the date listed on the syllabus.
Assignment 06 is worth 80 points.
Possible point values per category:
-------------------------------------------------------
Correctly implemented methods 80
(roughly evenly distributed)
Possible deductions:
Invalid code style -10%
Other poor practices 1020%
-------------------------------------------------------