0% found this document useful (0 votes)
86 views28 pages

PRA1 JAVA 20june2024 Pune With Answers 1

The document contains a series of multiple-choice questions related to Advanced Java and JDBC, each with a score of 5 points. Topics include inheritance, exception handling, collections, and JDBC operations. Each question provides four answer options, testing knowledge on Java programming concepts and JDBC functionalities.

Uploaded by

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

PRA1 JAVA 20june2024 Pune With Answers 1

The document contains a series of multiple-choice questions related to Advanced Java and JDBC, each with a score of 5 points. Topics include inheritance, exception handling, collections, and JDBC operations. Each question provides four answer options, testing knowledge on Java programming concepts and JDBC functionalities.

Uploaded by

snowj4582
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

PRA1_JAVA_20June2024_P… 120 minutes

Question - 1 SCORE: 5 points


Adv Java 1

Adv Java 1

What is the type of inheritance demonstrated below?


public class Vehicles {
......
}
public class Cars extends Vehicles {
......
}
public class Trucks extends Vehicles {
......
}
public class Bus extends Vehicles {
......
}

Single

Multiple

Multilevel

Hierarchical

Question - 2 SCORE: 5 points


Adv Java 2

Adv Java 2

In the statement : import java.util.Scanner; what does Scanner represent?

package

class

library

interface

Question - 3 SCORE: 5 points


Adv Java 3

Adv Java 3

1/28
Consider that we have declared a priority queue of type String-queue that contains the following elements that are added to the queue in the following
order: Amrita,Vijay,Jaikar,Raj.Assuming the code is syntactically correct,What will be ouput if the following statement?
System.out.println(queue.element());

Amrita

Raj

Amrita
Raj
Jaikar
Vijay

Question - 4 SCORE: 5 points


Adv Java 4

Adv Java 4

Consider we have created an ArrayList of type String . The following elements are added to the list in the following order-Ravi,Vijay,Chavi,Ajay,Mani.Assuming
the code is syntactically correct,What will be the output if the following code ?
import java.util.*;
............
Iterator itr=list.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
..........

Ravi
Mani
Vijay
Chavi
Ajay

Ravi
Vijay
Mani
Chavi
Ajay

Ravi
Vijay
Chavi
Mani
Ajay

Ravi
Vijay
Chavi
Ajay
Mani

Question - 5 SCORE: 5 points


Adv Java 5

Adv Java 5

2/28
Consider we have created a List of integers which consists of number 1,2,3 which are added to the list in the same order.Assuming the code is written
syntactically correct,What is the output of the following code?
int removedNumber = numbers.remove(1);
System.out.println("Removed Element: " + removedNumber);

Removed Element: 1

Removed Element: 3

Removed Element: 2

Error is displayed

Question - 6 SCORE: 5 points


Adv Java 6

Adv Java 6

Predict the output : class Vehicle {


void start() {
System.out.println("Vehicle started");
}
}
class Car extends Vehicle {
void start() {
System.out.println("Car started");
}
}
class Bike extends Vehicle {
void start() {
System.out.println("Bike started");
}
}
public class Test {
public static void main(String[] args) {
Vehicle v;
v = new Car();
v.start();
v = new Bike();
v.start();
}
}

Vehicle started Vehicle started

Car started
Bike started

Bike started
Car started

Compilation error

Question - 7 SCORE: 5 points

3/28
Adv Java 7

Adv Java 7

What will be the expected output of the following snippet : Set<String> set = new TreeSet<>();
set.add("banana");
set.add("apple");
set.add("mango");
System.out.println(set);

[banana, apple, mango]

[apple, banana, mango]

[mango, banana, apple]

[apple, mango, banana]

Question - 8 SCORE: 5 points


Adv Java 8

Adv Java 8

public class Demo {


public static void main(String[] args) {
int[] arr = new int[5];
try {
arr[10] = 10;
arr[4]=11;
System.out.println("Value inserted successfully!");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Array index out of bounds: " + e.getMessage());
} finally {
System.out.println(arr[4]);
System.out.println("Finally block executed.");
}
}
} What will be the output of the above code ?

Array index out of bounds: 10


Finally block executed.

Array index out of bounds: Index 10 out of bounds for length 5


11
Finally block executed.

Array index out of bounds: Index 10 out of bounds for length 5


0
Finally block executed

Array index out of bounds: No message


Finally block executed.

Question - 9 SCORE: 5 points

4/28
Adv Java 9

Adv Java 9

What will be the output for following code Snippet ? public class Demo {
public static void main(String[] args) {
List<Integer> list1 = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
List<Integer> list2 = new ArrayList<>(Arrays.asList(4, 5, 6, 7, 8));
list1.retainAll(list2);
System.out.println(list1);
}
}

[4,5]

[1,2,3,4,5]

[4,5,4,5]

[6,7,8]

Question - 10 SCORE: 5 points


Adv Java 10

Adv Java 10

What will be the output?


public class Test{
public static void main(String args[]) {
Map m = new HashMap();
m.put(null, "Test");
m.put(null, "Fest");
System.out.println(m);
}
}

{null=Fest} -- answer

{null=Test}

compilation error at 7 and 8

compilation error at 8, about can't override the value "Test"

Question - 11 SCORE: 5 points


Adv Java 11

Adv Java 11

what will be the output of following code ?

class Animal {
void eat() {
5/28
System.out.println("Eating");
}
}

class Bird extends Animal {


void eat() {
System.out.println("Bird eating");
}
}

public class Test {


public static void main(String[] args) {
Animal a = new Bird();
a.eat();
}
}

Eating

Bird eating

Compilation Error

Runtime Error

Question - 12 SCORE: 5 points


Adv Java 12

Adv Java 12

what will be the output of following code snippet ?

LinkedList<String> list = new LinkedList<>();


list.add("First");
list.add("Second");
list.addFirst("Third");
list.addFirst("Zero");
System.out.println(list.getFirst());

First

Second

Third

Zero

Question - 13 SCORE: 5 points


Adv Java 13

Adv Java 13

Analyze the following code snippet:

try {

6/28
int[] arr = new int[2];
arr[5] = 10;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("ArrayIndexOutOfBoundsException caught");
} finally {
System.out.println("Finally block executed");
}

What will be the output?

ArrayIndexOutOfBoundsException caught

Finally block executed

ArrayIndexOutOfBoundsException caught
Finally block executed

Compilation error

Question - 14 SCORE: 5 points


Adv Java 14

Adv Java 14

what will be the output of following code snippet ?

HashSet<String> set = new HashSet<>();


set.add("A");
set.add("B");
set.add("A");
set.add("C");
set.add("A");
set.add("C");
set.add("B");
set.add("D");
System.out.println(set.size());

Question - 15 SCORE: 5 points


Adv Java 15

Adv Java 15

What will be the output of following code snippet ?

class Parent {
void display() {

7/28
System.out.println("Parent");
}
}

class Child extends Parent {


void display() {
System.out.println("Child");
}
}

public class Test {


public static void main(String[] args) {
Parent p = new Child();
p.display();
}
}

Parent

Compilation Error

Runtime Error

Child

Question - 16 SCORE: 5 points


AdvanceJava_1_S

Advance_Java

Consider the following code snippet. What will be the output?


List<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add(1, "C");
System.out.println(list);

[A, C, B]

[A, B, C]

[C, A, B]

[A, B]

Question - 17 SCORE: 5 points


AdvanceJava_2_S

Advance_Java

What will happen if an exception is not caught in a Java program?

The program will continue executing.

The program will terminate.

The program will ignore the exception.

8/28
The exception will be handled by the JVM and the program will continue.

Question - 18 SCORE: 5 points


AdvanceJava_3_S

Advance_Java

Consider the following code snippet. What type of exception will be thrown?
int[] arr = new int[5];
System.out.println(arr[5]);

ArrayIndexOutOfBoundsException

NullPointerException

IndexOutOfBoundsException

ArithmeticException

Question - 19 SCORE: 5 points


AdvanceJava_4_S

Advance_Java

Consider the following code snippet. What will be the output?

class Animal {
void makeSound() {
System.out.println("Animal makes sound");
}
}

class Dog extends Animal {


void makeSound() {
System.out.println("Dog barks");
}
}

public class Test {


public static void main(String[] args) {
Animal a = new Dog();
a.makeSound();
}
}

Animal makes sound

Dog barks

Compilation error

Runtime error

Question - 20 SCORE: 5 points


AdvanceJava_5_S
9/28
Advance_Java

What is polymorphism in Java?

The ability to have multiple constructors in a class.

The ability of different classes to be treated as instances of the same class through inheritance.

The ability to write a class that can be used with any data type.

The ability to use multiple interfaces in a class.

Question - 21 SCORE: 5 points


JDBC 1

JDBC 1

Which among the following is the correct way to create a Statement object "sta" inside the Connection object "conn"?

Statement sta = conn.createStatement();

Statement sta = conn.Statement();

Statement sta = createStatement();

Statement sta = conn.Statementcreation();

Question - 22 SCORE: 5 points


JDBC 2

JDBC 2

public static void selectData(Connection c, String sql) throws SQLException{


Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
}
}
In the above code, what does "rs.getString(2)" do?

Inserts a string into the second column of the ResultSet

Updates a string in the second column of the ResultSet

Deletes a string from the second column of the ResultSet

Retrieves a string from the second column of the ResultSet

Question - 23 SCORE: 5 points


JDBC 3
10/28
JDBC 3

Which of the following method is used to perform DML statement-INSERT in JDBC?

executeResult()

executeQuery()

executeUpdate()

execute()

Question - 24 SCORE: 5 points


JDBC 4

JDBC 4

What is the purpose of a PreparedStatement in JDBC?

To execute SQL queries and retrieve results

To insert, update, or delete data in a database

To retrieve metadata about a database

To handle exceptions in JDBC operations

Question - 25 SCORE: 5 points


JDBC 5

JDBC 5

Which method in JDBC is used to execute an SQL query and retrieve the result as a ResultSet object?

executeQuery()

executeUpdate()

execute()

executeResult()

Question - 26 SCORE: 5 points


JDBC 6

JDBC 6

What should be present in blank for the below SQL statement ?


PreparedStatement ps = con.prepareStatement("select * from student");
ResultSet rs = ps.execute____();

11/28
Update

Select

Query

None of the above

Question - 27 SCORE: 5 points


JDBC 7

JDBC 7

Given the following code snippet, what will be the output?


String query = "SELECT name, age FROM Employees";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
System.out.println(rs.getString("name") + " " + rs.getInt("age"));
}
Assume the Employees table has the following data:
| name | age |
| John | 30 |
| Jane | 25 |

John 30
Jane 25

name age
John 30
Jane 25

Jane 25

John 30

Question - 28 SCORE: 5 points


JDBC 8

JDBC 8

What does setAutoCommit(false) do?

commits transaction after each query

explicitly commits transaction

does not commit transaction automatically after each query

never commits transaction

Question - 29 SCORE: 5 points


JDBC 9

12/28
JDBC 9

Which JDBC interface is responsible for managing transactions in JDBC?

java.sql.Connection

java.sql.Statement

java.sql.ResultSet

java.sql.Transaction

Question - 30 SCORE: 5 points


JDBC 10

JDBC 10

Which of these obtains a Connection?

Connection.getConnection(url)

Driver.getConnection(url)

DriverManager.getConnection(url)

new Connection(url)

Question - 31 SCORE: 5 points


JDBC 11

JDBC 11

How do you set a string parameter in a `PreparedStatement`?

setParameter()

setValue()

setString()

setText()

Question - 32 SCORE: 5 points


JDBC 12

JDBC 12

what the following code snippet does ?

if (rs.next()) {

13/28
// Process the row
}

set the maximum number of rows that a `Statement` object can return?

handle SQL warnings

check whether a `ResultSet` object contains more rows

Question - 33 SCORE: 5 points


JDBC 13

JDBC 13

what will be the output of following code snippet ?

try {
Connection connection = DriverManager.getConnection("jdbc:derby: :C//MyDB;create=true");
System.out.println("Connected to the database successfully.");
} catch (SQLException e) {
e.printStackTrace();
}

Error: Could not establish a connection.

Exception in thread "main" java.sql.SQLException: No suitable driver found

Connected to the database, but an error occurred.

Connected to the database successfully.

Question - 34 SCORE: 5 points


JDBC 14

JDBC 14

What must be the first characters of a database URL?

jdbc:

jdbc,

db:

db,

Question - 35 SCORE: 5 points


JDBC 15

JDBC 15

14/28
Which class is used to establish a connection to a database in JDBC?

Conncetion

Statement

DriverManager

ResultSet

Question - 36 SCORE: 5 points


JDBC_5_S

JDBC

What does JDBC stand for?

Java Database Connectivity

Java Data Connectivity

Java Database Command

Java Data Control

Question - 37 SCORE: 5 points


JDBC_4_S

JDBC

Which method is used to execute a query that returns a ResultSet object?

executeUpdate()

executeQuery()

execute()

executeResultSet()

Question - 38 SCORE: 5 points


JDBC_3_S

JDBC

Consider the following code snippet. What does it do?


String url = "jdbc:derby://localhost:3306/mydatabase";
Connection conn = DriverManager.getConnection(url);

It registers the JDBC driver.

15/28
It closes the database connection.

It establishes a connection to the MySQL database.

It executes a SQL query.

Question - 39 SCORE: 5 points


JDBC_2_S

JDBC

Which of the following is correct about PreparedStatement?

It is used for batch updates.

It is used to execute stored procedures.

It allows you to set parameters dynamically.

It doesn't support SQL queries.

Question - 40 SCORE: 5 points


JDBC_1_S

JDBC

Which of the following is a valid method to release a database connection in JDBC?

conn.close()

conn.disconnect()

conn.terminate()

conn.shutdown()

Question - 41 SCORE: 5 points


Java Web 1

Java Web 1

Which method takes responsibility to check the type of request received from the client and respond accordingly?

init()

service()

destroy()

request()

16/28
Question - 42 SCORE: 5 points
Java Web 2

Java Web 2

When a URL specific to a particular servlet is triggered, the _____________ method is invoked.

init()

service()

destroy()

request()

Question - 43 SCORE: 5 points


Java Web 3

Java Web 3

________________ method is called by the Servlet when wanting to halt the current or background threads

init()

service()

destroy()

request()

Question - 44 SCORE: 5 points


Java Web 4

Java Web 4

_jspinit() method is invoked in which phase of the JSP Life cycle?

Instantiation

Initialisation

Request Processing

Destroy

Question - 45 SCORE: 5 points


Java Web 5

Java Web 5

17/28
_jspservice() method is invoked in which phase of the JSP Life cycle?

Instantiation

Initialisation

Request Processing

Destroy

Question - 46 SCORE: 5 points


Java Web 6

Java Web 6

Which of the following code is used to get an attribute in a HTTP Session object in servlets?

session.getAttribute(String name)

session.alterAttribute(String name)

session.updateAttribute(String name)

session.setAttribute(String name)

Question - 47 SCORE: 5 points


Java Web 7

Java Web 7

What will be the output for the following code?


<html><body>
<% int i = 20 ;%>
<% while(i>=15) { %>
out.print(i);
<% } %>
</body></html>

20

15

2.02E+0.11

None of the above

Question - 48 SCORE: 5 points


Java Web 9

Java Web 9

18/28
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Out.println("<h2>Welcome to Servlets</h2>");
}
What will be displayed when this Servlet is accessed through a browser?

An Error message

Welcome

Welcome To Servlets

Compilation error

Question - 49 SCORE: 5 points


Java Web 10

Java Web 10

What is the purpose of the web.xml file in a servlet-based web application?

To define the HTML structure of web pages

To configure the servlet container and servlet mappings

To store client-side JavaScript code

To define the database schema

Question - 50 SCORE: 5 points


Java Web 11

Java Web 11

How do you set an attribute in a request object from a Servlet?

setAttribute()

addAttribute()

putAttribute()

setParam()

Question - 51 SCORE: 5 points


Java Web 12

Java Web 12

19/28
what the of following code snippet does?

<form action="submitServlet" method="post">


<input type="text" name="username" />
<input type="submit" value="Submit" />
</form>

read data from an HTTP request?

access session attributes in a Servlet

handle form submission in a JSP page

create a scriptlet in JSP

Question - 52 SCORE: 5 points


Java Web 13

Java Web 13

what the of following code snippet does?

RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp");


dispatcher.forward(request, response);

include a JSP file in another JSP file

forward a request from a Servlet to a JSP page?

handle form submission in a JSP page

used to read data from an HTTP request

Question - 53 SCORE: 5 points


Java Web 8

Java Web 8

Which of the following is a JSP declaration?

<%-- code --%>

<% code %>

<%= code %>

<%! code %>

Question - 54 SCORE: 5 points


Java Web 14

20/28
Java Web 14

How do you include a JSP file in another JSP file?

<include file="header.jsp"/>

<jsp:forward page="header.jsp"/>

<jsp:include>

<include page="header.jsp"/>

Question - 55 SCORE: 5 points


Java Web 15

Java Web 15

Which tag is used to create a scriptlet in JSP?

<scriptlet>

<jsp:scriptlet>

<%-- --%>

<% %>

Question - 56 SCORE: 5 points


JavaWeb_5_S

JavaWeb

What is the file extension for a JSP file?

.jsp

.html

.java

.xml

Question - 57 SCORE: 5 points


JavaWeb_3_S

JavaWeb

Consider the following code snippet. What will be the output if the servlet is accessed with the URL /hello?

21/28
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
PrintWriter out = response.getWriter();
out.println("Hello, World!");
}
}

Hello, Servlet!

Hello, World!

Compilation error

Runtime error

Question - 58 SCORE: 5 points


JavaWeb_2_S

JavaWeb

Consider the following code snippet in a JSP page. What will be the output?
<%! int count = 0; %>
<%= ++count %>

Compilation error

Runtime error

Question - 59 SCORE: 5 points


JavaWeb_4_S

JavaWeb

In JSP, which tag is used to forward the request to another resource (such as another JSP or servlet)?

<jsp:forward page="..."/>

<jsp:include page="..."/>

<%@ forward file="..."%>

<%! include file="..." %>

Question - 60 SCORE: 5 points


JavaWeb_1_S

JavaWeb

22/28
Which tag is used to insert a Java expression directly into the output in a JSP page?

<% %>

<%= %>

<%! %>

Question - 61 SCORE: 10 points


Arraylist_Iterator

You are required to manipulate an ArrayList of integers using an Iterator. Write a program that performs the following tasks:
Add several integers to the ArrayList.
Use the Iterator to remove all even numbers from the list.

Sample Input 1 :
Initial ArrayList: [1, 2, 3, 4, 5, 6]

Sample Output 1 :
After removing even numbers, the expected ArrayList should be: [1, 3, 5]

Question - 62 SCORE: 10 points


LINKEDLIST_REVERSESORT_CHECKELEMENT

Advanced_Java

Write a Java code that:


1. Accepts the size of a list,say n.
2. Create a Linked List of Strings of size n which accepts and stores values .
3. Accept an element, whose count is to be displayed (i.e. the number of times the element is present in the list), if present.
4. Display the count if the element that is being searched is present in the list else display the sorted list, sorted in descending order.

Sample Input 1
5
10
Sameeksha
5
Ritin
Sameeksha
Sameeksha

Sample Output1
2

Sample Input 2
3
1
Rekha
114
Seema

Sample Output2
Rekha
114
1
23/28
Question - 63 SCORE: 30 points
Advance Java - Flight

Java - Flight

NOTE: ANY MEANS OF INTENDED PLAGIARISM WHILE ATTEMPTING THIS QUESTION IS LIABLE TO HIGHEST POSSIBLE STRICT HR ACTIONS AS IT IS
VIOLATION OF INTEGRITY. HENCE, REFRAIN FROM ANY SUCH MEANS AND ATTEMPT THIS QUESTION AS PER YOUR EXPERTISE ONLY.

Create a class Flight with below attributes:

flightNumber : int
origin : String
destination : String
distance : double ( in miles)
pricePerMile : double (in dollars)

Write getters, setters and parameterized constructor in the above-mentioned attribute sequence as required.

Create class Solution with main method

Implement two static methods – findTotalPriceOfFlightByFlightNumber and findFlightWithSecondLowestPricePerMile in Solution class.

findTotalPriceOfFlightByFlightNumber
Create a static method findTotalPriceOfFlightByFlightNumber in the Solution class. This method will take two parameters, an array of Flight objects and
one int parameter (flight number) and return the total price of flight of mentioned flightNumber. If no flights are present in the array of Flight objects with
mentioned flight number , then the method should return zero.

Total Price = distance * pricePerMile

findFlightWithSecondLowestPricePerMile
Create a static method findFlightWithSecondLowestPricePerMilein the Solution class. This method will take an array of Flight objects and return the flight
object with the second lowest price .If no flights are present with the second lowest price per mile, then the method should return null.

These methods should be called from the main method.

Write code to perform the following tasks :

1. Take the necessary input variable and call findTotalPriceOfFlightByFlightNumber. For this method - The main method should print the total price of
flight with matching flight number given if the returned value is not 0, or it should print “No Flight found for mentioned flight number.”

2. Take the necessary input variable and call findFlightWithSecondLowestPricePerMile. For this method - The main method should print the flight details
of the flight object with second lowest price per mile if the returned value is not null, or it should print "No Flight found"

Note:

The above-mentioned static methods should be called from the main method. Also write the code for accepting the inputs and printing the outputs. Don't
use any static test or formatting for printing the result.

Just invoke the method and print the result

Note: All String comparison needs to be case in-sensitive.

24/28
You can use/refer to the below given sample input and output to verify your solution.

The 1st input taken in the main section is the number of flight objects to be added to the list of Flights.

The next set of inputs are flightNumber,origin,destination,distance( in miles),pricePerMile(in dollars)for each Flight object taken one after another and is
repeated for the number of Flights objects given in the first line of input.

Consider below sample input and output to test your code:

Sample input - 1

4
1001
New York
Los Angeles
2450
0.15
1002
London
Paris
215
0.25
1003
Tokyo
Sydney
4900
0.18
1004
Toronto
Vancouver
2100
0.22
1003

Sample Output - 1

Total Price - 882.0


flightNumber-1003
origin-Tokyo
destination-Sydney
distance-4900.0
pricePerMile-0.18

Sample Input - 2

5
1005
Dubai
Istanbul
2400
0.20
1006
Cape Town
Nairobi
3400
0.30
1007
Moscow
Berlin

25/28
1200
0.12
1008
Buenos Aires
Rio de Janeiro
1000
0.16
1009
Sydney
Auckland
1300
0.17
1006

Sample Output - 2

Total Price - 1020.0


flightNumber-1008
origin-Buenos Aires
destination-Rio de Janeiro
distance-1000.0
pricePerMile-0.16

Question - 64 SCORE: 30 points


Java Advance SBQ Event Management

CORE JAVA

Create a class Event with the below attributes:

eventId-int
eventname-String
location-String
eventfee-int
eventAttendee-int

The above attributes should be private. Write getters, setters and parameterized constructor as required.

Create class Solution with main method.

Implement two static method-findCountOfEventLocation and getLowestEventByPrice in solution class.

findCountOfEventByAttendee method:

This method will take array of Event objects and an integer value as input parameters.This method will return the count of event from an array of event
objects for the given eventAttendee (int parameter passed).

If no event with the given quantity is present in the array of event objects,then the method should return 0.

getLowestEventByPrice method:

This method will take array of object and an String value as input parameter.This method will return the event object with lowestPrice for the given
location.if no Product with the above condition present in the array of object then the method should return null.

Note- No event will have unique eventId


All searches should be case insensitive.

The above-mentioned static method should be called from the main method.

26/28
For findCountOfEventLocation method - The main method should print the returned count as it is if the returned value is greater than 0 or it should print
"No such event found.".

For getLowestEventByPrice method - The main method should print the eventname,location and fee from the returned event object if the returned value is
not null. If the returned value is null then it should print "No such event found.".

Before calling these static methods in main, use Scanner object to read the values of four event objects referring to attributes in the above-mentioned
attribute sequence.

Next, read the value of the int parameter and a String parameter for capturing eventAttendee and event fees respectively.

Consider below sample input and output:

Test case1:
101
Marriage
Mumbai
40000
200
102
Birthday
kolkata
15000
100
103
MARRIAGE
Delhi
19000
200
104
marriage
mumbai
35000
150
200
mumbai

Output:
2
marriage
mumbai
35000

Test case2:
101
Marriage
Mumbai
40000
200
102
Birthday
kolkata
15000
100
103
MARRIAGE
Delhi
19000
200

27/28
104
marriage
mumbai
35000
150
300
pune

Output:
No such event found.
No such event found.

public class Solution


{
public static void main(String[] args)
{
//code to read values
//code to call required method
//code to display the result
}
//code the first method
//code the second method
}
//code the class
-------------------------------------------------
Note on using Scanner object:
Sometimes scanner does not read the new line character while invoking methods like nextInt(), nextDouble() etc.
Usually, this is not an issue, but this may be visible while calling nextLine() immediately after those methods.
Consider below input values:
smartphones
15000
Referring below code:
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
String str = sc.nextLine(); -> here we expect str to have value Savings.Instead it may be "".
If the above issue is observed, then it is suggested to add one more explicit call to nextLine() after reading the numeric value

28/28

You might also like