Problem in calculating average

0

I'm trying to make a program, which gives the grade of two tests, P1 and P2. You add and divide by 2 to get the average. If it is greater than 6, the program returns the following sentence: Approved . If the average is less than 4, the program returns the following sentence: Disapproved . Now, if the grade is between 4 and 6, the program asks for the grade of the proof of recovery (VS), and if it is greater than 6, it returns: Approved , or if the grade is smaller which 6 returns: Disapproved .

I wanted to ask for help, where I went wrong with the problem.

Note: I can not use Scanner. I have to keep this anyway, but I can not run the program.

class Media {
    public static double Media( float P1, float P2) {
        double Media = (P1 + P2) / 2;
    } 

    public static double VS( float nota) {
        double VS = nota;
    }

    public static void main(String [] args) { 
        if (Media >= 6) { 
            System.out.println("Aprovado.");
        } 
        else if (Media < 4) {
            System.out.println("Reprovado."); 
        } 
        else { 
            if( nota >= 6) {
                System.out.println("Aprovado."); 
            } 
            else { 
                System.out.println("Reprovado."); 
            } 
        } 
    } 
}
    
asked by anonymous 04.04.2014 / 02:21

1 answer

1

Your code has some problems:

  • Media is already the name of the class, therefore it should not be used to designate the name of a method because in this way it is confused with a possible constructor of the same;
  • Define whether you will use float or double to work properly with the method that returns the average of notes;
  • Your VS method is initializing a local variable that has no functionality at all;
  • Your methods are not returning any value;
  • When calling the method that calculates the mean within main , you are forgetting to pass the arguments for the test scores P1 and P2;
  • You need to get all test scores (P1, P2, and Recovery) in some way, either by requesting input by the user or not.

One possible solution would be:

class Media {

    public static float media(float P1, float P2) {
        return (P1 + P2) / 2;
    } 

    public static void main(String [] args) { 

        float notaP1 = 10, notaP2 = 5, notaRecuperacao = 6;

        if ( media(notaP1, notaP2) >= 6) { 
            System.out.println("Aprovado.");
        } 
        else if (media(notaP1, notaP2) < 4) {
            System.out.println("Reprovado."); 
        } 
        else { 
            if( notaRecuperacao >= 6) {
                System.out.println("Aprovado."); 
            } 
            else { 
                System.out.println("Reprovado."); 
            } 
        } 
    } 
}
    
04.04.2014 / 02:49