KnowledgeBoat Logo

Computer Applications

Define a class called Student to check whether a student is eligible for taking admission in class XI with the following specifications:

Data MembersPurpose
String nameto store name
int mmto store marks secured in Maths
int scmto store marks secured in Science
double compto store marks secured in Computer
Member MethodsPurpose
Student( )parameterised constructor to initialize the data members by accepting the details of a student
check( )to check the eligibility for course based on the table given below
void display()to print the eligibility by using check() function in nested form
MarksEligibility
90% or more in all the subjectsScience with Computer
Average marks 90% or moreBio-Science
Average marks 80% or more and less than 90%Science with Hindi

Write the main method to create an object of the class and call all the member methods.

Java

Java Constructors

54 Likes

Answer

import java.util.Scanner;

public class Student
{
    private String name;
    private int mm;
    private int scm;
    private int comp;

    public Student(String n, int m, int sc, int c) {
        name = n;
        mm = m;
        scm = sc;
        comp = c;
    }

    private String check() {
        String course = "Not Eligible";
        double avg = (mm + scm + comp) / 3.0;
        
        if (mm >= 90 && scm >= 90 && comp >= 90)
            course = "Science with Computer";
        else if (avg >= 90)
            course = "Bio-Science";
        else if (avg >= 80)
            course = "Science with Hindi";

        return course;
    }
    
    public void display() {
        String eligibility = check();
        System.out.println("Eligibility: " + eligibility);
    }
    
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Name: ");
        String n = in.nextLine();
        System.out.print("Enter Marks in Maths: ");
        int maths = in.nextInt();
        System.out.print("Enter Marks in Science: ");
        int sci = in.nextInt();
        System.out.print("Enter Marks in Computer: ");
        int compSc = in.nextInt();
        
        Student obj = new Student(n, maths, sci, compSc);
        obj.display();
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Define a class called Student to check whether a student is eligible for taking admission in class XI with the following specifications: Write the main method to create an object of the class and call all the member methods.

Answered By

20 Likes


Related Questions