Question: Write a procedural program in JAVA for the same Object Oriented Program above. public class Football { / / Attributes private String playerName; private int
Write a procedural program in JAVA for the same Object Oriented Program above.
public class Football
Attributes
private String playerName;
private int totalPassingYards;
Default Constructor
public Football
this.playerName ;
this.totalPassingYards ;
Overloaded Constructor
public FootballString playerName, int totalPassingYards
this.playerName playerName;
this.totalPassingYards totalPassingYards;
Getters
public String getPlayerName
return playerName;
public int getTotalPassingYards
return totalPassingYards;
Setters
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;
Reading file and populating the array
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;
Menu options
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;
Method to find highest passing yards
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;
Method to find lowest passing yards
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;
Method to find average passing yards
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 Pass
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
