import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Assignment51
{
public static void main(String[] args)
{
/*
Four Categories are used as a basis for compiling a rating:
1. Percentage of completions
2. Average yards gained
3. Percentage of touchdown passes per attempt
4. Percentage of interceptions per attempt
*/
// DecimalFormat formatter = new DecimalFormat("#,##0.000");
String input; //get user input
String name; //player name
int completion; //number of completions in percentages
int yardsGained; //number of yards gained
int tdpasses; //number of touchdown passes
int interceptions; //number of interceptions
int attempts; //number of attempts
int yards; //number of yards
double score; //passer score
double totalScore; //total score
double totalPoints; //total award points
double total; //total sum
//get player name
name = JOptionPane.showInputDialog("Type in the player name");
//Creating Methods
PctCompletion();
AvgYardsGain();
PctTouchdown();
PctInterceptions();
//RETURN TO MAIN METHOD
double PctCompletion, AvgYardsGain, PctTouchdown, PctInterceptions;
totalPoints = PctCompletion + AvgYardsGain + PctTouchdown + PctInterceptions;
total = (totalPoints/6) * 100;
//OUTPUT
JOptionPane.showMessageDialog(null, "total points: " + totalPoints + "\ntotal: " + total);
//JOptionPane.showMessageDialog(null, name + " earned a total of " + total + " award points.\n"); //GET HELP WITH OUTPUT
}
//calling the PctCompletion method.
public static double PctCompletion()
{
String input; //user input
int num1; //first input
int num2; //second input total amount of passes
double percentComp = 0.0; //percent completed. num1/num2 = percentComp
double pointRatingComp = 0.0; //Completions point rating
double awardPoints1 = 0.0; //awarded points +/- 2.375
input = JOptionPane.showInputDialog("Type in the TOTAL number of passes");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Type in the number of COMPLETED passes");
num1 = Integer.parseInt(input);
percentComp = ((num1/num2) * 100);
//point rating
pointRatingComp = ((percentComp - 30) * .05);
if (pointRatingComp < 0 && percentComp < 30.0)
awardPoints1 = 0.0;
if (pointRatingComp > 2.375 && percentComp > 77.5)
awardPoints1 = 2.375;
return awardPoints1;
}
//calling the AvgYardsGain method
public static double AvgYardsGain()
{
String input; //user input
int num1; //first input total yards
int num2; //second input total attempts
double percentYard = 0.0; //percent completed. num1/num2 = percentYard
double pointRatingYard = 0.0; //Yards point rating
double awardPoints2 = 0.0; //awarded points +/- 2.375
input = JOptionPane.showInputDialog("Type in the TOTAL number of attempts");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Type in the TOTAL amount of yards");
num1 = Integer.parseInt(input);
percentYard = ((num1/num2) * 100);
//point rating
pointRatingYard = ((percentYard - 3) * .25);
if (pointRatingYard < 0 && percentYard < 3)
awardPoints2 = 0;
if (pointRatingYard > 2.375 && percentYard > 12.5)
awardPoints2 = 2.375;
return awardPoints2;
}
//calling the PctTouchdown method
public static double PctTouchdown()
{
String input; //user input
int num1; //input total number of touchdowns
int num2; //input total amount of attempts
double percentTD = 0.0; //percent completed. num1/num2 = percentTD
double pointRatingTD = 0.0; //touchdowns point rating
double awardPoints3 = 0.0; //awarded points +/- 2.375
input = JOptionPane.showInputDialog("Type in the TOTAL number of pass ATTEMPTS");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Type in the TOTAL number of TOUCHDOWNS");
num1 = Integer.parseInt(input);
percentTD = ((num1/num2) * 100);
//point rating
pointRatingTD = (percentTD * .2);
if (pointRatingTD > 2.375 && percentTD > 11.875)
awardPoints3 = 2.375;
return awardPoints3;
}
//calling the PctInterceptions method
public static double PctInterceptions()
{
String input; //user input
int num1; //input total amount of interceptions
int num2; //input total amount of attempts
double percentINT = 0.0; //percent completed. num1/num2 = percentComp
double pointRatingINT = 0.0; //Completions point rating
double awardPoints4 = 0.0; //awarded points +/- 2.375
input = JOptionPane.showInputDialog("Type in the TOTAL number of pass ATTEMPTS");
num2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog("Type in the TOTAL amount of INTERCEPTIONS");
num1 = Integer.parseInt(input);
percentINT = ((num1/num2) * 100);
//point rating
pointRatingINT = 2.375 - (percentINT * .25);
if (pointRatingINT < 0 && percentINT > 9.5)
awardPoints4 = 0;
else
awardPoints4 = 2.375;
return awardPoints4;
}
}
戻り値(受賞点)は、メソッドから受け取った値から計算を実行します。しかし、私はそうするときにエラーが発生しています。 これは問題のコードの一部です。メソッドの出力をJavaのメインメソッドに戻すにはどうすればよいですか?
//RETURN TO MAIN METHOD
double PctCompletion, AvgYardsGain, PctTouchdown, PctInterceptions;
totalPoints = PctCompletion + AvgYardsGain + PctTouchdown + PctInterceptions;
total = (totalPoints/6) * 100;
:
は、次のコードを参照してください。それがなければ、あなたを助けることは難しいです。 –
どのようなエラーが発生していますか? – SpringLearner
'Assignment51.java:50:エラー:シンボルを見つけることができません totalPoints = awardPoints1 + awardPoints2 + awardPoints3 + awardPoints4; ^ シンボル:変数awardPoints1 所在地:class Assignment51 –