import javax.swing.JOptionPane;
import java.text.DecimalFormat;
class QBRating
{
public static void main
(String[] args
) {
double completedPassesRating; // Number of completed passes
double attempts; // Number of attempted passes
double yardsRating; // Number of receiving yards
double touchdownsRating; // Number of passing touchdowns
double interceptionsRating; // Number of passing interceptions
double completed = 0;
double yards = 0;
double touchdowns = 0;
double interceptions = 0;
// QBs Name
name
= JOptionPane.
showInputDialog("Enter the Quarterback's name");
// Pass Attempts
input
= JOptionPane.
showInputDialog("Enter the number of attempted passes"); attempts
= Double.
parseDouble(input
);
// Pass completions
input
= JOptionPane.
showInputDialog("Enter the number of completed passes"); completed
= Double.
parseDouble(input
);
// Passing yards
input
= JOptionPane.
showInputDialog("Enter the number of passing yards"); yards
= Double.
parseDouble(input
);
// Passing touchdowns
input
= JOptionPane.
showInputDialog("Enter the number of passing touchdowns"); touchdowns
= Double.
parseDouble(input
);
// Interceptions
input
= JOptionPane.
showInputDialog("Enter the number of interceptions"); interceptions
= Double.
parseDouble(input
);
// Completion Rating
completedPassesRating = getCompletedPasses(attempts, completed);
// Yards Rating
yardsRating = getYardsPerAttempt(attempts, yards);
// Touchdown Rating
touchdownsRating = getTouchdownPasses(attempts, touchdowns);
// Interceptions Rating
interceptionsRating = getInterceptions(attempts, interceptions);
// All previous rating combined for the total rating
finalRating = getSum(completedPassesRating,yardsRating,touchdownsRating,interceptionsRating);
// Output all variables and calculations
JOptionPane.
showMessageDialog(null,
"Quarterback name: " + name
+ "\n" + "Pass Attempts: " + attempts + "\n" +
"Pass Completions: " + completed + "\n" +
"Passing Yards: " + yards + "\n" +
"Passing Touchdowns: " + touchdowns + "\n" +
"Interceptions: " + interceptions + "\n" +
"Passer Rating: " + finalRating);
}
public static double getCompletedPasses(double attempts, double completed)
{
double completedResult;
// Pass completion rating calculation
completedResult = ((((completed/attempts))-.3)*.05)*100;
if (completed/attempts < .3)
completedResult = 0;
else if (completedResult > 2.375)
completedResult = 2.375;
return completedResult;
}
public static double getYardsPerAttempt(double attempts, double yards)
{
double yardsPerAttemptResult;
// Yards rating calculation
yardsPerAttemptResult = (((yards/attempts))-3)*.25;
if (yardsPerAttemptResult < 0)
yardsPerAttemptResult = 0;
else if (yardsPerAttemptResult > 2.375)
yardsPerAttemptResult = 2.375;
return yardsPerAttemptResult;
}
public static double getTouchdownPasses(double attempts, double touchdowns)
{
double touchdownPassesResult;
// Touchdown rating calculation
touchdownPassesResult = (touchdowns/attempts)*20;
if (touchdownPassesResult > 2.375)
touchdownPassesResult = 2.375;
return touchdownPassesResult;
}
public static double getInterceptions(double attempts, double interceptions)
{
double interceptionsResult;
// Interceptions rating calculation
interceptionsResult = (2.375 - (interceptions/attempts)*25);
if (interceptionsResult < 0)
interceptionsResult = 0;
return interceptionsResult;
}
public static String getSum
(double completedPassesRating,
double yardsRating,
double touchdownsRating, double interceptionsRating)
{
double sum;
// Total Rating calculation
sum = (completedPassesRating + yardsRating + touchdownsRating + interceptionsRating);
sum = (sum/6)*100;
sumResult = qbr.format(sum);
return sumResult;
}
}