You are on page 1of 5

// Project: Final Project

// 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;

public class KevinMoFinalProject {

public static void main(String[] args) throws EOFException, IOException


{
// TODO Auto-generated method stub
//loops for T or F statements
boolean menuIsOn = true;
boolean eventIsOn = true;
boolean countryPick = true;

//Turn keyboard on
Scanner keyboard = new Scanner(System.in);
Random randomNumber = new Random();

//Array(Scores)
int[][] scores;
scores = new int[2][5];

//Main menu loop


do
{
System.out.println("Welcome to the Skeet Olypmic Final");
System.out.println("A place to watch your favorites suceed!");
System.out.println("Select a numbered option to proceed:");
System.out.println("1. Place you bet");
System.out.println("2. Explanation");
System.out.println("3. No thanks");
int menuOption = keyboard.nextInt();
switch (menuOption) {
//Option loops for selection
case 1:
{
System.out.println("Here we go!");
menuIsOn = false;
break;
}
case 2:
{
System.out.println("This is a place to pick your favorite competitor
from the two countries in the gold medal match");
System.out.println("Each athlete will shoot 5 rounds at 5 targets,
the goal is to pick the athlete that will hit the most targets");
System.out.println("Can be overlooked at as by round or overall");
System.out.println("Select 1 to continue to participate");
break;
}
case 3:
{
menuIsOn = false;
eventIsOn = false;
break;
}
default:
{
System.out.println("Select a number from the corresponding
option");
}

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];
}

//Scores and final winner output


try
{
FileWriter fw = new
FileWriter("/Users/kevinmo/Desktop/GoldMedalScores.txt", true);
PrintWriter outputFile = new PrintWriter(fw);
System.out.println("The overall scores are located in
GoldMedal.Scores.txt");
outputFile.println("Smith:" + SmithTotal + "\nFluet:" +
FluetTotal + "/n");

//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;
}
}
}
}
}

You might also like