Question

In: Computer Science

Write a program (C++) which allows a League of Legends player to both store and output...

Write a program (C++) which allows a League of Legends player to both store and output statistics on their games played. When the program starts it allows the user to enter new entries. The entries contain the following information: Champion Name Kills Assists Deaths Win? Each entry is appended to a file called games.txt. When the user is done entering data the statistics from the games in the file are to be displayed. The average kills, assists, and deaths are to be displayed with the percentage of wins to be displayed.

Solutions

Expert Solution

Here is the solution of the above problem in java. Save the file with name Main.java and run javac Main.java . To get output run java Main.

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Player {
//Champion Name Kills Assists Deaths Win
String championName;
Integer kills;
Integer assists;
Integer deaths;
Integer wins;

Player(String championName, Integer kills, Integer assists, Integer deaths, Integer wins) {
this.championName = championName;
this.kills = kills;
this.assists = assists;
this.deaths = deaths;
this.wins = wins;
}
}


class Application {
private ArrayList<Player> players;
private Scanner sc;
private BufferedWriter out;

// file name
private final String FILE_NAME = "games.txt";

Application() throws IOException {
players = new ArrayList<>(); // initialize players list
sc = new Scanner(System.in); // for taking system input
out = new BufferedWriter(new FileWriter(FILE_NAME, true));// initialization bufferedWriter

}

// Enter details of players
void enterPlayerData() throws IOException {
//Champion Name Kills Assists Deaths Win
String choice; // for storing choice (yes/no)
do { // run until choice is other than yes
System.out.println("Enter Champion Name?");
String name = sc.next();

System.out.println("Enter number of kills?");
Integer kills = sc.nextInt();

System.out.println("Enter number of assists?");
Integer assists = sc.nextInt();
System.out.println("Enter number of deaths?");
Integer deaths = sc.nextInt();
System.out.println("Enter number of wins?");
Integer win = sc.nextInt();
//create instance of player and store it into player list
players.add(new Player(name, kills, assists, deaths, win));
String str = name + "\t" + kills + "\t" + assists + "\t" + deaths + "\t" + win + "\n";
out.write(str);
System.out.println("Do you want to enter more(yes/no)?");
choice = sc.next();
} while (choice.equalsIgnoreCase("yes"));
// close file
out.close();
// for printing statics of entered data... it does not consisting old data which file already have
System.out.println("\n\nPrinting statics of players....");
printStatics();
}

private void printStatics() {
Integer totalKills = 0;
Integer totalAssists = 0;
Integer totalDeaths = 0;
Integer totalWins = 0;

// loop through players and store that into appropriate variables
for (Player p : players) {
totalAssists += p.assists;
totalKills += p.kills;
totalDeaths += p.deaths;
totalWins += p.wins;
}

// change formula according to your need ... here i'm doing is
// calculating total and dividing with total number of players... you can change according to your need

// average kills = (total number of kills / total players)
System.out.println("Average kills: " + Float.valueOf(totalKills)/players.size());

// average assists = (total number of assists / total players)
System.out.println("Average Assists: "+ Float.valueOf(totalAssists)/players.size());

// average deaths = (total number of deaths / total players)
System.out.println("Average Deaths: "+ Float.valueOf(totalDeaths)/players.size());

// percentage wins = (total number of win / (total number of wins + total number of deaths))
System.out.println("Percentage of wins: "+ (Float.valueOf(totalWins)/(totalWins + totalDeaths))*100);
}
}


// Driver class
public class Main {
public static void main(String[] args) throws IOException {
// create instance of Application
Application app = new Application();
app.enterPlayerData(); // call function enterPlayerData()
}
}
//Output


Related Solutions

Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O)...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that: Displays the contents...
Write a program that declares a struct to store the data of a football player (player’s...
Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of a...
Write a C++ program to help the Administration of a football league to manipulate the list...
Write a C++ program to help the Administration of a football league to manipulate the list of players registered in different teams. There are 26 teams participating in the league, each is denoted by a letter in the range A to Z. Each team can have 11 players at most. The information of all teams' players are stored in a text file named 'players.dat'. Each line from the input file contains the details of one player; where the player's details...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a C++ program to swap two numbers and show your output
Write a C++ program to swap two numbers and show your output
Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT