Question: Objectives: - Building Blocks - Class attributes accessors and mutators - Extracting relevant data and functions from paragraphed written problem I. Exercise: Voting machine class

 Objectives: - Building Blocks - Class attributes accessors and mutators -Extracting relevant data and functions from paragraphed written problem I. Exercise: Voting

Objectives: - Building Blocks - Class attributes accessors and mutators - Extracting relevant data and functions from paragraphed written problem I. Exercise: Voting machine class 1. Designing an electronic voting machine is a challenging task. You are asked to implement a very simplified voting machine class with the following specification. A voting machine has a list of candidates and the following methods: a) addCandidate (String name) / * Add a candidate with the name to the list */ b) castVote (String name) / * Cast a vote to the candidate with the name */ c) printresults () /* Print out the number of votes each candidate has received. The order does not matter Assume that only two attributes of a candidate, namely, the name and number of votes, are of interest here, and the size of the candidate list is unknown in advance 2. Implement the following functions (static methods) on Vector of Integer objects: a) public static boolean sorted(Vector lst) /* Return true if the list is sorted in ascending order; otherwise, false. */ b) public static int sum (Vector lst) / * Return the sum of the elements in the list. */ c) public static LinkedList replace (Vector lst, Integer o, Integer n) f Return a copy of the given list, replacing all occurrences of o with n. Use equals to test equality*/ II. Exercise: Date class Write a ThreeWayLamp class that models the behavior of a lamp that uses a three-way bulb. These bulbs have four possible states: off, low light, medium light, and high light. Each time the switch is activated, the bulb goes to the next state (from high, the next state is off, from off to low etc). The ThreeWayLamp class has a single method called switch() which takes a single int parameter indicating how many times the switch is activated. (you need to throw an exception if its negative). The switch() method should simply print out to System.out a message indicating the state of the bulb after it has changed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!