Answer:
The Java pseudocode and the Java code itself are given for better understanding
Step-by-step explanation:
Java pseudocode
- preAvg(int test[], int qgrade):
- sum := 0
- for each testi in test:
- sum := sum + testi
- sum := sum + qgrade
- return sum / 5
- additional(int at):
- res = (at * 1.5) / 30
- return res
- total = preAvg(test, qgrade) + additional(at)
Java code
import java.util.Scanner;
public class CSE1322 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int test[] = new int[4];
for(int i=1;i<=4;i++){
System.out.println("Enter your result for test"+i+": ");
test[i-1] = scanner.nextInt();
}
System.out.println("Enter the average quiz grade: ");
int qgrade = scanner.nextInt();
System.out.println("Enter the classes you attended(out of 30): ");
int at = scanner.nextInt();
double avg = preAvg(test,qgrade);
System.out.println("Your average before attendance is: "+avg);
double add = additional(at);
System.out.println("You receive an additional "+add+" points for attendance");
double total = avg + add;
System.out.println("Final grade is : "+total);
}
private static double additional(int at) {
double res = ((double)at * 1.5)/30.0;
return res;
}
private static double preAvg(int[] test, int qgrade) {
double sum = 0;
for(int i=0;i<4;i++) sum += test[i];
sum += qgrade;
return sum/5;
}
}