联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-06-03 11:07

2019/6/1 Assignment 06: A Utility Class for Integer Collections [cmps11s19]

https://jeff.cis.cabrillo.edu/classes/cmps11s19/assignments/assignment_06 1/3

cmps11s19

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

2019/6/1 Assignment 06: A Utility Class for Integer Collections [cmps11s19]

https://jeff.cis.cabrillo.edu/classes/cmps11s19/assignments/assignment_06 2/3

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.

2019/6/1 Assignment 06: A Utility Class for Integer Collections [cmps11s19]

https://jeff.cis.cabrillo.edu/classes/cmps11s19/assignments/assignment_06 3/3

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 10–20%

-------------------------------------------------------

assignments/assignment_06.txt · Last modified: 2019-05-11 16:51 by Jeffrey Bergamini


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp