fork download
  1. import javax.swing.JOptionPane;
  2. import java.text.DecimalFormat;
  3.  
  4. class QBRating
  5. {
  6. public static void main(String[] args)
  7. {
  8. String input;
  9. String name; // QB's name
  10. double completedPassesRating; // Number of completed passes
  11. double attempts; // Number of attempted passes
  12. double yardsRating; // Number of receiving yards
  13. double touchdownsRating; // Number of passing touchdowns
  14. double interceptionsRating; // Number of passing interceptions
  15. String finalRating;
  16.  
  17. double completed = 0;
  18. double yards = 0;
  19. double touchdowns = 0;
  20. double interceptions = 0;
  21.  
  22. // QBs Name
  23. name = JOptionPane.showInputDialog("Enter the Quarterback's name");
  24.  
  25. // Pass Attempts
  26. input = JOptionPane.showInputDialog("Enter the number of attempted passes");
  27. attempts = Double.parseDouble(input);
  28.  
  29. // Pass completions
  30. input = JOptionPane.showInputDialog("Enter the number of completed passes");
  31. completed = Double.parseDouble(input);
  32.  
  33. // Passing yards
  34. input = JOptionPane.showInputDialog("Enter the number of passing yards");
  35. yards = Double.parseDouble(input);
  36.  
  37. // Passing touchdowns
  38. input = JOptionPane.showInputDialog("Enter the number of passing touchdowns");
  39. touchdowns = Double.parseDouble(input);
  40.  
  41. // Interceptions
  42. input = JOptionPane.showInputDialog("Enter the number of interceptions");
  43. interceptions = Double.parseDouble(input);
  44.  
  45. // Completion Rating
  46. completedPassesRating = getCompletedPasses(attempts, completed);
  47.  
  48. // Yards Rating
  49. yardsRating = getYardsPerAttempt(attempts, yards);
  50.  
  51. // Touchdown Rating
  52. touchdownsRating = getTouchdownPasses(attempts, touchdowns);
  53.  
  54. // Interceptions Rating
  55. interceptionsRating = getInterceptions(attempts, interceptions);
  56.  
  57. // All previous rating combined for the total rating
  58. finalRating = getSum(completedPassesRating,yardsRating,touchdownsRating,interceptionsRating);
  59.  
  60. // Output all variables and calculations
  61. JOptionPane.showMessageDialog(null, "Quarterback name: " + name + "\n" +
  62. "Pass Attempts: " + attempts + "\n" +
  63. "Pass Completions: " + completed + "\n" +
  64. "Passing Yards: " + yards + "\n" +
  65. "Passing Touchdowns: " + touchdowns + "\n" +
  66. "Interceptions: " + interceptions + "\n" +
  67. "Passer Rating: " + finalRating);
  68. }
  69.  
  70. public static double getCompletedPasses(double attempts, double completed)
  71. {
  72. double completedResult;
  73.  
  74. // Pass completion rating calculation
  75. completedResult = ((((completed/attempts))-.3)*.05)*100;
  76.  
  77. if (completed/attempts < .3)
  78. completedResult = 0;
  79. else if (completedResult > 2.375)
  80. completedResult = 2.375;
  81.  
  82. return completedResult;
  83. }
  84.  
  85. public static double getYardsPerAttempt(double attempts, double yards)
  86. {
  87. double yardsPerAttemptResult;
  88. String input;
  89.  
  90. // Yards rating calculation
  91. yardsPerAttemptResult = (((yards/attempts))-3)*.25;
  92.  
  93. if (yardsPerAttemptResult < 0)
  94. yardsPerAttemptResult = 0;
  95. else if (yardsPerAttemptResult > 2.375)
  96. yardsPerAttemptResult = 2.375;
  97.  
  98. return yardsPerAttemptResult;
  99. }
  100.  
  101. public static double getTouchdownPasses(double attempts, double touchdowns)
  102. {
  103. double touchdownPassesResult;
  104. String input;
  105.  
  106. // Touchdown rating calculation
  107. touchdownPassesResult = (touchdowns/attempts)*20;
  108.  
  109. if (touchdownPassesResult > 2.375)
  110. touchdownPassesResult = 2.375;
  111.  
  112. return touchdownPassesResult;
  113. }
  114.  
  115. public static double getInterceptions(double attempts, double interceptions)
  116. {
  117. double interceptionsResult;
  118. String input;
  119.  
  120. // Interceptions rating calculation
  121. interceptionsResult = (2.375 - (interceptions/attempts)*25);
  122.  
  123. if (interceptionsResult < 0)
  124. interceptionsResult = 0;
  125.  
  126. return interceptionsResult;
  127. }
  128.  
  129. public static String getSum(double completedPassesRating, double yardsRating,
  130. double touchdownsRating, double interceptionsRating)
  131. {
  132. DecimalFormat qbr = new DecimalFormat("###.0");
  133. double sum;
  134. String sumResult;
  135.  
  136. // Total Rating calculation
  137. sum = (completedPassesRating + yardsRating + touchdownsRating + interceptionsRating);
  138. sum = (sum/6)*100;
  139. sumResult = qbr.format(sum);
  140.  
  141. return sumResult;
  142. }
  143. }
Runtime error #stdin #stdout #stderr 0.25s 3437056KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
	at java.lang.Thread.start0(Native Method)
	at java.lang.Thread.start(Thread.java:714)
	at sun.java2d.Disposer.lambda$static$0(Disposer.java:94)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.java2d.Disposer.<clinit>(Disposer.java:83)
	at sun.font.StrikeCache.<clinit>(StrikeCache.java:68)
	at sun.font.PhysicalStrike.<clinit>(PhysicalStrike.java:41)
	at sun.font.SunFontManager.initIDs(Native Method)
	at sun.font.SunFontManager.access$200(SunFontManager.java:65)
	at sun.font.SunFontManager$1.run(SunFontManager.java:343)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
	at javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:276)
	at javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:376)
	at javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:366)
	at javax.swing.JComponent.getMinimumSize(JComponent.java:1744)
	at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:693)
	at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
	at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
	at javax.swing.JComponent.setUI(JComponent.java:666)
	at javax.swing.JOptionPane.setUI(JOptionPane.java:1860)
	at javax.swing.JOptionPane.updateUI(JOptionPane.java:1882)
	at javax.swing.JOptionPane.<init>(JOptionPane.java:1845)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:568)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:524)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:474)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:440)
	at QBRating.main(Main.java:23)