如何使用java将另一个方法的结果转换成另一个方法?

如何使用java将另一个方法的结果转换成另一个方法?,java,Java,为了好玩,我做了一个简单的评分系统。我正在尝试应用成绩总数,并将其添加到我的getApercent()方法中的一个等式中。然而,我不断地犯错误,不知道该怎么办 package gradesystem; import java.util.Scanner; public class Gradesystem { public static void main(String[] args) { Scanner keyboard = new Scanner(Sy

为了好玩,我做了一个简单的评分系统。我正在尝试应用成绩总数,并将其添加到我的
getApercent()
方法中的一个等式中。然而,我不断地犯错误,不知道该怎么办

package gradesystem;

import java.util.Scanner;

public class Gradesystem {      

    public static void main(String[] args) {

        Scanner keyboard = new Scanner(System.in);
        Gradesystem gs = new Gradesystem();
        // TODO Auto-generated method stub
      int Acount,Bcount,Ccount,Dcount,Fcount;
     double ap,bp,cp,dp,fp;
      System.out.println("Enter the amount of A's");
      Acount = keyboard.nextInt();
      System.out.println("Enter the amount of B's");
      Bcount = keyboard.nextInt();
      System.out.println("Enter the amount of C's");
      Ccount = keyboard.nextInt();
      System.out.println("Enter the amount of D's");
      Dcount = keyboard.nextInt();
      System.out.println("Enter the amount of F's");
      Fcount = keyboard.nextInt();          

     int grades;
      ap = getApercent(Acount);
      System.out.println(ap);
      bp = getBpercent(Bcount);
      System.out.println(bp);
      cp = getCpercent(Ccount);
      System.out.println(cp);
      dp = getDpercent(Dcount);
      System.out.println(dp);
      fp = getFpercent(Fcount);
      System.out.println(fp);       
    }

    public static void Totalgrades(int acount, int bcount, int ccount, int dcount, int fcount){

    int totalofgrades = acount + bcount + ccount + dcount + fcount;      
    System.out.print(totalofgrades);            
    }

    public static double getApercent(int a){
        double ap;      
        ap = (a/a * 100) + 0.5; 
        return Math.round(ap);        
    }

    public static double getBpercent(int b){            
        double bp;
        bp = (b/b * 100) + 0.5;
        return Math.round(bp);          
    }

 public static double getCpercent(int c){           
        double cp;
        cp = (c/c * 100) + 0.5;
        return Math.round(cp);          
    }

 public static double getDpercent(int d){           
        double dp;
        dp = (d/d * 100) + 0.5;
        return dp;          
    }

 public static double getFpercent(int f){           
        double fp;
        fp = (f/f * 100) + 0.5;
        return fp;          
    }   
}

这里有点猜测。但计算百分比的方法似乎不适用。再次,假设;但要计算整体的百分比,您可以使用以下公式
percentage=part/all*100

e、 g

我们有9个等级,3个是A,3个是B,2个是C,1个是D,0个是E

那么我希望百分比如下:

33% A  // 3 / 9 * 100
33% B  // 3 / 9 * 100
22% C  // 2 / 9 * 100
11% D  // 1 / 9 * 100
0% E   // 0 / 9 * 100
需要指出的另一点是,带有两个整数的运算符
/
进行整数除法。所以
3/9==0

您可以用更通用的版本替换所有特定的方法

public static double getPercentage(int gradeCount, int totalNumberOfGrades) {
  double percentage = ( gradeCount / (double) totalNumberOfGrades * 100); 
  return Math.round(percentage);
}

我不断出错,不知道该怎么办
。。。我们也不知道,因为你从来没有告诉我们错误是什么。确切的问题是什么?a/a是基础数学。结果将是1。例如,10/10=1在Totalgrades中,我试图在getApertent()方法中获得Acount、Bcount等的总数。我正在尝试这样做“a/totalgrades()*100+0.5您需要在主方法中调用totalgrades()方法,并将输入参数传递给此方法。我建议您最好学习并遵循基本运算符优先表(Java)以及基本数学。谢谢@user2157247非常感谢您的帮助!