Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Voter.java
public class Voter {
//Declaring instance variables
private String name;
private char party;
//Parameterized constructor
public Voter(String name, char party) {
this.name = name;
this.party = party;
}
// getters
public char getParty() {
return party;
}
//toString method is used to display the contents
of an object inside it
@Override
public String toString() {
return "Voter [name=" + name + ",
party=" + party + "]";
}
}
__________________________
// Test.java
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
ArrayList<Voter> voters =
new ArrayList<Voter>();
Voter v1 = new Voter("Lelbowitz",
'D');
Voter v2 = new Voter("Billy",
'D');
Voter v3 = new Voter("Bowles",
'R');
voters.add(v1);
voters.add(v2);
voters.add(v3);
for (int i = 0; i <
voters.size(); i++) {
if
(voters.get(i).getParty() == 'D') {
System.out.println(voters.get(i));
}
}
}
}
_________________________
Output:
Voter [name=Lelbowitz, party=D]
Voter [name=Billy, party=D]
_______________Could you plz rate me well.Thank
You
ISu a The paradox d I ata fields (or mputers. Program 3 Assume the existence of a class called Vo...