Write a class called Candidate to store details of a candidate in the election. The class must define fields to store the following details: ● The name of the candidate. The value will be a String which will always have a length of at least 1 character. The number of votes the candidate has received. This is an integer value. The value will always be greater-than or equal to zero. The class must have a single constructor that takes the name of a candidate. You do not need to check that the value passed to the constructor is valid. You may assume that it always will be. In other words, you may assume that the name String will be at least one character long. The initial value of votes must always be zero when the object is constructed and it is not passed as a parameter to the constructor.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a class called Candidate to store details of a candidate in the election.
The class must define fields to store the following details:
The name of the candidate. The value will be a String which will
always have a length of at least 1 character.
The number of votes the candidate has received. This is an integer
value. The value will always be greater-than or equal to zero.
The class must have a single constructor that takes the name of a candidate.
You do not need to check that the value passed to the constructor is valid.
You may assume that it always will be. In other words, you may assume that
the name String will be at least one character long. The initial value of votes
must always be zero when the object is constructed and it is not passed as a
parameter to the constructor.
The class must define the following methods:
• An accessor (get) method for each field.
Transcribed Image Text:Write a class called Candidate to store details of a candidate in the election. The class must define fields to store the following details: The name of the candidate. The value will be a String which will always have a length of at least 1 character. The number of votes the candidate has received. This is an integer value. The value will always be greater-than or equal to zero. The class must have a single constructor that takes the name of a candidate. You do not need to check that the value passed to the constructor is valid. You may assume that it always will be. In other words, you may assume that the name String will be at least one character long. The initial value of votes must always be zero when the object is constructed and it is not passed as a parameter to the constructor. The class must define the following methods: • An accessor (get) method for each field.
●
●
A method called voteFor that adds 1 to the votes field.
A method called print to print the values of the fields on a single line
in exactly the following format:
Dodgy Drew has 5 votes.
where "Dodgy Drew" is an example of a String in the name field and 5
is an example of the current value in the votes field. Each Candidate
object will have its own particular values for these fields.
Transcribed Image Text:● ● A method called voteFor that adds 1 to the votes field. A method called print to print the values of the fields on a single line in exactly the following format: Dodgy Drew has 5 votes. where "Dodgy Drew" is an example of a String in the name field and 5 is an example of the current value in the votes field. Each Candidate object will have its own particular values for these fields.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education