亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何計算和顯示 NFL 傳球手評分?

如何計算和顯示 NFL 傳球手評分?

HUH函數 2023-08-16 18:07:44
我正在嘗試做這個家庭作業問題,但我在設置它和理解如何開始和完成這些結果時遇到困難。到目前為止,我已經聲明了公式的變量,創建了掃描儀并嘗試編寫公式。這是我到目前為止所擁有的:?//declaring variables? float a_CompletionPercentage, b_YardsPerAttempt, c_TouchdownsPerAttempt, d_InterceptionsPerAttempt;? float PasserRating;? double Completion, Attempts, Touchdowns, Yards, Interceptions;? Scanner in = new Scanner(System.in); //create Scanner Object? //PlayerName input? System.out.print("Enter the full name of the quarterback: "); //prompt asks for player name? String PlayerName = in.nextLine(); //set string PlayerName as user's input? //attempts input? System.out.print("Enter the number of attempts: "); //prompt asks for # of attempts? Attempts = in.nextDouble(); //set variable Attempts as user's input for # of attempts? //completion input? System.out.print("Enter the number of completions: ");?? Completion = in.nextDouble();?? //yards input? System.out.print("Enter the number of yards: ");?? Yards = in.nextDouble();? //touchdowns input? System.out.print("Enter the number of touchdowns: ");?? Touchdowns = in.nextDouble();?? //interceptions input? System.out.print("Enter the number of interceptions: ");?? Interceptions = in.nextDouble();?我不確定我的變量是否已正確聲明并且我的公式不起作用。這些是我應該得到的一些示例輸出:輸出示例 1:輸入四分衛的全名:Jameis Winston輸入嘗試次數:35輸入完成次數:22輸入碼數:345輸入達陣次數:4輸入攔截次數:1Jameis Winston 的傳球者評分為 121.72619047619047但我得到的是 664.58325 而不是 121.72619047619047。
查看完整描述

3 回答

?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

你的公式不正確。


這里:


b_YardsPerAttempt = (((float)(Yards/Attempts)- 3f) * 5f);

當您應該乘以 0.25 時,您卻將 (碼數/嘗試次數 - 3) 的結果乘以 5。這就是你的計算出現錯誤的地方。


請記住,您不應以大寫開頭字母命名變量。此外,在計劃使用新變量之前聲明它們也是一個很好的做法。這是一個片段,您可以看看如何寫得更好一些。


Scanner in = new Scanner(System.in);


System.out.print("Enter the full name of the quarterback: ");

String playerName = in.nextLine();


System.out.print("Enter the number of attempts: ");

Double attempts = in.nextDouble();


System.out.print("Enter the number of completions: ");

Double completion = in.nextDouble();



System.out.print("Enter the number of yards: ");

Double yards = in.nextDouble();


System.out.print("Enter the number of touchdowns: ");

Double touchdowns = in.nextDouble();


System.out.print("Enter the number of interceptions: ");

Double interceptions = in.nextDouble();


Double completionPercentage = ((completion / attempts - 0.3) * 5);

Double yardsPerAttempt = (((yards / attempts) - 3) * 0.25);

Double touchdownsPerAttempt = ((touchdowns / attempts) * 20);

Double interceptionsPerAttempt = (2.375 - ((interceptions / attempts) * 25));


Double passerRating = (((completionPercentage + yardsPerAttempt + touchdownsPerAttempt + interceptionsPerAttempt) / 6) * 100);


System.out.println("The passer rating for " + playerName + " is " + passerRating);


希望這可以幫助!


查看完整回答
反對 回復 2023-08-16
?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

我在變量及其格式的聲明方面遇到了問題。


我已經修復了代碼,現在如果有人感興趣的話它可以根據需要工作,這是我的最終工作代碼:


?//declaring variables

? double a_CompletionPercentage, b_YardsPerAttempt, c_TouchdownsPerAttempt, d_InterceptionsPerAttempt;

? double PasserRating;

? int Completion, Attempts, Touchdowns, Yards, Interceptions;



? Scanner in = new Scanner(System.in); //create Scanner Object



? //PlayerName input

? System.out.print("Enter the full name of the quarterback: "); //prompt asks for player name

? String PlayerName = in.nextLine(); //set string PlayerName as user's input


? //attempts input

? System.out.print("Enter the number of attempts: "); //prompt asks for # of attempts

? Attempts = in.nextInt(); //set variable Attempts as user's input for # of attempts


? //completion input

? System.out.print("Enter the number of completions: ");?

? Completion = in.nextInt();?


? //yards input

? System.out.print("Enter the number of yards: ");?

? Yards = in.nextInt();


? //touchdowns input

? System.out.print("Enter the number of touchdowns: ");?

? Touchdowns = in.nextInt();?


? //interceptions input

? System.out.print("Enter the number of interceptions: ");?

? Interceptions = in.nextInt();?


? //calculations?

? if (Attempts == 0) {

? ? ? ? System.out.println("The passer rating for " + PlayerName + " is " + 0);


? } else {


? ? ?a_CompletionPercentage = ((double)Completion /Attempts - 0.3) * 5.0; //formula for completion percentage

? ? ?b_YardsPerAttempt =? ? ? ((double)Yards? ? ? /Attempts - 3.0) * 0.25; //formula for yards per attempt

? ? ?c_TouchdownsPerAttempt = ((double)Touchdowns /Attempts)? ? ? ?* 20.0; //formula for touchdowns per attempt

? ? ?d_InterceptionsPerAttempt = 2.375f - ((double)Interceptions /Attempts * 25.0); //formula for interceptions per attempt


? ? ?//formula for passing rate

? ? ?PasserRating = (((a_CompletionPercentage + b_YardsPerAttempt + c_TouchdownsPerAttempt + d_InterceptionsPerAttempt)/6.0) * 100.0);?



? ? ?//Displays result

? ? ?if (PasserRating < 0){

? ? ? ? System.out.println("The passer rating for " + PlayerName + " is " + 0);

? ? ?} else{

? ? ? ? System.out.println("The passer rating for " + PlayerName + " is " + PasserRating);

? ? ?}

? }



查看完整回答
反對 回復 2023-08-16
?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

您沒有遵循變量名稱等的常用 Java 編碼約定。這會使您的代碼可讀性較差。從學習它們開始。

像大多數新手程序員一樣,您將太多精力集中在輸入上,而沒有足夠地編寫正確的函數。

現在學習JUnit還不算太早,?我建議編寫五個函數:

public interface PasserRatingCalculator {

? ? default double calculateCompletionPercentage(int numAttempts, int numCompletions) { return ((double)numCompletions)/numAttempts; }

? ? double calculateYardsPerAttempt(int numAttempts, int numYards) { return ((double)numYards/numAttempts; }

? ? double calculateTouuchdownsPerAttempt(int numAttempts, int numTouchdowns) { return ((double)numTouchdowns)/numAttempts; }

? ? double calculateInterceptionsPerAttempt(int numAttempts, int numInterceptions) { return ((double)numInterceptions)/numAttempts; }

? ? double calculatePasserRating(numAttempts, int numCompletions, int numYards, int numTouchdowns, int numCompletions);? ? ? ??

}


查看完整回答
反對 回復 2023-08-16
  • 3 回答
  • 0 關注
  • 224 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號