Answer to Question #266757 in Java | JSP | JSF for Cccc

Question #266757

How to use array to record the student profiles ?

How to Create a Student Class?



1
Expert's answer
2021-11-16T05:21:20-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


package com.company;

//Let us define a class called Student
class Student{
    public static void main(String arg[])
    {
        //declare and initialize an array with student names
        String student_names[] = { "Kelly Daniel", "Fred Syoks", "Eve Wambo", "Morreen Mutua", "Flex Asava" };
        //declare and initializa an array with marks
        int student_marks[] = { 45, 78, 83, 58, 93 };

        //Now let us print the students details and the grade
        int array_length = student_marks.length;
        System.out.println("\n");
        for(int i = 0; i < array_length; i++)
        {
            if(student_marks[i]>=70 && student_marks[i]<=100)
            {
                System.out.println(student_names[i]+ " has "+student_marks[i]+"marks and the grade is A");
            }
            else if(student_marks[i]>=60)
            {
                System.out.println(student_names[i]+ " has "+student_marks[i]+" marks and the grade is B");
            }
            else if(student_marks[i]>=50)
            {
                System.out.println(student_names[i]+ " has "+student_marks[i]+" marksmarks and the grade is C");
            }
            else if(student_marks[i]>=40)
            {
                System.out.println(student_names[i]+ " has "+student_marks[i]+" marks and the grade is D");
            }
            else if(student_marks[i]>=0)
            {
                System.out.println(student_names[i]+ " has "+student_marks[i]+" marks and the grade is F");
            }
            else
            {
                System.out.println("Invalid marks for student"+student_names[i]);
            }
        }
    }
}


SAMPLE PROGRAM OUTPUT



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS