import java.util.*;
public class playerStats
{
Scanner scan = new Scanner (System.in);
String name;
int ex = 0;
int choice;
int num;
int update;
int NULL_SIZE = 0;
basketballPlayer[] players = new basketballPlayer[NULL_SIZE];
public void userInput()
{
String teamName;
System.out.println ("Enter a team name: ");
teamName = scan.nextLine();
System.out.println ("");
while (ex != 1)
{
System.out.println (" SEASON STATS ");
System.out.println ("For the team: " + teamName);
System.out.println ("");
System.out.println ("1. Add a point or shooting guard");
System.out.println ("2. Add a center");
System.out.println ("3. Show players statistics");
System.out.println ("4. Update a players statistics");
System.out.println ("5. Exit");
choice = scan.nextInt();
scan.nextLine();
switch(choice)
{
case 1:
{
addGuard(); break;
}
case 2:
{
addCenter(); break;
}
case 3:
{
entireList(); break;
}
case 4:
{
updateStats(); break;
}
case 5:
{
ex = 1; break;
}
}
}
}
public void addGuard()
{
System.out.println ("Please indicate how many players (Guards) you would like to add: ");
num = scan.nextInt();
scan.nextLine();
if (num > players.length)
{
incSize(num);
}
for (int i = 0; i < num; i ++)
{
players[i] = new positionGuard (entName(),entAge(), entHeight(), entPositionRanking(), entDrafted(), entThreePointers(), entSteals(), entTotalSeasonPointsG());
}
}
public void addCenter()
{
System.out.println ("Please indicate how many players (Centers) you would like to add: ");
num = scan.nextInt();
scan.nextLine();
if (num > players.length)
{
incSize(num);
}
for (int i = 0; i < num; i ++)
{
players[i] = new positionCenter (entName(),entAge(), entHeight(), entPositionRanking(), entDrafted(), entBlocks(), entDunks(), entTotalSeasonPointsC());
}
}
public void entireList() //////////////////////// This is doing its job (i think) but the array keeps getting overwritten when a new entry is added: AddCenter or AddGuard
{
for (int i = 0; i < players.length; i++)
{
System.out.println (players[i].toString());
}
}
public void updateStats()
{
int option;
System.out.println ("Please select from the following options: ");
System.out.println ("1. Update a guards statistics: ");
System.out.println ("2. Update a centers statistics: ");
option = scan.nextInt();
scan.nextLine();
if (option == 1)
{
System.out.println ("What is this players name?");
name = scan.nextLine();
for (int i = 0; i < players.length; i ++)
{
if (players[i].getName().equals(name))
{
updateAge(i);
updateHeight(i);
updatePositionRanking(i);
updateThreePointers(i);
updateSteals(i);
updateTotalSeasonPointsG(i);;
}
else
{
System.out.println ("Players name is spelt incorrectly or doesn't exist");
}
}
}
if (option == 2)
{
System.out.println ("What is this players name: ");
name = scan.nextLine();
for (int i = 0; i < players.length; i ++)
{
if (players[i].getName().equals(name))
{
updateAge(i);
updateHeight(i);
updatePositionRanking(i);
updateBlocks(i);
updateDunks(i);
updateTotalSeasonPointsC(i);
}
else
{
System.out.println ("Players name is spelt incorrectly or doesn't exist");
}
}
}
}
public String entName()
{
String name;
System.out.println ("The players name is: ");
name = scan.nextLine();
return name;
}
public int entAge()
{
int age;
System.out.println ("The players age is: ");
age = scan.nextInt();
scan.nextLine();
return age;
}
public float entHeight()
{
float height;
System.out.println ("The players height is: ");
height = scan.nextFloat();
scan.nextLine();
return height;
}
public int entPositionRanking()
{
int positionRanking;
System.out.println ("The players position ranking is: ");
positionRanking = scan.nextInt();
scan.nextLine();
return positionRanking;
}
public int entDrafted()
{
int drafted;
System.out.println ("The player was drafted in the year: ");
drafted = scan.nextInt();
scan.nextLine();
return drafted;
}
public int entThreePointers()
{
int threePointers;
System.out.println ("How many three pointers has the player successfully shot: ");
threePointers = scan.nextInt();
scan.nextLine();
return threePointers;
}
public int entSteals()
{
int steals;
System.out.println ("How many steals has the player successfully completed: ");
steals = scan.nextInt();
scan.nextLine();
return steals;
}
public int entTotalSeasonPointsG()
{
int totalSeasonPointsG;
System.out.println ("How many points has the player accumulated this season: ");
totalSeasonPointsG= scan.nextInt();
scan.nextLine();
return totalSeasonPointsG;
}
public int entTotalSeasonPointsC()
{
int totalSeasonPointsC;
System.out.println ("How many points has the player accumulated this season: ");
totalSeasonPointsC= scan.nextInt();
scan.nextLine();
return totalSeasonPointsC;
}
public int entDunks()
{
int dunks;
System.out.println ("How many dunks has the player achieved: ");
dunks = scan.nextInt();
scan.nextLine();
return dunks;
}
public int entBlocks()
{
int blocks;
System.out.println ("How many blocks has the player achieved: ");
blocks = scan.nextInt();
scan.nextLine();
return blocks;
}
public void updateAge(int i)
{
int updateA;
System.out.println ("Enter a new age, or enter '0' to leave it at the current value");
updateA = scan.nextInt();
scan.nextLine();
if (updateA > 0)
{
players[i].setAge(updateA);
}
}
public void updateHeight(int i)
{
int updateB;
System.out.println ("Enter a new height, or enter '0' to leave it at the current value");
updateB = scan.nextInt();
scan.nextLine();
if (updateB > 0)
{
players[i].setHeight(updateB);
}
}
public void updatePositionRanking(int i)
{
int updateC;
System.out.println ("Enter a new position rank, or enter '0' to leave it at the current value");
updateC = scan.nextInt();
scan.nextLine();
if (updateC > 0)
{
players[i].setPositionRanking(updateC);
}
}
public void updateThreePointers(int i)
{
basketballPlayer bballGuard = players[i];
positionGuard guard = (positionGuard) bballGuard;
int updateD;
System.out.println ("Enter a new value, or enter '0' to leave it at the current value");
updateD = scan.nextInt();
scan.nextLine();
if (updateD > 0)
{
guard.setThreePointers(updateD);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void updateSteals(int i)
{
basketballPlayer bballGuard = players[i];
positionGuard guard = (positionGuard) bballGuard;
int updateE;
System.out.println ("Enter a new value: ");
updateE = scan.nextInt();
scan.nextLine();
if (updateE > 0)
{
guard.setSteals(updateE);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void updateBlocks(int i)
{
basketballPlayer bballCenter = players[i];
positionCenter center = (positionCenter) bballCenter;
int updateF;
System.out.println ("Enter a new value: ");
updateF = scan.nextInt();
scan.nextLine();
if (updateF > 0)
{
center.setBlocks(updateF);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void updateDunks(int i)
{
basketballPlayer bballCenter = players[i];
positionCenter center = (positionCenter) bballCenter;
int updateG;
System.out.println ("Enter a new value: ");
updateG = scan.nextInt();
scan.nextLine();
if (updateG > 0)
{
center.setDunks(updateG);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void updateTotalSeasonPointsG(int i)
{
basketballPlayer bballGuard = players[i];
positionGuard guard = (positionGuard) bballGuard;
int updateH;
System.out.println ("Enter a new value: ");
updateH = scan.nextInt();
scan.nextLine();
if (updateH > 0)
{
guard.setTotalSeasonPointsG(updateH);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void updateTotalSeasonPointsC(int i)
{
basketballPlayer bballCenter = players[i];
positionCenter center = (positionCenter) bballCenter;
int updateK;
System.out.println ("Enter a new value: ");
updateK = scan.nextInt();
scan.nextLine();
if (updateK > 0)
{
center.setTotalSeasonPointsC(updateK);
}
else
{
System.out.println ("Incorrect value entered, must be greater than '0' ");
}
}
public void setName(String upName)
{
name = upName;
}
public String getName()
{
return name;
}
public static void main (String [] args)
{
playerStats stats = new playerStats();
stats.userInput();
}
public void incSize (int inc)
{
int size = players.length;
size = size + inc;
basketballPlayer [] temp = new basketballPlayer [size];
for (int i = 0; i < players.length; i ++)
{
temp[i] = players[i];
}
players = temp;
}
}