public static void main (String[] args) throws java.lang.Exception { Scanner sc
ID: 3904514 • Letter: P
Question
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many students");
int n = sc.nextInt();
int a[] = new int[100];
int b[] = new int[100];
int total[] = new int[100];
for(int j =1;j<=n;j++)
{
int sum = 0;
System.out.println("Enter the student"+j+"Scores");
for(int i =1;i<=4;i++)
{
System.out.println("Exam #"+i+"Score");
a[i] = sc.nextInt();
System.out.println("Assigment #"+i+"Score");
b[i] = sc.nextInt();
sum = a[i]+b[i]+sum;
}
total[j] = sum;
}
for(int i =1;i<=n;i++)
{
System.out.println(total[i]);
if(total[i]>=450)
{
System.out.println("A");
}
else{
if(total[i]>=400)
{
System.out.println("B");
}
else
{
if(total[i]>=350)
{
System.out.println("C");
}
else
{
if(total[i]>=300)
{
System.out.println("D");
}
else
{
System.out.println("F");
}
}
}
}
}
}
}
How can I add to this code the following:
the criterion of the grade A is
A: >= Average of the students + (2 × Standard Deviation of the students)
B: >= Average of the students + (1 × Standard Deviation of the students) (but less than “A”)
C: >= Average of the students (but less than “B”)
D: >= Average of the students – (1 × Standard Deviation of the students) (but less than “C”)
F: < Average of the students – (2 × Standard Deviation of the students)
Explanation / Answer
If you have any doubts, please give me comment..
import java.util.*;
public class GradingApp {
public static void main(String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many students");
int n = sc.nextInt();
int a[] = new int[100];
int b[] = new int[100];
int total[] = new int[100];
for (int j = 1; j <= n; j++) {
int sum = 0;
System.out.println("Enter the student" + j + "Scores");
for (int i = 1; i <= 4; i++) {
System.out.println("Exam #" + i + "Score");
a[i] = sc.nextInt();
System.out.println("Assigment #" + i + "Score");
b[i] = sc.nextInt();
sum = a[i] + b[i] + sum;
}
total[j] = sum;
}
double mean = 0.0, sd = 0.0;
for (int i = 1; i <= n; i++) {
mean += total[i];
}
mean /= n;
for (int i = 1; i <= n; i++) {
sd += (total[i] - mean) * (total[i] - mean);
}
sd /= n;
sd = Math.sqrt(sd);
for (int i = 1; i <= n; i++) {
System.out.println(total[i]);
if (total[i] >= mean + (2 * sd)) {
System.out.println("A");
} else if (total[i] >= mean + (1 * sd)) {
System.out.println("B");
} else if (total[i] >= mean) {
System.out.println("C");
} else if (total[i] >= mean - (1 * sd)) {
System.out.println("D");
} else {
System.out.println("F");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.