You are on page 1of 5

/************************************/

//-------------STEP 1----------------------------

/**************************************

/*******Student.java (same for all 3 case)*****/

public class Student {

private String name;

private double age;

private String city;

public Student(String name, double age, String city) {

this.name = name;

this.age = age;

this.city = city;

public String getCity() {

return this.city;

public double getAge() {

return this.age;

}
}

/*********Solution.java***********/

import java.util.*;

public class Solution {

public static int studentCountWithSameCityAndAge(Student s1, Student s2, Student s3) {

int sameCount = 0;

if ((s1.getAge() == s2.getAge()) && ((s1.getCity().equals(s2.getCity())))) {

if ((s1.getAge() == s3.getAge()) && ((s1.getCity().equals(s3.getCity())))) {

sameCount = 3;;

} else {

sameCount = 2;

} else if ((s3.getAge() == s2.getAge()) && ((s3.getCity().equals(s2.getCity())))) {

sameCount = 2;

return sameCount;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Student se1 = new Student("aaa",15,"mumbai");


Student se2 = new Student("bbb",15,"mumbai");

Student se3 = new Student("ccc",17,"mumbai");

System.out.println(studentCountWithSameCityAndAge(se1,se2,se3));

/***********STEP 2 : SOLUTION.JAVA **********/

import java.util.*;

public class Solution {

public static int studentCountWithSameCityAndAge(Student s1, Student s2, Student s3) {

int sameCount = 0;

if ((s1.getAge() == s2.getAge()) && ((s1.getCity().equals(s2.getCity())))) {

if ((s1.getAge() == s3.getAge()) && ((s1.getCity().equals(s3.getCity())))) {

sameCount = 3;;

} else {

sameCount = 2;

} else if ((s3.getAge() == s2.getAge()) && ((s3.getCity().equals(s2.getCity())))) {

sameCount = 2;

return sameCount;

}
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Student se1 = new Student(sc.nextLine(),sc.nextDouble(), sc.nextLine());

Student se2 = new Student(sc.nextLine(),sc.nextDouble(), sc.nextLine());

Student se3 = new Student(sc.nextLine(),sc.nextDouble(), sc.nextLine());

System.out.println(studentCountWithSameCityAndAge(se1,se2,se3));

/***********************STEP 3 : Solution.java *********/

import java.util.*;

public class Solution {

public static int studentCountWithSameCityAndAge(Student s1, Student s2, Student s3) {

int sameCount = 0;

if ((s1.getAge() == s2.getAge()) && ((s1.getCity().equals(s2.getCity())))) {

if ((s1.getAge() == s3.getAge()) && ((s1.getCity().equals(s3.getCity())))) {

sameCount = 3;;

} else {

sameCount = 2;

} else if ((s3.getAge() == s2.getAge()) && ((s3.getCity().equals(s2.getCity())))) {


sameCount = 2;

return sameCount;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Student se1 = new Student("aaa",15,"delhi");

Student se2 = new Student("bbb",16,"mumbai");

Student se3 = new Student("ccc",17,"mumbai");

System.out.println(studentCountWithSameCityAndAge(se1,se2,se3));

You might also like