0% found this document useful (0 votes)
53 views3 pages

Java Qns

This document provides instructions for writing Java programs to solve different problems involving employees and students. It includes creating classes with attributes like name, age, id, etc. and writing methods to return the employee or student with the maximum value for a given attribute by comparing object values. Main methods are used to instantiate objects, set attribute values, call methods and display results. Students are compared based on having the same age and city. Output is tested by compiling and running the Java files.

Uploaded by

Smashit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Java Qns

This document provides instructions for writing Java programs to solve different problems involving employees and students. It includes creating classes with attributes like name, age, id, etc. and writing methods to return the employee or student with the maximum value for a given attribute by comparing object values. Main methods are used to instantiate objects, set attribute values, call methods and display results. Students are compared based on having the same age and city. Output is tested by compiling and running the Java files.

Uploaded by

Smashit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AREA :

SWAP EMPLOYEE NAMES :

CHECK MAIL :

EMPLOYEE WITH MAX AGE :

Write constructor to initialize the attributes.

Try to compile the class with command:

javac Employee.java

Create file Solution.java

Create public class Solution in that file.

Write a method getEmployeeWithMaxAge which takes three Employee objects as input parameters and
returns the Employee object with maximum age.

Declare main method in Solution class. Create three Employee objects e1, e2 and e3.

Set age values for these objects as 22,33 and 44, names as "aaa", "bbb", and "ccc" and ids as 1,2 and 3
respectively.
Call getEmployeeWithMaxAge method from main method.

Display the id, name and age of employee returned with space in between.

Compile the class using command javac Solution.java

Execute Solution class using command "java Solution" and test the output. Correct result should display
"3 ccc 44"'

EMPLOYEE WITH SAME AGE AND CITY :


Create a file Student.java, using touch Student.java

Create public class Student with below attributes

 name String
 double age
 city String

Write constructor to initialize the attributes.

Try to compile the class with command:

javac Student.java

Create a Solution.java file, using touch Solution.java

Create public class Solution in that file.

Write a method studentCountWithSameCityAndAge which takes three Student objects as


input parameters and returns the count of students with same city and age.

Consider the logic as below:


 Method returns 3 if all students have same city and age.
 Method returns 2 if two students have same city and age.
 For any other combinition, method will return 0.

Declare main method in Solution class. Create three Student objects e1, e2 and e3.
Set below values (without using Scanner. Hence set hard coded values in main method
itself):

 e1 will have attributes "aaa",15,"mumbai"


 e2 will have attributes "bbb",15,"mumbai"
 e3 will have attributes "ccc",17,"mumbai"

Call studentCountWithSameCityAndAge method from main method.

Display the output of this method. It should be 2.

Compile the class using command javac Solution.java

Execute Solution class using command java Solution and test the output. Correct result
should display "2".

ARRAYS AND ITERATIONS :

SORT ODD VALUES

SWAP VALUES IN AN ARRAY

SEQUENTIAL DISTANCE

SECOND LOW AGE

You might also like