Program that asks for the notes, adds them and makes the average

-1

I have to do a program that asks for the practical note and the theory note and calculates the final grade, the practical one is 30% and the theory 70%, a 5 is needed in the theory and a 5 in the theory. practice to do the average. I have done the program so what happens is that if I give a grade lower than 5, I add the notes but not the multiples by the percentages, then I always give the notes as approved.

import java.util.Scanner;

public class notes {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    double notaPracticas=0;

    double notaTeoria=0;

    double notaFinal=0;

    Scanner teclado=new Scanner(System.in);

    System.out.println("Introduce tu nota de prácticas");

    notaPracticas=teclado.nextDouble();

     if (notaPracticas>=5) {

         notaPracticas=notaPracticas*0.30;

         System.out.println(notaPracticas);

    } else if (notaPracticas<5) {

        System.out.println("Nota incorrecta");

    }

    System.out.println("Introduce tu nota de teoría");

    notaTeoria=teclado.nextDouble();

    if (notaTeoria>=5) {

        notaTeoria=notaTeoria*0.70;

        System.out.println(notaTeoria); 


    }else if (notaTeoria<5)

        System.out.println("Nota incorrecta");

    notaFinal=notaPracticas+notaTeoria;

    System.out.println(notaFinal);
}

}

    
asked by marxal 19.09.2017 в 20:52
source

2 answers

0

Your problem is in the misuse of the if and only multiply by your percentages if the note is greater than or equal to 5, if you want to anyway enter a note multiply it by your percentages if or if you should do the following:

public static void main (String [] args) {
    // TODO Auto-generated method stub

double notaPracticas=0;
double notaTeoria=0;
double notaFinal=0;
Scanner teclado=new Scanner(System.in);

// practice note

System.out.println("Introduce tu nota de prácticas");
notaPracticas=teclado.nextDouble();
notaPracticas=notaPracticas*0.30;
System.out.println(notaPracticas);


    // note of theory

System.out.println("Introduce tu nota de teoría");
notaTeoria=teclado.nextDouble();
notaTeoria=notaTeoria*0.70;

// final grade

notaFinal=notaPracticas+notaTeoria;
System.out.println(notaFinal);

// Conditional according to your criteria print approved or not approved }

    
answered by 19.09.2017 в 21:04
0

Based on the statement you have made, I have made a small example of how I would do it. First I ask for the notes, then I check that none is less than 5 and if I pass the test I calculate the final grade with the formula of (teo*0.7)+(pra*0.3) .

import java.util.Scanner;
public class notas {
    public static void main(String[] args) {
        double notaPracticas, notaTeoria, notaFinal = 0;
        Scanner teclado = new Scanner(System.in);

        //Pedir datos por consola
        System.out.println("Introduce tu nota de prácticas");
        notaPracticas = teclado.nextDouble();
        System.out.println("Introduce tu nota de teoría");
        notaTeoria=teclado.nextDouble();

        //Tratar los datos
        if (notaTeoria < 5)
            System.out.println("Teoría suspensa, no se puede hacer la media")
        else if (notaPracticas < 5) 
            System.out.println("Prácticas suspensas, no se puede hacer la media.");
        else {
            notaFinal = (notaPracticas*0.30)+(notaTeoria*0.70)
            System.out.println("Tú nota final es de: '" + notaFinal + "' ptos.");
        }
    }
}

On the other hand, responding directly to your question . Note that if the note is less than 5 it does not pass through the percentage multiplier, since it is within the if(nota >= 5) , so if you want to show the multiplied note (although it does not seem necessary, since you should not do average) Take it out.

Another point, be careful with the use of if() else if() , it is better that you use if() else . Because although in this case the operation is the same, it may cause some headache in the future.

I hope you have been helpful;)

    
answered by 19.09.2017 в 22:52