Question: Please work this on codes given. Your job for this program is to use your Quarterback Program (or the one that is attached) and make

Please work this on codes given. Your job for this program is to use your Quarterback Program (or the one that is attached) and make it look wonderful. The requirements are to make the program really user-friendly by using a grid layout for your input and output. Make sure everything is well documented internally and externally.

20 import java.util.*; 21 import javax.swing.*; 22 import java.text.DecimalFormat; 23 24 public class Ch7_Assign1 25 { 26 27 public static void main(String[] args) 28 { 29 30 /*****************************************************************/ 31 //------------------Input the Data--------------------------- 32 33 /***************************************** 34 * 35 * Using separate, subsequent dialog boxes, 36 * the user will be prompted to enter data 37 * regarding the quarterback. 38 * 39 ******************************************/ 40 41 String name = 42 JOptionPane.showInputDialog 43 ("Please enter the quarterback's name: "); 44 45 String completedTemp = 46 JOptionPane.showInputDialog 47 ("Please enter the number of completed passes: "); 48 int completed = Integer.parseInt(completedTemp); 49 50 String attemptsTemp = 51 JOptionPane.showInputDialog 52 ("Please enter the number of attempted passes: "); 53 int attempted = Integer.parseInt(attemptsTemp); 54 55 String yardsTemp = 56 JOptionPane.showInputDialog 57 ("Please enter the number of receiving yards: "); 58 int yard = Integer.parseInt(yardsTemp); 59 60 String touchdownsTemp = 61 JOptionPane.showInputDialog 62 ("Please enter the number of passing TDs: "); 63 int touchdown = Integer.parseInt(touchdownsTemp); 64 65 String interceptionsTemp = 66 JOptionPane.showInputDialog 67 ("Please enter the number of intercepted passes: "); 68 int interception = Integer.parseInt(interceptionsTemp); 69 70 71 //----------------Call Methods-------------------------------- 72 73 /******************************************** 74 * 75 * Here, I call my methods and store the 76 * corresponding statistic as a new 77 * double variable, for later use. 78 * 79 * Note that in the last call, I use the 80 * former results to calculate the QB rating. 81 * 82 *********************************************/ 83 84 double compResult = calcCompletions(completed, attempted); 85 double ygaResult = calcYGA(yard, attempted); 86 double tdResult = calcTDResult(touchdown, attempted); 87 double interResult = calcInter(interception, attempted); 88 double rating = qbRating(compResult, ygaResult, 89 tdResult, interResult); 90 91 92 //----------------Display the output-------------------------- 93 94 /******************************************** 95 * 96 * Using the data computed from my methods 97 * below and called/stored above, I use 98 * a dialog box to display all of the 99 * data at once. 100 * I decided to use the DecimalFormat class 101 * to display the output to three decimal 102 * places, since it is much cleaner than printf 103 * 104 *********************************************/ 105 106 DecimalFormat threeDec = new DecimalFormat("0.000"); 107 108 String output = name + "'s quarterback rating is: " + 109 threeDec.format(rating) + "." + 110 " " + "This is based upon the data you inputted:" + 111 " " + "Completed Passes: " + completed + "." + 112 " " + "Attempted Passes: " + attempted + "." + 113 " " + "Receiving Yards: " + yard + "." + 114 " " + "Touchdowns: " + touchdown + "." + 115 " " + "Interceptions: " + interception + "." + " " + 116 " " + "Percentage of Completions: " 117 + threeDec.format(compResult) + "." + 118 " " + "Average Yards Gained Per Attempt: " 119 + threeDec.format(ygaResult) + "." + 120 " " + "Percentage of Touchdowns: " 121 + threeDec.format(tdResult) + "." + 122 " " + "Percentage of Interceptions: " 123 + threeDec.format(interResult) + "."; 124 125 JOptionPane.showMessageDialog(null, output, 126 "Quarterback Rating", JOptionPane.INFORMATION_MESSAGE); 127 128 System.exit(0); 129 130 } 131 132 //---------Create Methods--------------------------------- 133 134 /******************************************** 135 * 136 * Here, I have created methods that receive 137 * their input data from the dialog boxes 138 * above and return double values to be 139 * stored in the variables above, when the 140 * methods are called. 141 * 142 * The method for the QB rating requires 143 * several 'if' statements nested within 144 * the method, for proper calculation 145 * of the rating. By using non-void methods, 146 * I was able to more easily manipulate the 147 * data in terms of calculating the QB rating, 148 * as well as the output. 149 * 150 *********************************************/ 151 152 public static double calcCompletions(int comp, int attempt) 153 { 154 double comps = comp; 155 double attempts = attempt; 156 double compPerc = (comps/attempts)*100; 157 return compPerc; 158 } 159 160 public static double calcYGA(int yard, int attempt) 161 { 162 double yards = yard; 163 double attempts = attempt; 164 double YGA = (yards/attempts); 165 return YGA; 166 } 167 168 public static double calcTDResult(int td, int attempt) 169 { 170 double tds = td; 171 double attempts = attempt; 172 double tdPerc = (tds/attempts)*100; 173 return tdPerc; 174 } 175 176 public static double calcInter(int inter, int attempt) 177 { 178 double inters = inter; 179 double attempts = attempt; 180 double interPerc = (inters/attempts)*100; 181 return interPerc; 182 } 183 184 public static double qbRating(double comp, double yga, 185 double td, double inter) 186 { 187 double compRating = (comp - 30.0)*.05; 188 if (compRating < 0.0) 189 compRating = 0.0; 190 if (compRating > 2.375) 191 compRating = 2.375; 192 193 double ygaRating = (yga - 3.0)*0.25; 194 if (ygaRating < 0.0) 195 ygaRating = 0.0; 196 if (ygaRating > 2.375) 197 ygaRating = 2.375; 198 199 double tdRating = (td*0.2); 200 if (tdRating > 2.375) 201 tdRating = 2.375; 202 203 double intRating = 2.375 - (inter*0.25); 204 if (intRating < 0.0) 205 intRating = 0.0; 206 207 double rating = (compRating + ygaRating + 208 tdRating + intRating)/6 * 100; 209 return rating; 210 } 211 212 213 214 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!