Write a program that will record the votes for one of two candidates by using the class VoteRecorder, which you will design and create. Vote Recorder will have static variables to keep track of the total votes for candidates and instance variables to keep track of the votes made by a single person. It will have the following attributes.
- nameCandidatePresident11—a static String that holds the name of the first candidate for president
- nameCandidatePresident2—a static string that holds the name of the second candidate for president
- nameCandidateVicePresident1 —a static string that holds the name of the first candidate for Vice president
- nameCandidateVicePresident2—a static string that holds the name of the second candidate for Vice president
- votesCondidatePresident1—a static integer that holds the number of votes for the first candidate for president
- votesCandidatePresident2—a static integer that holds the number of voles for the second candidate for president
- votesCandidateVicePresident1—a static integer that holds the number of votes for the first candidate for Vice president
- votesCandidateVicePresident2—a static integer that holds the number of rates for the second candidate for Vice president
- myVoteForPresident—an integer that holds the vote of a single individual for president (0 for no choice, 1 for the first candidate, and 2 for the second candidate)
- myVoteForVicePresident—an integer that holds the vote of a single individual for vice president (0 for no choice, 1 for the first candidate, and 2 for the second candidate)
In addition to appropriate constructors, VotRecorder has the following methods:
- setCandidaterPresident(String name1, String name2)—a static method that sets the names of the names of the two candidates for president
- getCandicateoVicePresident (String name1, string name2)—a static method that sets the names of the two candidates for vice president
- resetVotes—a static method that resets the vote counts to zero
- getCurrentVotePresident—a static method that returns a string with a current total number of votes for both presidential candidates
- getAndConfirmVotes—a non-static method that gets an individual’s votes, confirms then, and then records them
- getAVote(String name1, string name2)—a private method that returns a vote choice for a single race from a individual (0 for no choice, 1 for the first candidate, and 2 for the second candidate)
- getVotes—a private method that returns a vote choice for president and vice president from an individual
- confirmVotes—a private method that displays a person’s vote for president and vice president, asks whether the voter is happy with these choices, and returns true or false according to a yes-or-no response
- recordVotes—a private method that will add an individual’s votes to the appropriate static variables
Create a program that will candidates an election. The candidates for president are Annie and Bob. The candidates for vice president are John and Susan. Use a loop to record the votes of many voters. Create a new Vote Recorder object for each voter. After all the voters are done, present the results.
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting out with Visual C# (4th Edition)
Absolute Java (6th Edition)
C How to Program (8th Edition)
Starting Out with Java: Early Objects (6th Edition)
- Create the StockTask1 Java project Create a Stock object class that contains the following information: The symbol of the stock is stored in a private string data field called symbol. The stock's name is stored in a private string data field called name. previousClosingPrice is a private double data area that stores the stock price for the previous day. currentPrice is a private double data area that stores the stock price at the current time. A constructor for creating a stock with the given symbol and name. For the data fields, there are accessor methods (get-methods). For the data fields, there is a mutator method (set-methods). A method named getChangePercent()that returns the percentage changed from previousClosingPrice to currentPrice. Formula:perc_change = (current price - previous closing price) / previous closing price x 100 Create a test class named testStockthat creates a Stockobject with the stock symbol SUNW, the name Sun Microsystems Inc., and the previous closing…arrow_forwardPYTHON ONLY PLZZZ Create a class object with the following attributes and actions: Class Name Class number Classroom Semester Level Subject Actions: Store a class list Print the class list as follows: Class name Class Number Semester Level Subject Test your object: Ask the user for all the information and to enter at least 3 classes test using all the actions of the object print using the to string action Describe the numbers and text you print. Do not just print numbers or strings to the screen explain what each number represents.arrow_forwardIn python Add the following four methods to your Crew class: move(self, location): This takes in a location as a string, along with self, and attempts to move the crew member to the specified location. If location is one of the five valid location options ("Bridge", "Medbay", "Engine", "Lasers", or "Sleep Pods"), then this should change self.location to that new value. Otherwise, the function should print out the message: Not a valid location. repair(self, ship): first_aid(self, ship): fire_lasers(self, ship, target_ship, target_location): The above three methods represent tasks that a basic Crew member is not capable of (but one of its derived classes will be able to accomplish). So each of them should simply print out a message of the form: <Name> doesn't know how to do that. Examples: Copy the following if __name__ == "__main__" block into your hw12.py file, and comment out tests for parts of the class you haven’t implemented yet. if __name__ == '__main__': crew1…arrow_forward
- Please answer this in python Define a class in python named BoatRace that contains the following information about a Boat Race: race_name: string race_id: int distance: int racers: List of Boat objects Write a constructor that allows the programmer to create an object of type BoatRace with a race_name, race_id, list of racers objects, and distance. The constructor will only take in one parameter, a string representing the name of a CSV file. The file will have the following format: Each row will always have exactly two columns. The first row will always contain the name of the race. The second row will always contain the id number for the race. The third row will always contain the distance for the race. All remaining rows contain information about the boats involved in the race: the first column will be the name of the boat, and the second column is that boat’s top speed. For example, the race in the file below has two boats: The Fire Ball with top speed 12, and The Leaf with…arrow_forwardDescriptionIn this assignment, you are required to implement an electronic programming quiz system. User can createquestions and preview the quiz.Your TaskYou are asked to write a Java program for the programming quiz system. There are two types of questions:Multiple Choice Question and Ture/False Question. User can create questions using the system; andpreview the quiz, which display all questions in the system one by one. During the preview, the user canattempt the quiz by entering his/her answers to questions. The system will then immediately check theanswer and calculate. After attempting all questions, the total score will be displayed. A sample run of theprogram is shown as below (Green text refers to user input): Please choose (c)reate a question, (p)review or (e)xit >> cEnter the type of question (MC or TF) >> MCEnter the question text >> Each primitive type in Java has a correspondingclass contained in the java.lang package. These classes are called…arrow_forwardA mountain climbing club maintains a record of the climbs that its members have made. Information about a climb includes the name of the mountain peak and the amount of time it took to reach the top. The information is contained in the ClimbInfo class as declared below. The ClimbingClub class maintains a list of the climbs made by members of the club. The declaration of the ClimbingClub class is shown below. You will write implementations of the addClimb method. import java.util.List; import java.util.ArrayList; class ClimbInfo { private String name; private int time; /** Creates a ClimbInfo object with name peakName and time climbTime. * * @param peakName the name of the mountain peak * @param climbTime the number of minutes taken to complete the climb */ public ClimbInfo(String peakName, int climbTime) { name = peakName; time = climbTime; } /** @return the name of the mountain peak */ public String getName() { return name; } /** @return the number of minutes…arrow_forward
- PYTHON Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Once you have written the class, write a program that creates three Employee objects to hold the following data, then save the data in (employee.txt) filearrow_forwardDefine a class called StringFormatter. The purpose of an object of this class is to store a string variable (you may use the C++ string type or a char array). An object of this class can be created by calling a constructor that accepts one string argument. The string to be passed as argument will be a long line of text, such as “The world is indeed full of peril and in it there are many dark places. But still there is much that is fair. And though in all lands, love is now mingled with grief, it still grows, perhaps, the greater.” The object will also have a function called printRightAligned() which accepts one integer argument n. The value of the argument represents the maximum number of characters that can be displayed on a line. This function displays the string stored in the object’s attribute on the screen, right aligned and with no more than n characters per line. Similarly, there should be a function called printLeftAlgigned() which displays the text left aligned, again, with no…arrow_forwardPlease help me with this Java Labarrow_forward
- Computer Science You are required to develop a small chatting application where two or more friends can communicate each other through messages. Create a class Message which has Date d, and message (string). Provide getters/setters, constructors, toString. Create a class Friend having String name, String contact, email and ArrayList of Messages provide getters/setters, constructors, toString addMessage(Message m) method which will add new message to the list. Provide following options to the user using JFrame. Login which will help user login to the application. View Friends (Display List of All Friends) View Messages ( This should display all message of a Friend) Send message (This should ask for friend name and message match the friend name and write that message to the array list).arrow_forwardFor your homework assignment, build a simple application for use by a local retail store. Your program should have the following classes: Item: Represents an item a customer might buy at the store. It should have two attributes: a String for the item description and a float for the price. This class should also override the __str__ method in a nicely formatted way. Customer: Represents a customer at the store. It should have three attributes: a String for the customer's name, a Boolean for the customer's preferred status, and a list of 5 indexes to hold Item objects. Include the following methods: make_purchase: accepts a String and a double as parameters to represent the name and price of an item this customer is purchasing. Create a new Item object with this info and append it to the internal list. If the customer is a preferred customer based on the Boolean attribute's value, take 10% off the total sale price. __str__: Override this method to print the customer's name and every…arrow_forwardWrite a program that creates a class named “sentence”. The class has a string data member called data and another called size that shows the number of characters of the string. Create setter/getter and display function. Create a constructor that initializes the class objects. Also create a copy constructor that copies the data of one object to the other. Call all functions in main and display outputarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT