I need to finish this assignment by tonight. I have been working on it for the last five hours and I am completely stuck.
Any help would be greatly appreciated! I have already talked to my teacher, but she is awful. No help at all.
This is what I have to do.
Write a test program that counts votes for two candidates for student body president. The votes are entered from the keyboard. Number 1 is a vote for Candidate 1, and number 2 is a vote for Candidate 2. Number -1 deducts a voter from Candidate 1, and number -2 deducts a vote from Candidate 2. Number o signifies the end of the count. Display the name and votes for each candidate and the student body president.
Here is what I have so far.
import javax.swing.JOptionPane;
public class test {
public static void main(String[] args) {
//int count =0;
int tracker = 0;
Vote test = new Vote();
Candidate names = new Candidate();
while( tracker < 5) {
String enterVote = JOptionPane.showInputDialog(" Enter 1 to vote for candidate One or Two to vote for candidate Two \n press 0 to quit." + tracker++);
int stringValue = Integer.parseInt (enterVote);
// test.increment();
// System.out.println(test.getCount());
//Vote updateCount = new Vote();
// System.out.println(stringValue);
if (stringValue == 1){
test.increment();
System.out.println(test.getCount());
}
else{ test.decrement();
{
}
System.out.println(test.getCount());
}
}
class Vote {
int count ;
Vote()
{
count = 0;
}
int getCount(){
return count;
}
void setCount (int newCount){
count = newCount;
}
void clear (){
count = 0;
}
void increment(){
count++;
}
void decrement (){
count--;
}
//end class vote
class Candidate {
int numberOfCandidates = 0;
String name = "";
Vote vote = new Vote();
Candidate(){
numberOfCandidates++;
}
Candidate(String newname, Vote newvote){
name = newname;
vote = newvote;
}
String getname() {
return name;
}
int getVote(){
return vote.getCount();
}
int getNumberofCandidate(){
return numberOfCandidates;
}
}
}
}
}