Compare Two Students

Compare Two Students: The program must accept the nameage and registration number of two students as the input. The program must print the string value “EQUAL” if the details of the two students are equal. Else the program must print “NOT EQUAL” as the output. Ignore the case of alphabets while comparing the name and the registration number of two students.

Your task is to define the class Student so that the program runs successfully.

Example Input/Output 1:
Input:
Hector
21
20uec147
HECTOR
21
20UEC147

Output:
EQUAL

Example Input/Output 2:
Input:
GAVIN
22
20uec147
Gavin
22
21UME147

Output:
NOT EQUAL

Example Input/Output 3:
Input:
Bhuvana
15
80014
Buvanaa
15
80014

Output:
NOT EQUAL

Example Input/Output 4:
Input:
Pavithra
21
XY4001
Babloo
21
xy4001

Output:
NOT EQUAL

import java.util.*;
class Student
{
    String name,country;
    int age;
    Student(String name,int age , String country){
        this.name = name;
        this.age = age;
        this.country = country;
    }
    public boolean equals(Student s){
        if(this.name.equalsIgnoreCase(s.name)&& this.country.equalsIgnoreCase(s.country)&& this.age==s.age)
        return true;
        return false;
    }
}
public class Hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Student student1 = getStudent(sc);
        Student student2 = getStudent(sc);
        System.out.println(student1.equals(student2) ? "EQUAL" : "NOT EQUAL");
    } //end of main method
    private static Student getStudent(Scanner sc) {
        String name = sc.nextLine().trim();
        int age = Integer.parseInt(sc.nextLine().trim());
        String country = sc.nextLine().trim();
        return new Student(name, age, country);
    } // end of getCitizen method
} //end of Hello class

Previous Article

Define class Rectangle

Next Article

C - Python - 017

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *