0% found this document useful (0 votes)
130 views3 pages

E2.3 - CPSC 210 - PrairieLearn

The document describes a class called Target that represents climate change agreements. Target has three fields: agreement, carbonLevels, and timespan. It discusses how the equals and hashCode methods should be implemented for the Target class. For equals, it must compare the agreement and carbonLevels fields, but can ignore timespan. For hashCode, it may consider agreement and carbonLevels but must not consider timespan.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views3 pages

E2.3 - CPSC 210 - PrairieLearn

The document describes a class called Target that represents climate change agreements. Target has three fields: agreement, carbonLevels, and timespan. It discusses how the equals and hashCode methods should be implemented for the Target class. For equals, it must compare the agreement and carbonLevels fields, but can ignore timespan. For hashCode, it may consider agreement and carbonLevels but must not consider timespan.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 3: COP 210

Consider the domain of climate change agreements. Nations set targets that become parts of agreements.
Assume
the class Target has three fields agreement, carbonLevels, and timespan.
We want to implement equals in Target.
Two Targets should be equal as long as their agreement and carbonLevels
are the same, regardless of whether their
timespan is the same.

Given this, select each of the following that must be part of the code for the Target.equals method:
(a) refer to this.agreement
(b) declare its parameter's type to be Target
(c) refer to its parameter's timespan
(d) refer to its parameter's carbonLevels
(e) have an explicit REQUIRES for the parameter to be non-null
(f) cast its parameter's type to Target
(g) have an implicit REQUIRES for the parameter to be non-null
(h) refer to this.carbonLevels
(i) refer to its parameter's agreement
(j) refer to this.timespan
Select all possible options that apply.
100%
Now, select each of the following that the hashCode method must, may, or must not use to influence its return
value. (Must means "is required to", may means "can but is not required to", and must not means "is required not to".)
hashCode must 0% use this.agreement
hashCode must 0% use this.carbonLevels
hashCode may 0% use this.timespan

This question is complete and cannot be answered again.

Correct answer
Given this, select each of the following that must be part of the code for the Target.equals method:
(a)
refer to this.agreement
(d)
refer to its parameter's carbonLevels
(f)
cast its parameter's type to Target
(h)
refer to this.carbonLevels
(i)
refer to its parameter's agreement
Now, select each of the following that the hashCode method must, may, or must not use to influence its return
value. (Must means "is required to", may means "can but is not required to", and must not means "is required not to".)
hashCode may use this.agreement
hashCode may use this.carbonLevels
hashCode must NOT use this.timespan

Submitted answer
4 hide
Submitted at 2022-11-07 18:43:35 (PST) 50%

Given this, select each of the following that must be part of the code for the Target.equals method:
(a)
refer to this.agreement
(d)
refer to its parameter's carbonLevels
(f)
cast its parameter's type to Target
(h)
refer to this.carbonLevels
(i)
refer to its parameter's agreement
100%
Now, select each of the following that the hashCode method must, may, or must not use to influence its return
value. (Must means "is required to", may means "can but is not required to", and must not means "is required not to".)
hashCode must 0% use this.agreement
hashCode must 0% use this.carbonLevels
hashCode may 0% use this.timespan

Submitted answer
3 show
Submitted at 2022-11-07 18:37:53 (PST) saved, not graded

Submitted answer
2 show
Submitted at 2022-11-07 18:12:46 (PST) saved, not graded

Show/hide older submissions

Exam 2
Assessment overview

Question
Submission status: 50%
Total points: 12.5 /25
Auto-graded question
Report an error in this question

Previous question Next question

Attached files
No attached files
Attachments can't be added or deleted because the assessment is closed.

You might also like