CSE116的学习笔记-Lec3-6:Immutability
Just the Lecture Question!!!
Lecture Question
Restriction:
No state is allowed in this question. Specifically, the keyword “var” is banned
Question:
In a package named “functions” write a class named VoteCounter with the following features:
- Has a constructor that takes a List of Strings representing all votes that have been cast
- A method named “castVote” that takes a String as a parameter representing a vote for a candidate and returns a new VoteCounter with this vote added to the List of votes
- A method named “submitVotes” that takes a String representing a candidate to vote for and an Int representing the number of votes to cast for that candidate and returns a new VoteCounter with these votes added
- A method named “countVotes” that takes a String representing a candidate and returns the number of votes cast for that candidate
Testing:
In a package named “tests” create a class named “TestVoteCounter” as a test suite that tests all the functionality listed above
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment
TwikooValine