You are required to write a program to analyze the marks distribution. (ANSWER I
ID: 3833301 • Letter: Y
Question
You are required to write a program to analyze the marks distribution. (ANSWER IN JAVA)********************
First prompt the user for the number of students in the class. And then create an integer array with the specified size to read and store the marks of all the students. Finally print the following:
(a) number of students who scored HD (80 – 100) in the class
(b) number of students who scored DI (70 – 79) in the class
(c) number of students who scored CR (60 - 69) in the class
(d) number of students who scored PA (50 – 59) in the class
Sample Input /Output 1:
Enter the number of students 5
Enter marks for student 1 : 90
Enter marks for student 2 : 76
Enter marks for student 3 : 67
Enter marks for student 4 : 58
Enter marks for student 5 : 59
PA count is 2
CR count is 1
DI count is 1
HD count is 1
2. Complete the program below to print the average marks of students and the marks and names of those scoring above average.
import java.util.*;
public class MarksProcessing2
{
public static void main(String args[])
{
String names[] = {"Bill", "Chew","David","Ravi","Smith","Teo"};
int marks[] = {70,65,90,34,56,38};
}
}
}
Expected Output
Average mark is 58.833333333333336
Student scoring above average
Bill 70
Chew 65
David 90
Explanation / Answer
1) Java program for the first question is as follows.
/* import util package for Scanner class */
import java.util.*;
public class ResultAnalysis{
public static void main(String []args){
/* T0 store marks */
int marks[];
/*Initialize variables as necessary */
int studentCount = 0,i = 0,HD=0,DI=0,CR=0,PA=0;
Scanner s = new Scanner(System.in);
/* Prompt for number of students */
System.out.println("Enter the number of students:");
/* Read number of students */
studentCount = s.nextInt();
/* Create array to read marks */
marks = new int[studentCount];
/* Read and process the marks as required */
for(i=0;i<studentCount;i++)
{
/* Prompt for the marks of each student */
System.out.printf("Enter marks for student %d:",i+1);
/* Read the marks for each student */
marks[i] = s.nextInt();
/* See which category is the student belong to PA,CR,DI,HD */
switch(marks[i]/10)
{
case 10:
case 9:
case 8: HD++; break;
case 7: DI++; break;
case 6: CR++; break;
case 5: PA++; break;
}
}
/*Display the counts */
System.out.printf("PA Count is %d CR Count is %d DI Count is %d HD Count is %d ",PA,CR,DI,HD);
}
}
2) Program for second question is as follows.
import java.util.*;
public class MarksProcessing2
{
public static void main(String args[])
{
/* Names of students */
String names[] = {"Bill", "Chew","David","Ravi","Smith","Teo"};
/* Marks of students */
int marks[] = {70,65,90,34,56,38};
int i=0;
double sum = 0, average = 0;
/* Find sum of all marks */
for(i=0;i<6;i++)
{
sum = sum+marks[i];
}
/* Compute the average marks */
average = sum/i;
/* Display the average MArks */
System.out.println("Average Mark is "+average);
/* Display the details of students whose marks are greater than the average marks */
System.out.println("Student scoring above average:");
for(i=0;i<6;i++)
{
if(marks[i] > average)
{
System.out.println(names[i]+" "+marks[i]) ;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.