Question
fix this bug I am getting: I added all my code below OUTPUT: Team 1: Team Name: Tigers Owner: Bob Team 2: Team Name: Raiders
fix this bug I am getting: I added all my code below
OUTPUT:
Team 1: Team Name: Tigers Owner: Bob
Team 2: Team Name: Raiders Owner: Darrell
//I think error is caused by not being able to read the file java.io.FileNotFoundException: file.txt (The system cannot find the file specified) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:216) at java.base/java.io.FileInputStream.(FileInputStream.java:157) at java.base/java.util.Scanner.(Scanner.java:639) at FantasyFootballTester.main(FantasyFootballTester.java:29)
Unable to add player. Unable to add player. Unable to add player. Unable to add player. Unable to add player. Unable to add player.
null null null null null null
OUTPUT SHOULD LOOK LIKE THIS:
Team Name: Giants Agros Owner: Bob
Name: Phil Sims, Position: Quarter Back, NFL Team: Giants Completion Percentage: 0.25, Average Passing Yards Per Game: 500.00 Average Touch Downs Per Game: 1.50, Player's Rating: 127 Name: Jim Brown, Position: Running Back, NFL Team: Browns Running Yards Per Game: 104.17, Running Yards Per Attempt: 9.77 Average Touch Downs Per Game: 0.67, Player's Rating: 31 Name: Spider Lockart, Position: Defensive Back, NFL Team: Giants Tackles Per Game: 1.43, Interceptions Per per Game: 0.36 Forced Fumbles Per Game: 0.21, Player's Rating 18
FantasyFootballTester.java
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class FantasyFootballTester { public static void main(String[] args) { //String name, String post, String team, int games, int passAtt, int passComp, int touchPass, int totalYardsPass FantasyFootballTeam fft1 = new FantasyFootballTeam("Giants", "Bob", 10); FantasyFootballTeam fft2 = new FantasyFootballTeam("Raiders", "Darrell", 10); QuarterBack qb1 = null; QuarterBack qb2 = null; RunningBack rb1 = null; RunningBack rb2 = null; DefensiveBack db1 = null; DefensiveBack db2 = null; System.out.println("Team 1:"); System.out.println(fft1); System.out.println("Team 2:"); System.out.println(fft2); File footballFile = new File("file.txt"); try { Scanner scanner = new Scanner(footballFile); while(scanner.hasNextLine()){ String Line = scanner.nextLine(); String contents[] = Line.split(", "); String playerName = contents[0]; String post = contents[1]; String team = contents[2]; int games = Integer.parseInt(contents[3]); if(post.equals("Quarter Back")){ int passAtt = Integer.parseInt(contents[4]); int passComp = Integer.parseInt(contents[5]); int totalYardsPass = Integer.parseInt(contents[6]); int td = Integer.parseInt(contents[7]); //puts it in first then second team if(qb1 == null){ qb1 = new QuarterBack(); qb1.setPName(playerName); qb1.setPost(post); qb1.setTeam(team); qb1.setGames(games); qb1.setPassAtt(passAtt); qb1.setPassComp(passComp); qb1.setTouchPass(td); qb1.setTotalPass(totalYardsPass); }else{ qb2 = new QuarterBack(); qb2.setPName(playerName); qb2.setPost(post); qb2.setTeam(team); qb2.setGames(games); qb2.setPassAtt(passAtt); qb2.setPassComp(passComp); qb2.setTouchPass(td); qb2.setTotalPass(totalYardsPass); } }else if(post.equals("Running Back")) { int runningAttempts = Integer.parseInt(contents[4]); int totalRunning = Integer.parseInt(contents[5]); int touchDowns = Integer.parseInt(contents[6]); //puts it in first then second team if(rb1 == null){ rb1= new RunningBack(); rb1.setPName(playerName); rb1.setPost(post); rb1.setTeam(team); rb1.setGames(games); rb1.setRunAtt(runningAttempts); rb1.setTotalRun(totalRunning); rb1.setTouchDown(touchDowns); }else{ rb2 = new RunningBack(); rb2.setPName(playerName); rb2.setPost(post); rb2.setTeam(team); rb2.setGames(games); rb2.setRunAtt(runningAttempts); rb2.setTotalRun(totalRunning); rb2.setTouchDown(touchDowns); } }else if(post.equals("Defensive Back")){ int tackles = Integer.parseInt(contents[4]); int interceptions = Integer.parseInt(contents[5]); int forcedFumbles = Integer.parseInt(contents[6]); //puts it in first then second team if(db1 == null){ db1 = new DefensiveBack(); db1.setPName(playerName); db1.setPost(post); db1.setTeam(team); db1.setGames(games); db1.setTackles(tackles); db1.setInterceptions(interceptions); db1.setForcedFumbles(forcedFumbles); }else{ db2 = new DefensiveBack(); db2.setPName(playerName); db2.setPost(post); db2.setTeam(team); db2.setGames(games); db2.setTackles(tackles); db2.setInterceptions(interceptions); db2.setForcedFumbles(forcedFumbles); } } } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } //adds each player to teams fft1.addPlayer(qb1); fft1.addPlayer(rb1); fft1.addPlayer(db1); fft2.addPlayer(qb2); fft2.addPlayer(rb2); fft2.addPlayer(db2); System.out.println(" "); //prints players info System.out.println(qb1); System.out.println(qb2); System.out.println(rb1); System.out.println(rb2); System.out.println(db1); System.out.println(db2); System.out.println(" "); //test System.out.println("Testing Finding player by position "+fft1.findPlayerbyPosition("Quarter Back")); //System.out.println(" Testing comparing two players rating"); } }
FantasyFootballTeam.java
public class FantasyFootballTeam{ private String owner; private String name; private FootballPlayer fbArray[]; private int index; public FantasyFootballTeam() { owner = ""; name = ""; } public FantasyFootballTeam(String name, String owner, int size) { this.owner = owner; this.name = name; this.fbArray = new FootballPlayer[size]; this.index = 0; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public void addPlayer(FootballPlayer player) { if(player != null && index < fbArray.length) { fbArray[index] = player; index++; }else{ System.out.println("Unable to add player."); } } public String findPlayerbyPosition(String position) { String allPlayers = ""; for(int i = 0; i < index; i++){ if(fbArray[i].getPost() == position) { allPlayers += fbArray[i].toString() + " "; } } if(allPlayers == ""){ allPlayers = "No player found at: " + position + " "; } return allPlayers; } @Override public String toString() { String allString = "Team Name: " + this.getName() + " Owner: " + this.getOwner() + " "; for(int i = 0; i < index; i++) { allString += fbArray[i].toString() + " "; } return allString; } }
FootballPlayer.java
public abstract class FootballPlayer { String name; String post; String team; int games; public FootballPlayer() { this.name=""; this.post=""; this.team=""; this.games=0; } public FootballPlayer(String name, String post, String team, int games) { super(); this.name = name; this.post = post; this.team = team; this.games = games; } //pass to compare public abstract int playerRating(); public int compareTo(int rate) { if(this.playerRating() > rate){ return 1; }else if(this.playerRating() < rate){ return -1; }else{ return 0; } } public String getPName() { return name; } public void setPName(String name) { this.name = name; } public String getPost() { return post; } public void setPost(String post) { this.post = post; } public String getTeam() {//change? return team; } public void setTeam(String team) { this.team = team; } public int getGames() { return games; } public void setGames(int games) { this.games = games; } @Override public String toString(){ return "Player Name: " + getPName() + " Player Position: " + getPost() + " Team: " + getTeam() + " "; } }
QuarterBack.java
public class QuarterBack extends FootballPlayer{ //Stores statistics specific to Quarterbacks private int passAtt; private int passComp; private int touchPass; private int totalYardsPass; public QuarterBack(){ super(); passAtt = 0; passComp = 0; touchPass = 0; totalYardsPass = 0; } public QuarterBack(String name, String post, String team, int games, int passAtt, int passComp, int touchPass, int totalYardsPass){ super(name, post, team, games); this.passAtt = passAtt; this.passComp = passComp; this.touchPass = touchPass; this.totalYardsPass = totalYardsPass; } public int getPassAtt(){ return passAtt; } public void setPassAtt(int passAtt){ this.passAtt = passAtt; } public int getPassComp(){ return passComp; } public void setPassComp(int passComp){ this.passComp = passComp; } public int getTouchPass(){ return touchPass; } public void setTouchPass(int touchPass){ this.touchPass = touchPass; } public int getTotalPass(){ return touchPass; } public void setTotalPass(int totalYardsPass){ this.totalYardsPass = totalYardsPass; } //calc methods public double completionPercentage(){ return passComp/passAtt; //Formula: passes completed / pass Attempts } public double averagePassingYardsPerGame(){ return totalYardsPass/this.games; //Formula: total yards passing/games Played } public double averageTouchDownsPerGame(){ return touchPass/this.games; //Formula: touch Downs Passing/games Played } @Override public int compareTo(int rating) { return playerRating() - rating; } @Override public int playerRating(){ int rating = (int) (this.averageTouchDownsPerGame()+(this.completionPercentage()*100)+(this.averagePassingYardsPerGame()/5)); return rating; } @Override public String toString(){ //returns a String representation of the object return super.toString()+ "Completion Percentage: "+completionPercentage()+ " Average Passing Yards Per Game: "+averagePassingYardsPerGame()+ " Average Touch Downs Per Game: "+averageTouchDownsPerGame()+ " Player's Rating: "+this.playerRating() + " "; } }
RunningBack
public class RunningBack extends FootballPlayer{ //Similar to the QuarterBack class except for slightly different //instance variables and statistical methods. private int runAtt; private int totalRun; private int touchDowns; public RunningBack() { super(); runAtt = 0; totalRun = 0; touchDowns = 0; } public RunningBack(String name, String post, String team, int games, int runAtt, int totalRun, int touchDowns) { super(name, post, team, games); this.runAtt = runAtt; this.totalRun = totalRun; this.touchDowns = touchDowns; } //make setters and getters public int getRunAtt() { return runAtt; } public void setRunAtt(int runAtt) { this.runAtt = runAtt; } public int getTotalRun() { return totalRun; } public void setTotalRun(int totalRun) { this.totalRun = totalRun; } public void setPassComp(int totalRun) { this.totalRun = totalRun; } public int getTouchDown() { return touchDowns; } public void setTouchDown(int touchDowns) { this.touchDowns = touchDowns; } public void setTouchPass(int touchDowns) { this.touchDowns = touchDowns; } //calc methods public double averageYardsPerGame() { return this.totalRun/this.games; } public double averageYardsPerAttempt() { return this.runAtt/this.totalRun; } public double averageTouchDownsPerGame() { return this.touchDowns/this.games; } @Override public int compareTo(int rating) { return playerRating() - rating; } @Override public int playerRating() { int rating = (int) (this.averageTouchDownsPerGame()+this.averageYardsPerAttempt()+(this.averageYardsPerGame()/5)); return rating; } @Override public String toString() { return super.toString()+ "Average Yards Per Game: "+averageYardsPerGame()+ " Average Yards Per Attempt: "+averageYardsPerAttempt()+ " Average Touch Downs Per Game: "+averageTouchDownsPerGame()+ " Player's Rating: "+this.playerRating()+" "; } }
DefensiveBack
public class DefensiveBack extends FootballPlayer{ private int tackles; private int interceptions; private int forcedFumbles; public DefensiveBack() { super(); tackles = 0; interceptions = 0; forcedFumbles = 0; } public DefensiveBack(String name, String team, String post, int games, int tackles, int interceptions, int forcedFumbles) { super(name,post,team,games); this.tackles = tackles; this.interceptions = interceptions; this.forcedFumbles = forcedFumbles; } //make setters and getters public int getTackles() { return tackles; } public void setTackles(int tackles) { this.tackles = tackles; } public int getInterceptions() { return interceptions; } public void setInterceptions(int interceptions) { this.interceptions = interceptions; } public int getForcedFumbles() { return forcedFumbles; } public void setForcedFumbles(int forcedFumbles) { this.forcedFumbles = forcedFumbles; } //calculus methods public double averageTacklesPerGame(){ return this.tackles/this.games; } public double averageInterceptionsPerGame(){ return this.interceptions/this.games; } public double averageForcedFumblesPerGame(){ return this.forcedFumbles/this.games; } @Override public int playerRating(){ int rating = (int)(this.averageTacklesPerGame() + this.averageInterceptionsPerGame() + ((this.averageForcedFumblesPerGame()/5)) * 10); return rating; } @Override public int compareTo(int rating) { return playerRating() - rating; } @Override public String toString(){ //returns a String representation of the object return super.toString()+ "Average Tackles Per Game: "+averageTacklesPerGame()+ " Average Interceptions Per Game: "+averageInterceptionsPerGame()+ " Average Forced Fumbles Per Game: "+averageForcedFumblesPerGame()+ " Player's Rating: "+this.playerRating()+" "; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The error youre encountering javaioFileNotFoundException indicates that the program cannot find the ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started