I need help with the adding the following to my python code (also provided below)
M5A6Part2
⦁ When a user successfully votes, add the user’s
voterID to the _voterIDsVoted list
⦁ When a user successfully votes, increment the value
of the variable that counts the votes for the candidate the user
voted for. This would be either _candidateAVotes or
_candidateBVotes
Hint: run your original test code again. If you reused a valid
voter ID in your tests it should cause more ‘already voted’
messages to appear.
⦁ Add a registerToVote() method.
This method has 2 parameter variables – self and voterName. We
haven’t yet studied techniques how to link the voter names to their
IDs, so this registerToVote() method will simply add a new valid
voter ID to the _registeredVoters list, print the new voter id, and
also return the new voter ID to the calling code.
To create a valid voter id this method reads the class
lastUsedVoterID value and increments it by 1. It also writes this
incremented lastUsedVoterID value back into the class variable.
⦁ Add a countVotes() method
This method reads the values of the _candidateAVotes and
_candidateBVotes variables and uses them to display
Total votes cast
Votes for A
Votes for B
Either “The winner is candidatesnamefromConstant” or “The race is a
tie”
To test
Create 2 new voters and have both vote for B
Run the countVotes() method
Create another new voter who votes for A
Run the countVotes() method
Create another new voter who votes for A
Run the countVotes() method
Print the value of the class variable _lastVoterID
Print the contents of the instance variable _voterIDsVoted
Print the contents of the instance varaible _registeredVoters
======================================================================================
my code [below]
<===================================== Main Python Code ================================>
## Voting Machine program in Python
# Declaring Class
class VotingMachine():
#class variables
_lastUserVoterID=1110
_candidates=['A','B']
#class constants
CANDIDATE_A='Bob Smith'
CANDIDATE_B='Susan Jones'
def __init__(self):
self._candidateAVotes=0
self._candidateBVotes=0
self._voterIDsVoted=[1100,1101,1104]
self._registeredVoters=[1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110]
## Method with instance variable
#
#
#
def vote(self,voterID,vote):
# checks voterID agisnt _registeredVoters
if voterID in self._registeredVoters:
#checks if VoterID has voted
if voterID not in self._voterIDsVoted:
# Checks to see if supplied vote is vaild and which
Candidate.
if vote in VotingMachine._candidates:
if vote ==VotingMachine._candidates[0]:
print('\nYou have successfully voted for
{0}'.format(VotingMachine.CANDIDATE_A))
self._candidateAVotes+=1
else:
print('\nYou have successfully voted for
{0}'.format(VotingMachine.CANDIDATE_B))
self._candidateBVotes+= 1
self._voterIDsVoted.append(voterID)
else:
print('\nInvalid vote: you must vote for Bob Smith or Susan
Jones.')
else:
print('\nYou cannot vote; you have already voted.')
else:
print('You must register before voting')
<======================================= Test Program ============================>
#
## This program tests the VotingMachine class.
#
# Imports VotingMachine
from M5A6p1x3BergemannK import VotingMachine
## main method
def main():
votingMachine1 = VotingMachine()
votingMachine1.vote(2901, 'A')
votingMachine1.vote(1104, 'A')
votingMachine1.vote(1110, 'A')
votingMachine1.vote(1108, 'B')
votingMachine1.vote(1109, 'C')
## Execute main() function.
if __name__ == '__main__' :
main()

class VotingMachine():
_lastUserVoterID=1110
_candidates=['A','B']
CANDIDATE_A='Bob Smith'
CANDIDATE_B='Susan Jones'
def __init__(self):
self._candidateAVotes=0
self._candidateBVotes=0
self._voterIDsVoted=[1100,1101,1104]
self._registeredVoters=[1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110]
def vote(self,voterID,vote):
if voterID in self._registeredVoters:
if voterID not in self._voterIDsVoted:
if vote in VotingMachine._candidates:
if vote ==VotingMachine._candidates[0]:
print('You have successfully voted for {0}'.format(VotingMachine.CANDIDATE_A))
self._candidateAVotes+=1
else:
print('You have successfully voted for {0}'.format(VotingMachine.CANDIDATE_B))
self._candidateBVotes += 1
self._voterIDsVoted.append(voterID)
else:
print('Invalid vote: you must vote for Bob Smith or Susan Jones.')
else:
print('You cannot vote; you have already voted.')
else:
print('You must register before voting')
def registerToVote(self, voterName):
x = VotingMachine._lastUserVoterID
self._registeredVoters.append(x)
VotingMachine._lastUserVoterID += 1
return x
def countVotes(self):
print('Total votes cast:', (self._candidateAVotes + self._candidateBVotes))
print('Votes for A:', self._candidateAVotes)
print('Votes for B:', self._candidateBVotes)
if self._candidateAVotes < self._candidateBVotes:
print('The winner is', VotingMachine.CANDIDATE_A)
elif self._candidateAVotes > self._candidateBVotes:
print('The winner is', VotingMachine.CANDIDATE_B)
else:
print('The race is a tie')
def main():
vm = VotingMachine()
vm.vote(1000,'B') # invalid voter
vm.vote(1101,'B') # already voted
vm.vote(1105,'C') # invalid candidate
vm.vote(1106,'A') # valid
vm.vote(1107,'A') # valid
vm.vote(1108,'B') # valid
x = vm.registerToVote('Person1')
y = vm.registerToVote('Person2')
vm.vote(x, 'B')
vm.vote(y, 'B')
vm.countVotes()
x = vm.registerToVote('Person3')
vm.vote(x, 'A')
vm.countVotes()
x = vm.registerToVote('Person4')
vm.vote(x, 'A')
vm.countVotes()
print(vm._lastUserVoterID)
print(vm._voterIDsVoted)
print(vm._registeredVoters)
main()
please upvote. Thanks!
I need help with the adding the following to my python code (also provided below) M5A6Part2...
in python, please provide code that can be edit. Create software for a full-service voting machine. The user (voter) supplies a voter ID and the candidate he is voting for. The program checks for The user is a registered voter, by comparing the user's voter ID to a list of valid voter IDs The user has not already voted, by comparing the user's voter ID to a list of voter IDs of people who have already voted The user is...
How do I make my code print out the text in the ServiceNotifier class? Python Code: class ServiceNotifier: #Subject responsible for notifying registered observer objects Observer = [Email, SMS, Phone] def attach(self): #add new observer Observer.append(insertnewobserverhere) def dettach(self): #remove an observer Observer.pop(insertnewobserverhere) def servicenotifier(self): for observers in Observer: print("Due to the forecast for tomorrow, all university and campus operations will be closed.") ...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...
Below is Python code for logic gates. It is written for a specific Circuit. Do the following: 1) Fill in the appropriate If , Else statement for the OrGate ( Look at the AndGate for a hint ) 2) Create two new objects, the NandGate and the NorGate classes. 3) Look at the AndGate class. What does this class inherit and use from the BinaryGate class? class LogicGate: def __init__(self,n): self.name = n self.output = None def getName(self): return self.name...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...
This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...