Professional Documents
Culture Documents
Programming Final
Programming Final
// Author: Kevin Mo
// GitHub: kevinmo48
// Description: Final Program
// Date: Dec. 1, 2019
// Version: 1.0
import java.util.Scanner;
import java.util.Random;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.EOFException;
//Turn keyboard on
Scanner keyboard = new Scanner(System.in);
Random randomNumber = new Random();
//Array(Scores)
int[][] scores;
scores = new int[2][5];
while (menuIsOn);
//Country options and selection
while (eventIsOn)
{
//Internal method to select country/athlete initially
while (countryPick)
{
System.out.println("Enkoy the event and remember to play
responsibly!");
System.out.println("Below are the athletes vying for the
Gold medal!");
System.out.println("Which country do you believe will be
the best?");
System.out.println("1. Ben Smith of the USA");
System.out.println("2. Matt Fluet of Canada");
int country = keyboard.nextInt();
switch (country)
{
case 1:
//Athlete chosen in round 1 is Ben Smith
{
for (int roundSmith = 0; roundSmith <= 4;
roundSmith++)
{
//Choosing athlete for round 1 of the match
System.out.println("Which athlete do you
think will win the round " + (roundSmith + 1) + "?");
System.out.println("Select 1 for Smith and 2
for Fluet");
int athlete = keyboard.nextInt();
// Choosing for each round
switch (athlete)
{
case 1:
scores[1][roundSmith] =
randomNumber.nextInt(5);
break;
default:
System.out.println("Please
choose one of the two competitors");
break;
}
scores[0][roundSmith] =
randomNumber.nextInt(5);
}
countryPick = false;
break;
}
case 2:
{
for (int roundFluet = 0; roundFluet <= 4;
roundFluet++)
{
//Choosing athlete for round 1 of the match
System.out.println("Which athlete do you
think will win the round " + (roundFluet + 1) + "?");
System.out.println("Select 1 for Smith and 2
for Fluet");
int athlete = keyboard.nextInt();
//Choosing for each round
switch (athlete)
{
case 1:
scores[1][roundFluet] =
randomNumber.nextInt(5);
break;
default:
System.out.println("Please choose
one of the two competitors");
break;
}
scores[0][roundFluet] =
randomNumber.nextInt(5);
}
countryPick = false;
break;
}
default:
{
System.out.println("Select the from the two finalists!
");
break;
}
}
}
int innings = 1;
double SmithTotal = 0;
double FluetTotal = 0;
System.out.println("\nSmith\tFluet");
//Final Scores
for (int inning = 0; inning<scores[0].length; inning++)
{
System.out.println(scores[0][inning] + "\t\t" + scores[1]
[inning]);
//Scores for every round
SmithTotal += scores[0][inning];
FluetTotal += scores[0][inning];
}
//Winner Announced
if (SmithTotal>FluetTotal)
{
outputFile.println("Ben Smith of the USA has won
the gold medal!");
}
if (FluetTotal>SmithTotal)
{
outputFile.println("Matt Fluet of Canada has won
the gold medal!");
}
outputFile.close();
}
catch (FileNotFoundException p)
{
System.out.println("The file was NOT found");
System.out.println("Error:" + p.getMessage());
}
catch (EOFException p)
{
System.out.println("The file was too large");
System.out.println("Error:" + p.getMessage());
}
catch (IOException e)
{
System.out.println("Error:" + e.getMessage());
}
eventIsOn = false;
}
}
}
}
}