Java|Comp2402 A4 PartB

这是一个加拿大的Java编程作业作业
Purpose & Goals
Generally, the assignments in this course are meant to give you the opportunity to practice with the topics of this course in a way that is challenging yet also manageable. At times you may struggle and at others it may seem more straight-forward; just remember to keep trying and practicing, and over time you will improve.

Specifically, assignment 4 aims to improve your understanding of the (Unsorted) Set interface and sorting algorithms by:

Using the Hashtable, HashMap, sorting algorithms, and any interfaces from previous assignments to solve a variety of problems (Part A),

Implementing some new methods in the MyStrictHT, and HCPracticeclasses (Part B)

Part B: The Implementation

The (provided) StrictHTand MyStrictHTclasses are implementations of the Set interface via a hashtable that has a strict/constant number of buckets (as opposed to our usual kind that adds more buckets as the load of the hashtable hits a certain threshold.) StrictHTis the basic implementation that you do not and should not modify. MyStrictHTis a child class of StrictHTthat you can and should modify in order to better implement the Set interface (with regards to time). More details below in question 5. The Personclass (within the HCPracticeclass) is an (incomplete) implementation of the Personclass, in that it will not allow us to correctly create a Set of Persons without duplicates. Your task is to complete its implementation so that we can create such a Set. More details below in question 6. Default implementations are provided for both questions 5 and 6, but they will not pass the server tests.

[14 marks] In the MyStrictHTclass, make changes to any of the StrictHTnon-final methods (by overriding them in MyStrictHT) as you see fit in order to pass the (time) performance server tests. MyStrictHTis a child class of StrictHT, so it will compile and run and be correct right out of the gate; the default implementation, however, will not pass the server performance tests because it is too slow. Your task is to determine what makes the methods so slow in this “strict” setting, and make improvements.

Note that some inherited methods and variables are final so that they cannot be changed; this is on purpose to try to prevent you from taking certain shortcuts I don’t want you to take. Anything that is not final can be overridden in MyStrictHTand implemented as you see fit. Do not make changes to StrictHT, as a local copy (not yours) will be used on the server.

Also note that the main methods in StrictHTand MyStrictHTare the same, and they start off by taking ~10s each (on Prof Alexa’s local machine.) The fastest implementation I have can run these tests in <2s, for reference, and a ~5s solution will pass most, if not all, server tests. This is a more open-ended question than we’re used to; this is intentional! It’s meant to give you flexibility to apply one of many possible solutions, so try to relax and think critically about the existing code and how you can improve upon it. If it helps, I will only test this on types T that are Comparable (e.g. Integers, Strings). If you want to run MyStrictHT.mainwith the assertions, use the -eaparameter, e.g. % java -ea comp2402w22a4.MyStrictHT [13 marks] In the Personclass (within the HCPracticeclass), implement the equalsand hashCodemethods so that we can correctly store a Set of Personswithout duplicates, that is, we want to be able to add, remove, and find distinct Persons. Each Person has 4 characteristics: fname– first name – we assume this is constant over the course of the program lname– last name – we assume this is constant over the course of the program birthYear– year of birth – we assume this is constant (!!) luckyNumber– a person’s lucky number, if they even have one. This can change over the course of the program There are some basic tests in the HCPractice.mainthat you should examine and play around with. If you want to run HCPractice.mainwith the assertions, use the -ea parameter, e.g. % java -ea comp2402w22a4.HCPractice

发表评论

了解 KJESSAY历史案例 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读