Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java Write a method named classPresidents that tallies votes for presidents of two school classes. Somehow the vote tallies for sophomore and junior class

Using Java Write a method named classPresidents that tallies votes for presidents of two school classes. Somehow the vote tallies for sophomore and junior class presidents got mixed up! Your method should accept as its parameter a Scannerrepresenting a file of vote results. It should output the next sophomore and junior class presidents. The file format looks like the following:

Jared s 25 Sophie j 12 Tom j 44 Isaac s 30 Emily s 60 Russ s 23 Madison j 20

The file repeats the patternnameyearvotes. The year is either "s" for sophomore or "j" for junior. Your program should output the candidate in each presidential race with the most votes, and how many votes they got. Specifically, if this file were named candidates.txt, your method could be called in the following way:

Scanner input = new Scanner(new File("candidates.txt"));classPresidents(input);

The above call should produce the following output:

Sophomore Class President: Emily (60 votes)Junior Class President: Tom (44 votes)

You may assume that there are no ties and that each class has one single person who received the most votes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Probability And Statistics

Authors: William Mendenhall, Robert Beaver, Barbara Beaver

14th Edition

9781133103752

Students also viewed these Programming questions

Question

What are the two major components of error control?

Answered: 1 week ago

Question

Difference between truncate & delete

Answered: 1 week ago