简体   繁体   中英

how can I take one methods result as another methods' parameter

I need to take this "over" statement under the overallmethod as finalmethods' parameter, how can I do this. I want to learn the final letter but to do that I want to access over statement.

public static void overallmethod(int quiz1,int quiz2,int quiz3,int     midterm,int grade){
          double quizzes = ( ((quiz1*10) + (quiz2*10) + (quiz3*10)) *25) /300;
          double finalg = ( grade * 40) / 100;
          double mid = (midterm * 35) / 100;
          double over = quizzes + finalg + mid;
          System.out.println("Your overall score is: " + over);
      }


        public static void finalmethod(double over){


        if(over <= 100 && over >= 90){

            System.out.println("Your final letter is: A");
        }
        else if(over >= 80) {
            System.out.println("Your final letter is: B");
        }
        else if (over >= 70) {
            System.out.println("Your final letter is: C");
        }
        else if (over >= 60) {
            System.out.println("Your final letter is: D");
        }
        else{
            System.out.println("Your final letter is: F");
        }
    }

You're going to need to return the variable over and change your return type to double .

public static double overallmethod(int quiz1,int quiz2,int quiz3,int midterm,int grade)
{          
    //Your code
    return over;
}

Then simply pass the value returned from the overallmethod to finalmethod .

Make your overall function return the value of over. Then just call the overall function inside the parameter list of finalmethod

over is not a statement, it is a local variable now. Just make it class attribute:

public static double over

The best solution would be to declare over as a private int outside both the methods, ie it should have visibility to all the methods in that class (class variable).

Now compute the overall score in the overallMethod and store it to the over variable.

Next, make a public method getOver() which returns the value of over, and call finalMethod in this way : ClassName.finalMethod(objectOfClass.getOver())

通过将方法的返回类型更改为double,然后将该方法中的值传递给final方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM