Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Compare Two Students

 Compare Two Students

brown wooden door

The program must accept the name age and registration number of two students as the input. The details of the two students are equal. Else the program must print "NOT EQUAL" as the output. Ignore 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

20uec 147

HECTOR

21

20UEC147

Output: EQUAL


Example Input/Output 2:

Input:

GAVIN

22

20uec 147

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 


JAVA PROGRAM :

 

import java.util.*;

class Student

{

private String name,country;

private int age;

public Student(String name,int age,String country){

this.name = name;

this.age = age;

this.country = country;

}

public Boolean equals(Student other){

if(this.name.equalsIgnoreCase(other.name)&&this.country.equalsIgnoreCase(other.country)&& this.age ==other.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



IMAGE FROM : https://unsplash.com/photos/JVD3XPqjLaQ




 

Post a Comment

Previous Post Next Post