Java Project. Help Please! Learning Objectives 1. (60 points) Program runs succe
ID: 3911596 • Letter: J
Question
Java Project. Help Please!
Learning Objectives 1. (60 points) Program runs successfully a. b. c. d. e. (10 points) Inputs Team name from the user using a Scanner object. (10 points) Tracks win counts based on these team names (10 points) Repeats until x is entered (15 points) Outputs all of the data input, (15 points) Correctly outputs winner, including using a random number to choose between multiple winners 2. (20 points) Use the following programming tools correctly (20 points) Implement the oversized array strategy to store the team names and win counts, a. i. This means the array is created at a reasonable size (ie, 5 or 10), then increased by doubling the size each time more space is needed. A size variable is used to track the number of items stored, which may be different from the capacity (ie length) of the array. Note: Creating a massive array at the beginning of the program so that it never needs resized is NOT an oversized array strategy and is worth 0 points ii. You may not use ArrayList objects 3. (20 points) Follow the best practices we have learned in this class (10 points) Correct data types, and useful variable names. All 10 points will be taken off for using casting instead of choosing correct data types. (10 points) Format/Tab and document code using best practices learned in class. Use at least 5 helpful comments to explain your code to me a. b. Summary We will create a more complex win tracker which will track both the number of wins AND the team names. Details Your program will track each win input by the user by first getting the name of a team that has won a game. (Note: This team name will not have any spaces in it, so you can use the .next0 method instead of .nextLineO if you prefer). If this name is "x", then the program will output the winner and exit. You may assume that there will be at least one team input each time so you do not need to make a special output for 0 teams. You will have no idea how many teams are playing, so you will need to implement the Oversized Array strategy to track the number of teams entered and managed the capacity of the array. The program will check to see if the team name entered has already been used. If the team name has been entered previously, the win count will for that team will be incremented. If the teamExplanation / Answer
ScreenShot
------------------------------------------------------------------------------
Program
/* This is the program to track the winner
*Initially two arrays intialized with size 5
*one String array for team name and int array for win rate
*Prompt user to enter team name until x enter
*each time count the times of team name enter and put corresponding arrays
*After using loop to display details of teams and their win score
*Then find which team got highest score using loop */
import java.util.*;
public class WinTracker {
public static void main(String[] args) {
//Variable for size of the array track and add values in the array
int size=0,i=0;
//User input variable
String input="";
//To check Repeating team name
boolean boolTeam=false;
//Scanner object for input read
Scanner sc=new Scanner(System.in);
//Two rrays for team name and their winning score
String[] team=new String[5];
int win[]= new int[5];
//User prompt
System.out.println("Welcome to the Advanced Sportsball Tracker!");
System.out.println("Which team just won?(x to exit)");
input=sc.next();
//Loop to check the entered input x or not
while(!input.equals("x")) {
boolTeam=false;
//If array size out of bound double the size of the array
if(team.length<size) {
team=new String[2*size];
win=new int[2*size];
}
//Check the team name already entered or not
for(int j=0;j<size;j++) {
if(team[j].equals(input) ){
win[j]+=1;
boolTeam=true;
}
}
//If not enter as a new data
if(boolTeam!=true) {
team[i]=input;
win[i]+=1;
size++;
i++;
}
//Prompt again
System.out.println("Which team just won?(x to exit)");
input=sc.next();
}
//Display user enetred details
for(int k=0;k<size;k++) {
System.out.println(team[k]+": "+win[k]);
}
//Array to get all maximum winning team details
String[] maxWinner=new String[size];
//Variablefor index of the new array and max value of the score
int maxWinIndex=0,maxWinScore=0;
// Create instance of Random class
Random rand = new Random();
//Loop to get max value teams
for(int k=0;k<size;k++) {
if(maxWinScore<win[k]) {
maxWinScore=win[k];
maxWinner[maxWinIndex++]=team[k];
}
else if(maxWinScore==win[k]) {
maxWinner[maxWinIndex++]=team[k];
}
}
//Randomly generate a number within the range
int randomIndex=rand.nextInt(maxWinIndex+1);
//Display winner
System.out.println("Winner is the "+team[randomIndex]+" with "+maxWinScore+" win(s)");
}
}
----------------------------------------------------------
Output
Welcome to the Advanced Sportsball Tracker!
Which team just won?(x to exit)
Sooners
Which team just won?(x to exit)
Sooners
Which team just won?(x to exit)
CowBoys
Which team just won?(x to exit)
Bears
Which team just won?(x to exit)
Bears
Which team just won?(x to exit)
CowBoys
Which team just won?(x to exit)
ThatOtherTeam
Which team just won?(x to exit)
x
Sooners: 2
CowBoys: 2
Bears: 2
ThatOtherTeam: 1
Winner is the CowBoys with 2 win(s)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.