Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java program to do the above requirements The Olympics will begin this summer an

ID: 3665484 • Letter: J

Question

Java program to do the above requirements

The Olympics will begin this summer and several countries will clamor to find out who will win the medal count. However, there are two ways of scoring the games. The first way is called the "American" method. In this method the scoring is based on the number and type of medals a country has won. Gold medals count the most, silver is used to break ties and finally bronze medals are looked at if a country has the same number of gold and silver Several countries (who usually score fewer gold medals) use the "Canadian" method of scoring instead of the "American" method. Using the "Canadian" method the total number of overall medals determines the winner of the Olympics, Write a Java program that computes the medal winner for the Olympic Games. Do the following: Ask the user what scoring method they would like to use to score the Olympics (a character). Prompt the user for the number of countries competing in the current Olympics. Read in the country names and their medal count. Print out the name of the winning country. In case of a tie, print out the winning countries in input order. Error check. Output should look similar to below. Sample Runs: Please enter the scoring method. A)merican or C)anadian -> a Number of countries competing? 3 Please enter country and medal count> Germany 3 2 1 Please enter country and medal count> America 2 3 1 Please enter country and medal count> Canada 12 4 The winner is: Germany with 3 gold medals, 2 silver medals, 1 bronze medal Please enter the scoring method. A)merican or C)anadian C Number of countries competing? 3 Please enter country and medal count> Germany 3 2 1 Please enter country and medal count> America 2 3 1 Please enter country and medal count> Canada 124 The winner is: Canada with 1 gold medal, 2 silver medals,4bronzemedals Name the program: OlympicMedals. Java, where XX are your initials.

Explanation / Answer

Can help you with this


import java.io.*;
class Olympics
{
public static void main(String[] args) throws IOException
{
System.out.println("**** Olympic medals ****");
System.out.println();
BufferedReader in = Text.open(System.in);
BufferedReader fin = Text.open(System.in);
String filename = "";
for (;;)
{
try
{
System.out.print("What file for the medals statistics?");
filename = Text.readString(in);
fin = Text.open(filename);
break;
}
catch (FileNotFoundException e)
{
System.out.println(filename+" does not exist.");
System.out.println("Try again");
}
}
String country;
int gold, silver, bronze, total, all = 0;
System.out.println(" Country Gold Silver Bronze Total");
try
{
for (;;)
{
country = Text.readString(fin);
gold = Text.readInt(fin);
silver = Text.readInt(fin);
bronze = Text.readInt(fin);
total = gold + silver + bronze;
System.out.print(country);
if (country.length() < 8)
System.out.print(" ");
System.out.println(" "+gold+" "+silver+" "+bronze+" "+total);
all += total;
}
}
catch (EOFException e)
{
System.out.println(all+" medals won.");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote