Question
Create a system with three classes: 1. Create a Candidate class ( Candidate.java ) with four private fields: firstName, lastName, party, and trustworthy (with types:
Create a system with three classes:
1. Create a Candidate class (
Candidate.java
) with four private fields: firstName,
lastName, party, and trustworthy (with types: String, String, char, and boolean,
respectively).
o
Create a single constructor that accepts parameters for first name, last name,
party, and trustworthy.
o
The first name and the last name are read only. The other two fields have both
accessors and mutators.
2. Create an Election class (
Election.java
) that manages a list of all candidates in the
upcoming election.
o
This class should have a private field, of type array, that will hold all of the
candidates.
o
Provide a single constructor that accepts no parameter, and creates a
Candidate array with size of 0.
o
Provide support to add a candidate.
o
Provide support to display all candidates.
3. Create an ElectionTest class (
ElectionTest.java
) with two methods:
o
main (the standard entry point) should call a private method createElection
(see below), and then display all candidates in the election.
o
createElection() should return an Election object:
?
Create an Election object.
?
Create at least three Republican (R) candidates with only the first one
being trustworthy and add each to the election.
?
Create at least three Democrat (D) candidates with only the first one
being trustworthy and add each to the election.
The output should look similar to the following:
Some of the major candidates in the upcoming election are:
First Name
Last Name
Party
Trustworthy
--------------------------------------------
Donald
Trump
R
true
Ben
Carson
R
false
Jeb
Bush
R
false
Hillary
Clinton D
true
Bernie
Sanders D
false
Jim
Webb
D
false
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