Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started