[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 1.73 MB, 2592x1936, IMG_0672.jpg [View same] [iqdb] [saucenao] [google]
5721105 No.5721105[DELETED]  [Reply] [Original]

in Java how do you create a method that will prompt the user to type in 10 votes to determine a winner in a two candidate election?
Ex: Vote 10 times - Smith vs. Watson

User enters:
Watson
watson
wATson
Smith
SMITH
smiTh
watson
smith
watson
waTSoN
And then this should report that Watson wins 6 votes to 4 votes.
the names dont have to be Watson and Smith, any two names will do.

>> No.5721139

.

>> No.5721198

>>5721105

Create several methods. One to prompt for the votes, one to take in the votes, one to process the votes/determine a winner. Create every section separately, and debug them as you go. If you don't know how to write methods, look back on your notes, there are also some great lectures on youtube.

>> No.5721204

convert all the inputs to upper or lower case to make it easier

>> No.5721207

>>5721204
something I forgot to mention.

make sure you format everything to make it easier on you and the user. cover all your bases to make sure input/output will work correctly.

>> No.5721216

>>5721105
>in Java
reported

>> No.5721225

#include <OPISFAG>
#include <iostream>
#include <string>
using namespace std;

int main()
{
int cand1 = 0;
string fag1 = "OP";
string fag2 = "faget";
int cand2 = 0;
string uwot;

for(int i=0;i<10;i++)
{
cout << "WHO U VOTE 4???" << endl;
cin >> uwot;
if (uwot == fag1) cand1++;
else cand2++;
}
if (cand1 > cand2) cout << fag1 << " wins weee!!111";
else cout << fag2 << " wins weee@!!11";
system("PAUSE");
return 0;
}

now write it in your poopy language

>> No.5721229

>>5721105
we're not doing your homework

Also, "if you try to solve a problem using regular expressions, you'll now have 2 problems".

>> No.5721231

>>5721225
lold

>> No.5721228

>>5721216
because it's java?

>> No.5721248

>>5721225
>system("PAUSE");

Fucking kill yourself, you pretentious wanna be. Learn to program.

>> No.5721258

da fuck is all this? and who the fuck is the fucking reporter?

>> No.5721267

>>5721258
This isn't the place to come for homework help. This is a discussion board.

>> No.5721263

"quote your own mother fucking ass." (Dick).

>> No.5721275
File: 210 KB, 1024x768, 1364158782401.jpg [View same] [iqdb] [saucenao] [google]
5721275

>>5721228
yes, mindless java/cs code monkeying belongs in >>>/g/ not /sci/

>> No.5721285

>>5721275
Understandable. I see too many matlab/python/java threads here. I agree that /g/ would be a better fit.