A common feature of political debates is real time polling, where members of the audience can enter positive and negative responses to debate points, and these responses are aggregated and displayed on the screen as they are entered. For this assignment, you are to design and implement a class that keeps track of an individual viewer's responses during a debate. The viewer enters a response as a real number, either positive or negative, with the number size denoting the intensity of the response. For example, a response of 1.0 might be viewed as a mildly positive response, while 5.0 is an extremely positive response. Similarly, -5.0 might be viewed as an extremely negative response.
A skeleton for the RealTimePoll class is provided for you. It does not contain any fields and the methods are empty (or return a default value if required). You are to add appropriate fields to the class and implement the methods to carry out the designated tasks. The methods are:
recordResponserecords a response, a real number, which is provided as a parameter. For example, given a
poll, the call
poll.recordResponse(2.0)would record a response of 2.0, while
poll.recordResponse(-1.0)would record a response of -1.0.
getAveragereturns the average of all the responses entered so far. For example,
poll.getAverage()would return 0.5 (assuming the two recorded responses above). The average should be rounded to one digit to the right of the decimal place. For example, the average of response values 1.0, 1.0 and 3.0 would be 1.7.
getMinimumreturns the minimum of all the responses entered so far. For example,
poll.getMinimum()would return -1.0 (assuming the two recorded responses above).
getMaximumreturns the maximum of all the responses entered so far. For example,
poll.getMaximum()would return 2.0 (assuming the two recorded responses above).
resetresets the average and all related statistics, allowing for a new poll to begin.
getMaximum should all return 0.0 if called before any actual responses are recorded.
It is strongly recommended that you develop and test your class in stages. For example,
first specify the fields and constructor, then use BlueJ to create an object and inspect
its fields to make sure they are correct. Next, implement and test the
getAverage methods, making sure that you can record a response and calculate the average. Finally, move on to the
Once you have fully tested your class, you can download the file
and add it to your BlueJ project. The
PollGUI class defines a graphical
user interface (GUI) that allows you to enter responses concerning either debater by dragging a slider, and then see the stats automatically updated.
Once you have compiled this class, you can open up an interface window by
right-clicking and selecting
RealTimePoll.javafile via BlueLine2.