Question: Write a procedural program in JAVA for the same Object Oriented Program above. public class Football { private String playerName; private int totalPassingYards; public Football
Write a procedural program in JAVA for the same Object Oriented Program above.
public class Football
private String playerName;
private int totalPassingYards;
public Football
this.playerName ;
this.totalPassingYards ;
public FootballString playerName, int totalPassingYards
this.playerName playerName;
this.totalPassingYards totalPassingYards;
public String getPlayerName
return playerName;
public int getTotalPassingYards
return totalPassingYards;
public void setPlayerNameString playerName
this.playerName playerName;
public void setTotalPassingYardsint totalPassingYards
this.totalPassingYards totalPassingYards;
toString Method
@Override
public String toString
return "Player: playerName Passing Yards: totalPassingYards;
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class FootballDriver
public static void mainString args
Football footballPlayers new Football; assuming players
int playerCount ;
String fileName "football.txt;
try
Scanner fileScanner new Scannernew FilefileName;
Skip header
if fileScannerhasNextLine
fileScanner.nextLine;
Read player names and yards
while fileScannerhasNextLine && playerCount footballPlayers.length
String playerName fileScanner.nextLine;
int passingYards Integer.parseIntfileScannernextLine;
footballPlayersplayerCount new FootballplayerName passingYards;
playerCount;
fileScanner.close;
catch FileNotFoundException e
System.out.printlnFile not found: fileName;
return;
Scanner inputScanner new ScannerSystemin;
int option;
do
System.out.printlnMenu:;
System.out.println Highest Passing Yards";
System.out.println Lowest Passing Yards";
System.out.println Average Passing Yards";
System.out.println Quit";
System.out.printChoose an option: ;
option inputScanner.nextInt;
switch option
case :
highestPassingYardsfootballPlayers;
break;
case :
lowestPassingYardsfootballPlayers;
break;
case :
averagePassingYardsfootballPlayers;
break;
case :
System.out.printlnExiting program.";
break;
default:
System.out.printlnInvalid option. Please try again.";
while option ;
inputScanner.close;
public static void highestPassingYardsFootball footballPlayers
Football highestPlayer footballPlayers;
for Football player : footballPlayers
if player null && player.getTotalPassingYards highestPlayer.getTotalPassingYards
highestPlayer player;
System.out.printlnHighest Passing Yards: highestPlayer;
public static void lowestPassingYardsFootball footballPlayers
Football lowestPlayer footballPlayers;
for Football player : footballPlayers
if player null && player.getTotalPassingYards lowestPlayer.getTotalPassingYards
lowestPlayer player;
System.out.printlnLowest Passing Yards: lowestPlayer;
public static void averagePassingYardsFootball footballPlayers
int totalYards ;
int count ;
for Football player : footballPlayers
if player null
totalYards player.getTotalPassingYards;
count;
double average double totalYards count;
System.out.printfAverage Passing Yards: f
average;
Football.txt file
Player Most Passing yards
Tom Brady
Drew Brees
Peyton Manning
Brett Favre
Phillip Rivers
Ben Roethlisberger
Dan Marino
Eli Manning
Matt Ryan
Aaron Rogers
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
