Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
10/31/2017- V.1
Recent CodeBins
View All CodeBins
/** * Write a description of class VoteCounter here. * * @author (your name) * @version (a version number or a date) */ public class VoteCounter { private String candidate1; private String candidate2; private int candidate1Votes; private int candidate2Votes; private boolean completed; public VoteCounter(String candidate1, String candidate2) { this.candidate1 = candidate1; this.candidate2 = candidate2; this.candidate1Votes = 0; this.candidate2Votes = 0; this.completed = true; } public String vote(int choice) { if (choice == 1) { this.candidate1Votes++; return "your vote has been cast"; } else if (choice == 2) { this.candidate2Votes++; return "your vote has been cast"; } else { return ("voting is now complete, no further votes will be cast."); } } public void printResults() { double totalVotes = candidate1Votes + candidate2Votes; double candidate1Share = candidate1Votes / totalVotes * 100; double candidate2Share = candidate1Votes / totalVotes * 100; System.out.format("received %3.1f percent of the votes\n", candidate1Share); System.out.format("received %3.1f percent of the votes\n", candidate2Share); if (completed == false) { System.out.println(" No votes have been cast, the results will not be printed"); } else if (completed == false) { System.out.println("Voting is not complete. The results will not be printed."); } else if (completed = true) { System.out.println("Voting is complete. No more votes will be cast."); } } public String getCandidate1() { return this.candidate1; } public String getCandidate2() { return this.candidate2; } public Boolean completed() { return this.completed; } public void completed(boolean completed) { this.completed = completed; } public VoteCounter() { this("CANDIDATE 1", "CANDIDATE 2"); // or could implement as: // this.candidate1 = "CANDIDATE 1"; // this.candidate2 = "CANDIDATE 2"; // this.candidate1Votes = 0; // this.candidate2Votes = 0; // this.completed = false; } }
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
Setting
Validate
Copy
Format
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):