Array Java 2
Array Java 2
1. Write a program that reads (fictitious) student test scores in the range 0
through 100 and print the following statistics to two decimal places:
The difference between the average score and the student’s score (this can
be either positive or negative).
The grade letter where
A is a score of 90 or greater.
B is a score of 80 through 89.99.
C is a score of 70 through 79.99
D is a score of 60 through 69.99
E is a score of less than 60.
PROGRAM:
import java.util.Scanner;
public class Lab6 {
public static void main(String[] args) {
System.out.println("****STUDENT MARKSHEET RECORD******");
Scanner obj=new Scanner(System.in);
int totalstu;
double sum=0;
int max=0;
int min=0;
int i;
System.out.println("Enter total Number of student in your List ?");
totalstu=obj.nextInt();
int roll[]=new int[totalstu];
double marks[]=new double[totalstu];
System.out.println("*****************");
for( i=0;i<totalstu;i++)
{
System.out.println("Roll Number and Marks of Following Students are : ");
roll[i]=obj.nextInt();
marks[i]=obj.nextDouble();}
// System.out.println("Calculating Sum !");
for( i=0;i<totalstu;i++){
sum=sum+marks[i];}
// System.out.println("Calculating Average Of result !");
double avg=sum/totalstu;
// System.out.println("Calculating Difference between avg score and student
score ! ");
double[] dis=new double[totalstu];
for( i=0;i<totalstu;i++) {
dis[i]=marks[i]-avg;}
// System.out.println("Finding Maximum Score!");
for( i=0;i<totalstu;i++){
if(marks[max]>marks[i]){
//marks[max]=marks[i];
max=i;}}
for( i=0;i<totalstu;i++){
if(marks[min]<marks[i]){
//marks[min]=marks[i];
min=i;}}
// System.out.println("Finding student Scoring higghest then Average !");
int more=0;
for( i=0;i<totalstu;i++){
if(marks[i]>avg){
more++;}}
// System.out.println("Finding Grade !");
String []grade=new String[totalstu];
for( i=0;i<totalstu;i++){
if(marks[i]>=90){
grade[i]=" Got A grade";}
else if(marks[i]>=80 && marks[i]<=89.99){
grade[i]=" Got B grade ";}
else if(marks[i]>=70 && marks[i]<=79.99){
grade[i]="Got C grade ";}
else if(marks[i]>=60 && marks[i]<=69.99)
{
grade[i]="Got D grade";
}
elsegrade[i]="Got E grade";
System.out.println("Roll Number + Score + difference + grade ----->"+roll[i]
+" ,"+marks[i]+", "+dis[i]+", "+grade[i]);}
System.out.println("Average of total Score of student is : "+avg);
System.out.println(" Low Scoring Student : "+marks[max]);
System.out.println(" High Scoring Student : "+marks[min]);
System.out.println("Number of Student above Average score is :"+more);
}}
OUTPUT: