0% found this document useful (0 votes)
102 views

JAVA OOPS Practice Questions

Uploaded by

gauri.rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

JAVA OOPS Practice Questions

Uploaded by

gauri.rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

JAVA OOPS Practice Questions

Ques.1……………………………………………………..
create the class Course with the below Attributes.

courseId- int
courseName- String
courseAdmin- String
quiz- int
handson -int

The above methods should be private ,write getter and


setter and parametrized constructor as required.

create class courseProgram with main method.

implement two static methods-


findAvgOfQuizByAdmin method:this method will take array
of Course objects and a String value as input parameters.
This method will find out Average (as int) of Quiz questions
for given Course Admin (String parametre passed)
This method will return Average if found.if there is no course
that matches then the method should return 0.

sortCourseByHandsOn method:
This method will take an Array of Course Objects and int

By- Er. Gauri Shankar Rai


value as input parameters.
This methods should return an Array of Course objects in an
ascending order of their handson which are less than the
given handson(int parameter passed) value. if there is no
such course then the method should return null.

The above mentioned static methods should be called from


main methods.

for findAvgOfQuizByAdmin method: The main method


should print the average if the returned value is not 0.
if the returned value is 0 then it should print "No Course
found."

for sortCourseByHandsOn method:


the main method should print the name
of the Course from the returned Course object Array if the
returned value is not null.if the returned value is null then
it should print "No Course found with mentioned attribute.”
TestCases:
input1:
111
kubernetes
Nisha

By- Er. Gauri Shankar Rai


40
10
321
cassandra
Roshini
30
15
457
Apache Spark
Nisha
30
12
987
site core
Tirth
50
20
Nisha
17

output1:
35
kubernetes
Apache Spark
cassandra

By- Er. Gauri Shankar Rai


input2:
111
kubernetes
Nisha
40
10
321
cassandra
Roshini
30
15
457
Apache Spark
Nisha
30
12
987
site core
Tirth
50
20
Shubhamk
5

By- Er. Gauri Shankar Rai


output 2:
No Course found
No Course found with mentioned attributes.
Ques.2…………………………………………….
create a class Footwear which consists of the below attributes.
footwearId=int
footwearName=String
footwearType=String
price =int

the above attributes should be private.


write getter and setter and parametrised constructor as required.

create the class footwearProgrammm with the main method.


implement the 2 static methods.getCountByType and
getSecondHighestPriceByBrand in the Solution class.

getCountByType method:
this method will take two input parameters.
array of the Footwear objects and string parameter footwear
type.
this method will return the count of the footwears from array of
the
footwear objects for the given type of footwear.

By- Er. Gauri Shankar Rai


if no footwear with the given footwear type is found in the
array of footwear abjects,then the method should return 0.

getSecondHighestPriceByBrand method:
this method will take 2 input parameters-array of footwear
objects and string parameter inputFootwearName.the method
will return the second highest footwear objects based on the price
from the array of the Footwear objects

whose brand name matches with the input string parameter.

if no footwear with the given brand is present in the array of the


footwear objects,the the method
should return null.

NOTE: no two footwear objects would have the same


footwearId.All the searches should be case insensitive.
the above mentioned static methods should be called from the
main method.

for getCountByType method- the main method should print the


count of the footwears ,if the returned value

By- Er. Gauri Shankar Rai


is greater than zero. or it should print "Footwear not available";

for getSecondHighestPriceByBrand method-The main method


should print price from the returned footwear objects

if the returned footwear object is not null.else it should print


"Brand not available".
for example.
112
ABC
25555
where 112 is the footwear id,ABC is brand name,25555 is price.

TestCases:
100
Sketchers
sneekers
12345
103
Puma
running shoes
10099
102
reebok

By- Er. Gauri Shankar Rai


Running shoes
5667
101
Reebok
running shoes
5656
99
reebok
floaters
5666
Running shoes
reebok

Sample output:
3
99
reebok
5666

Sample input2:

100
Puma
sneekers
12345

By- Er. Gauri Shankar Rai


101
Puma
sneekers
10099
102
Puma
sneekers
5000
102
Reebok
sneekers
8000
104
Puma
floaters
2000
running shoes
bata

Sample output:
Footwear not available
Brand not available
Ques.3………………………………………………….
Create a class called Student with the below attributes:

By- Er. Gauri Shankar Rai


rollNo - int
name - String
branch - String
score - double
dayScholar - boolean

The above attributes should be private, write getters, setters and


parameterized constructor as required.

Create class Solution with main method.


Implement two static methods -findCountOfDayscholarStudents
and findStudentwithSecondHighestScore in Solution
class.

findCountOfDayscholarStudents:

This method will take an array of Student objects as an input


parameter . This method will calculate and return
the count of Students whose score is greater than 80 and who are
all from dayScholar.

If no Student scored greater than 80 and from dayScholar are


present in the array of Student objects, then the
method should return 0.

findStudentwithSecondHighestScore:

By- Er. Gauri Shankar Rai


This method will take an array of Student objects as an input
parameter. This method will return the object
of the second highest score student from the array of Student
objects who are not from the dayScholar.

If no Student is a dayScholar in the array of Student objects, then


the method should return null.

Note : All the searches should be case insensitive.

The combination of dayScholar and score for each student is


always unique.

The above mentioned static methods should be called from the


main method.

For findCountOfDayscholarStudents method - The main method


should print the returned count as it is
if the returned value is greater than 0, else it should print "There
are no such dayscholar students".

For findStudentwithSecondHighestScore method - The main


method should print the rollNo, name and score
in the below format from the returned object if the retuned value
is not null.

By- Er. Gauri Shankar Rai


rollNo#name#score

If the returned value is null, then it should print ”There are no


student from non day scholar”

Before calling these static methods in main, use Scanner object to


read the values of four Student
objects referring attributes in the above mentioned attribute
sequence.
TestCases:

Input:

1001
Ashwa
IT
85
true
1002
Preeti
IT
70
false
1003
Uma

By- Er. Gauri Shankar Rai


ECE
85
false
1004
Akash
EEE
90
true

Output:
2
1002#Preeti#70.0
Ques.4………………………………………………...
Create a class College with the below attributes.

id-int

name -String

contactNo-int

address-String

pinCode-int

By- Er. Gauri Shankar Rai


Write the getters and setters and parametrized constructor in the
above

mentioned sequence as required.

Create the class Solution with the main method.

Implement the two static methods:

1.findCollegeWithMaximumPincode

2.searchCollegeByAddress

findCollegeWithMaximumPincode method:

Create the Static method in the Solution Class.

This method will take array of the College objects and return the

By- Er. Gauri Shankar Rai


College object having maximum pincode if found else return null
if not

found.

for this method ,main method will print College object with
maximum

pincode if the returned value is not null.if the returned value is


null ,

then the main method will print "No college found with
mentioned attribute".

searchCollegeByAddress method:

Create the Static method in the Solution Class.

This method will take array of College objects as input and


address as

By- Er. Gauri Shankar Rai


input and return College object having the mentioned address if
found

else return null if not found.

for this method main method will print College object details as
it is ,

if the returned value is not null.if the returned value is null then ,

main method will print "No college found with mentioned


attribute".

TestCases:

input 1:

4
109
ACT
2500256

By- Er. Gauri Shankar Rai


mumbai
695001
107
MCE
2500254
malapuram
612354
113
CTE
2500252
chennai
623145
102
SCT
2500255
AP
523641
AP

OUTPUT1:

id-109

By- Er. Gauri Shankar Rai


name-ACT

contactNo-2500256

address-mumbai

pincode-695001

id-102

name-SCT

contactNo-2500255

address-AP

pincode-523641

INPUT2:

By- Er. Gauri Shankar Rai


4
111
MJT
2500251
Calicut
401235
105
MET
2500256
kochi
668745
115
IIT
2500262
banglore
569874
110
ACT
2500263
delhi
687945
delhi

By- Er. Gauri Shankar Rai


output2:

id-110

name-ACT

contactNo-2500263

address-delhi

pincode-687945

id-110

name-ACT

contactNo-2500263

address-delhi

pincode-687945
Ques.5……………………………………………………….
Create a class Motel with the below attributes:

motelId - int

By- Er. Gauri Shankar Rai


motelName - String
dateOfBooking – String (in the format dd-mon-yyyy)
noOfRoomsBooked – int
cabFacility – String
totalBill- double

The above attributes should be private, write getters, setters and


parameterized constructor as
required.
Create class Solution with main method.
Implement one static method – totalNoOfRoomsBooked in
Solution class.
totalNoOfRoomsBooked method:
This method will take two input parameter - array of Motel
objects and a String parameter.
The method will return the total numbers of rooms booked from
array of Motel objects if the cab facility
attribute matches with the given String parameter(cab facility)
and the number of rooms booked is
greater than 5.
If no rooms are booked with the above criteria in the array of
Motel objects, then the method should
return 0.
Note :
No two Motel object would have the same motelId.
dateOfBooking is stored in the format dd-mon-yyyy(eg. 01-Jan-
2022)

By- Er. Gauri Shankar Rai


The above mentioned static method should be called from the
main method.
For totalNoOfRoomsBooked method - The main method should
print the total number of booked rooms
as it is, if the returned value is greater than 0, else it
should print "No such rooms booked"
Before calling these static methods in main, use Scanner object to
read the values of four Motel objects
referring attributes in the above mentioned attribute sequence.
Next, read the value of one String parameter for capturing the cab
facility
TestCases:
Input
___________
1001
M&M
01-Dec-2022
5
Yes
30000
1002
BestStay
10-Jan-2022
3
Yes
27000

By- Er. Gauri Shankar Rai


1003
Novatel
11-Jun-2022
5
Yes
25000
1004
Chola
01-Sep-2022
7
Yes
72000
Yes
___________
OutPut
___________
7
Ques 6.
Create a class Hotel with the below attributes:

hotelId - int
hotelName - String
dateOfBooking – String (in the format dd-mon-yyyy)
noOfRoomsBooked – int
wifiFacility – String

By- Er. Gauri Shankar Rai


totalBill- double

The above attributes should be private, write getters, setters and


parameterized constructor as required.

Create class Solution with main method.

Implement two static methods –


noOfRoomsBookedInGivenMonth and searchHotelByWifiOption
in Solution class.

noOfRoomsBookedInGivenMonth method:
This method will take two input parameter - array of Hotel
objects and a String parameter.
The method will return the total numbers of rooms booked from
array of Hotel objects for the given month(String parameter
passed).
If no rooms are booked for the given month in the array of Hotel
objects, then the method should return 0.

searchHotelByWifiOption method:
This method will take two input parameter - array of Hotel
objects and a String parameter

By- Er. Gauri Shankar Rai


The method will return Hotel object with second highest totalbill,
from the array of Hotel objects where wifiFacility attribute
matches with the given wifi facility(String parameter passed).
If no Hotel with the given wifi option is present in the array of
Hotel objects, then the method should return null.

Note :
No two Hotel object would have the same hotelId.
No two Hotel object would have the same totalbill.
The Array either has at least two objects with specified wifi
option OR no object with specified wifi option.
All the searches should be case insensitive.
dateOfBooking is stored in the format dd-mon-yyyy(eg. 01-Jan-
2022)

The above mentioned static methods should be called from the


main method.

For noOfRoomsBookedInGivenMonth method - The main method


should print the total number of booked rooms as it is,
if the returned value is greater than 0, else it should print "No
rooms booked in the given month"

For searchHotelByWifiOption method - The main method should


print the hotelId from the returned Hotel object if the returned
value is not null.
If the returned value is null then it should print "No such option
available".

By- Er. Gauri Shankar Rai


Before calling these static methods in main, use Scanner object to
read the values of four Hotel objects referring attributes in the
above mentioned attribute sequence.
Next, read the value of two String parameters for capturing the
month and wifi option .

Consider below sample input and output:

Input1:
101
Best Stay
01-jan-2022
10
Yes
20000
102
Apple Stay
12-Feb-2022
3
Yes
4000
103

By- Er. Gauri Shankar Rai


Accord
11-May-2022
5
Yes
15000
104
Royal Park
22-Dec-2021
7
Yes
12000
May
Yes

Output1:
5
103

Input2:
101
Best Stay
01-jan-2022
10

By- Er. Gauri Shankar Rai


Yes
20000
102
Apple Stay
12-Feb-2022
3
Yes
4000
103
Accord
11-May-2022
5
Yes
15000
104
Royal Park
22-Dec-2021
7
Yes
12000
May1
Yes1

By- Er. Gauri Shankar Rai


Output2:
No rooms booked in the given month
No such option available

--------------------------------------------------
Sample code snippet for reference:
Please use below code to build your Solution.
--------------------------------------------------
import java.util.Scanner;
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

By- Er. Gauri Shankar Rai


//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:


1001
Savings

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 above issue is observed, then it is suggested to add one more


explicit call to nextLine() after reading numeric value.

Ques 7.
Create a class Book with below attributes

By- Er. Gauri Shankar Rai


id - int

pages - int

title - String

author - String

price - double

The above attributes should be private, write getters and setters


and parameterized constructor as required.

Create a class Solution with main method


--------------------------------------------
Implement two static methods - findBookWithMaximumPrice and
searchBookByTitle in Solution class.

findBookWithMaximumPrice :
=============================
Create a static method findBookWithMaximumPrice in the
Solution class. This method will take array of Book objects and
returns the Book object having the maximum Price if found else
return null if not found.

searchBookByTitle :

By- Er. Gauri Shankar Rai


=============================
Create a static method searchBookByTitle in the Solution class.
This method will take array of Book objects and Title as
input and returns the Book object having the mentioned Title if
found else return null if not found.

These methods should be called from the main method.

write code to perform the following tasks.

1. Take necessary input variable and call


findBookWithMaximumPrice. For this method - The main method
should print the Book
object with the maximum of mentioned attribute as it is if the
returned value is not null, or it should print
"No Book found with mentioned attribute."

2. Take necessary input variable and call searchBookByTitle. For


this method - The main method should print the Book object
details as it is, if the returned value is not null or it should print
"No Book found with mentioned attribute."

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.

By- Er. Gauri Shankar Rai


All String comparison needs to be in case sensitive.

Input:

1
845
Bengali
Arijit
525.50
2
456
English
Raju
412.30
3
1022
History
Kaka
525.50
4
125
geography
MN
524

By- Er. Gauri Shankar Rai


English

Output:

1 Bengali
3 History
2
456

Ques 8.
Create a class AutonomousCar with the below attributes:

carld – int
brand – String
noOfTestsConducted – int
noOfTestsPassed- int
environment – String

Write getters, setters for the above attributes . Create constructor


which takes parameter in the above sequence
except grade.

Create class Solution with main method. Implement two static


methods – findTestPassedByEnv and updateCarGrade in
Solution class.

By- Er. Gauri Shankar Rai


findTestPassedByEnv method:

This method will take two input parameters -array of


AutonomousCar objects and string parameter environment. The
method
will return the sum of the noOfTestsPassed attribute from
autonomousCar objects for the environment passed as parameter.
If no autonomousCar with the given environment is present in the
array of AutonomousCar objects, then the method should
return 0.

updateCarGrade method:

This method will take a String parameter brand, along with the
array of AutonomousCar objects. The method will return
the autonomousCar object, if the input String parameter matches
with the brand attribute of the autonomousCar object.
Before returning the object, the grade should be derived based on
the rating calculation mentioned below. This grade
value should be assigned to the object. If any of the above
conditions are not met, then the method should return null.
The grade attribute should be calculated as follows: rating .
(noOfTestsPassed * 100)/noOfTestsConducted
If the rating > = 80 then grade should be ‘A1’, otherwise the grade
should be ‘B2’.

By- Er. Gauri Shankar Rai


The above mentioned static methods should be called from the
main method. For findTestPassedByEnv method – The main
method should print the totalTestPassed as it is, if the returned
value is greater than 0, or it should print “There
are no tests passed in this particular environment”.

For updateCarGrade method – The main method should print the


brand and grade of the returned autonomousCar object.
The brand and grade should be concatinated with :: while
printing. eg:- Tesla::A1, where Tesla is the brand and Al
is the grade.

If the returned value is null then it should print “No Car is


available with the specified brand”. Before calling these
static methods in main, use Scanner object to read the values of
four autonomousCar objects referring attributes in the
above mentioned attribute sequence (except grade attribute).
Next, read the value for environment and brand.

Input
----------------
100
Tesla
1000
500
Hills
200

By- Er. Gauri Shankar Rai


Ford
2000
1500
Desert
300
Royce
3000
1700
Hills
400
Mercedez
1000
400
Desert
Desert
Mercedez

Output
-----------
1900
Mercedez::B2
Ques 9.
Create a class Phone with below attributes:

phoneId - int

By- Er. Gauri Shankar Rai


os - String
brand - String
price - int

Write getters, setters and parameterized constructor in the above


mentioned attribute sequence as required.

Create class Solution with main method.

Implement two static methods - findPriceForGivenBrand and


getPhoneIdBasedOnOs in Solution class.

findPriceForGivenBrand method:
----------------------------------
This method will take two input parameters - array of Phone
objects and string
parameter brand. The method will return the sum of the price
attribute from phone objects for the brand passed
as parameter. If no phones with the given brand is present in the
array of phone objects, then the method should
return 0.

getPhoneIdBasedOnOs method:
----------------------------------
This method will take a String parameter os, along with the array
of Phone objects.

By- Er. Gauri Shankar Rai


The method will return the phone object, if the input String
parameter matches with the os attribute of the phone
object and its price attribute is greater than or equal to 50000. If
any of the conditions are not met, then the
method should return null.

Note : No phone object would have the same value for os


attribute. All phone object would have the price greater than 0.
All the searches should be case insensitive.

These above mentioned static methods should be called from the


main method.

For findPriceForGivenBrand method - The main method should


print the price as it is if the returned price is greater
than 0, or it should print "The given Brand is not available".

For getPhoneIdBasedOnOs method - The main method should


print the phoneId of the returned phone object. If the returned
value is null then it should print "No phones are available with
specified os and price range".

Before calling these static methods in main, use Scanner object to


read the values of four Phone objects referring
attributes in the above mentioned attribute sequence. Next, read
the value for brand and os.

By- Er. Gauri Shankar Rai


Input
--------------
111
iOS
Apple
30000
222
android
Samsung
50000
333
Symbian
HTC
12000
444
Paranoid
HTC
89000
Blackberry
aNdRoid

Output
------------------
The given Brand is not available
222

By- Er. Gauri Shankar Rai


Ques 10.
Create a class Student with below attributes:

rollNo - int
name - String
subject - String
grade - char
date - String [DD/MM/YYYY]

The above attributes should be private.Write Getter and Setter


and parametrized constructor as required.

Create class Solution with main method.


******************************************************************
**********
Implement one static method: findStudentByGradeAndMonth
Solution Class.

findStudentByGradeAndMonth Method:

By- Er. Gauri Shankar Rai


This method will take an array of Student objects, char value as
grade and int value as month
for input parameters.The method will find out all Students from
the given grade and month.
This method will return array of Student object assending based
on their rollNo if found.
If there is no Student that matches then the method should return
null.

for this method- main method should print Student name, subject
and total student found [The
length of the list], if the returned value is not null. If the returned
value is null then
main method should print "No student found".

NOTE:
1. For Taking char as input use sc.nextLine().charAt(0)
2. To match/check the month You havee to convert int
month in the parameter to String.
3. No need to count the Student array if return not null just
print the array length.

******************************************************************
**********

By- Er. Gauri Shankar Rai


Consider the below input and output:

input1:

111
Arijit
Math
B
22/09/2023
101
Priyanka
English
A
30/03/2022
107
Shreosi
History
C
13/05/2022
105
Tatan
Physics

By- Er. Gauri Shankar Rai


A
27/03/2022
A
3

output1:

Priyanka
English
Tatan
Physics
2

input2:

111
Sohel
Math
B
22/09/2022

By- Er. Gauri Shankar Rai


101
Priyanka
English
A
30/03/2022
107
Gopa
History
C
12/05/2022
105
Kamal
Physics
A
27/03/2022
A
7

output 2:

No student found
Ques 11.
Create a class TravelAgencies with below attributes:

By- Er. Gauri Shankar Rai


regNo – int
agencyName – String
pakageType – String
price – int
flightFacility – boolean

Write getters, setters for the above attributes . Create constructor


which takes parameter in the above sequence.

Create class Solution with main method. Implement two static


methods – findAgencyWithHighestPackagePrice and
agencyDetailsforGivenIdAndType in Solution class.

findAgencyWithHighestPackagePrice method:

This method will take array of TravelAgencies objects as an input


parameter and return the highest package
price from the given array of objects.

agencyDetailsForGivenldAndType method:

This method will take three input parameters -array of


TravelAgencies objects, int parameter regNo and String
parameter packageType. The method will return the
TravelAgencies object based on below conditions.

By- Er. Gauri Shankar Rai


FlightFacility should be available.
The input parameters(regNo and packageType) should matched
with the regNo and packageType of TravelAgencies object.
If any of the above conditions are not met, then the method
should return null. Note : Same Travel agency can
have more than one package type. Travel agency and package
type combination is unique. All the searches should
be case insensitive.

The above mentioned static methods should be called from the


main method.

For findAgencyWithHighestPackagePrice method – The main


method should print the highestPackagePrice as it is.
For agencyDetailsForGivenldAndType method -The main method
should print the AgencyName and price of the returned
object.The AgencyName and price should be concatinated with :
while printing.
---------
Input
---------
123
A2Z Agency
Platinum
50000

By- Er. Gauri Shankar Rai


true
345
SSS Agency
Gold
30000
false
987
Cox and Kings
Diamond
40000
true
888
Global Tours
Silver
20000
false
987
Diamond
-------------------------------
Output
-------------------------------
50000
Cox and Kings:40000

Ques 12.

By- Er. Gauri Shankar Rai


Create a class Bill with below attributes:

billNo- int
name - String
typeOfConnection - String
billAmount - double
status – boolean

where billNo is the bill number, name is the name of the


customer, typeOfConnection is the type of the connection
(prepaid, postpaid), billAmount is the bill amount and status is
whether the bill is paid or not (if paid then value is TRUE
else value is FALSE).

The above attributes should be private, write getters, setters and


parameterized constructor as required.

Create class Solution with main method.


Implement two static methods -
findBillWithMaxBillAmountBasedOnStatus and
getCountWithTypeOfConnection in Solution class.

findBillWithMaxBillAmountBasedOnStatus method:
-----------------------------------------------------

By- Er. Gauri Shankar Rai


This method will take an array of Bill objects and a boolean
parameter as parameters.
The method will return bill object array in ascending order of
their bill number from the array of Bill objects whose bill
amount is maximum in the array with the status attribute that
matches with the input parameter.

If no Bill with the given status is present in the array of Bill


objects, then the method should return null.

getCountWithTypeOfConnection method:
-----------------------------------------------------
This method will take two input parameters - array of Bill objects
and string parameter ( for type of connection).
The method will return the count of bills from array of bill objects
for the given type of connection.
If no bill with the given type of connection is present in the array
of bill objects, then the method should return 0.

Note :

Two bill object can have the same bill amount.


All the searches should be case insensitive.

The above mentioned static methods should be called from the


main method.

By- Er. Gauri Shankar Rai


For findBillWithMaxBillAmountBasedOnStatus method - The
main method should print the billNo followed by # and name
from the
returned Bill object array if the returned value is not null.

If the returned value is null then it should print "There are no bill
with the given status".

For getCountWithTypeOfConnection method - The main method


should print the count of bills as it is, if the returned value is
greater than 0, otherwise it should print "There are no bills with
given type of connection".

Before calling these static methods in main, use Scanner to read


the number of object and objects to read the values of Bill
objects referring attributes in the above mentioned attribute
sequence.

Next, read the value for status and typeOfConnection.

Consider below sample input and output:


Input:

4
111

By- Er. Gauri Shankar Rai


Aman Mittal
Prepaid
914.25
true
222
Rekha Kumar
Prepaid
1425.75
false
333
Samyra Gupta
Prepaid
1305.00
true
444
Mohit Saxena
Postpaid
1300.50
false
false
Prepaid

Output:

222#Rekha Kumar

By- Er. Gauri Shankar Rai


3
******************************************************************
*******************
--------------------------------------------------
Sample code snippet for reference:
Please use below code to build your solution.
--------------------------------------------------

import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
//code to read values

//code to call required method

//code to display the result

public static Bill[] findBillWithMaxBillAmountBasedOnStatus( /*


required parameters to be added */ ) {
//method logic
}

By- Er. Gauri Shankar Rai


public static int getCountWithTypeOfConnection( /* required
parameters to be added */ ) {
//method logic
}
}
class Bill
{
//code to build 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:

1234
Merin Bakers

Referring below code:

By- Er. Gauri Shankar Rai


Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
String str = sc.nextLine(); -> here we expect str to have value
Bakers name. Instead it may be "".

If above issue is observed, then it is suggested to add one more


explicit call to nextLine() after reading numeric value.

Ques 13.

create the class Song with below attributes.

songId - int
title - String
artist - String
duration-double

The above attributes should be private, getters, setters and


parameterized constructor as required.

Create class MyClass with main method. Implement two static


methods - findSongDurationForArtist and
getSongsInAscendingOrder in MyClass class.

findSongDurationForArtist method:
----------------------------------------------------

By- Er. Gauri Shankar Rai


This method will take two input parameters of Song objects and
String parameter.
The method will return the sum of song duration from array of
Song object for the given artist (String parameter passed).

If no Song with the given artist is present in the array of Song


objects, then the method should return zero.

getSongsInAscendingOrder method:
----------------------------------------------------
This method will take input parameters array, of Song objects and
String parameter.The method will return Song objects array
in an ascending order of their duration, from the array of Song
objects whose artist attribute matches with the input String
parameter.

If no Song with the given artist is present in the array of Song


objects, then the method should return null.

Note:
----------
1. No two Song object would have the same songid.
2. Combination of artist and duration should be unique.
3. All the searches should be case insensitive.

The above mentioned static methods should be called from the


main method.

By- Er. Gauri Shankar Rai


For getfindSongDuration ForArtist method - in method should
print the sum of duration of artist as it is, if the returned
value is greater than 0 or it should print "There are no songs with
given artist".

For getSongsinAscendingOrder method - The main method


should print the song id and title from the returned song object
array
if the returned value is not null. If the returned value is null then it
should print "There are no songs with given artist".

For Example,

112
ABC

where 112 is song ld. ABC is song title.

Before calling these static methods in main, use. Scanner object to


read the values of five Song objects referring attributes
in the above mentioned attribute sequence. Next, read two String
values for capturing artists.

*****************************************************************

By- Er. Gauri Shankar Rai


Sample Input 1:
------------------

2150
In time
Justin Timberlake
4
250
Cry Me
Justin Timberlake
3
1200
Mirrors
Justin Timberlake
5
1300
That's the way it is
celion dion
5
500
Ashes
celion dion
3

By- Er. Gauri Shankar Rai


celion dion
Justin Timberlake

Sample output1:
------------------------

8.0
250
Cry Me
2150
In time
1200
Mirrors

Sample Input 2:
----------------------

2150
Cry Me
Justin Timberlake
3
1000

By- Er. Gauri Shankar Rai


Why Not
Enrique Iglesius
5
1200
Mirrors
Justin Timberlake
5
1300
That's the way it is
Celion Dion
5
500
Ashes
celion Dion
3
Bryan Adams
Michael Larkson

Output 2:
-----------------------

There are no songs with given artist


There are no songs with given artist

By- Er. Gauri Shankar Rai


Ques 14.

Find the palindrome words from the sentence and print them and
also count
Input:
----------------
My name is nitin and I can speak malayalam
Output:
----------------
nitin
I
malayalam
3

Ques 15.

Count the number of words in a sentence that start and end with
the same letter.

Input: Anna asked about the Ginseng recipe


Output: 2

Explanation: There are two words in the sentence that start and
end with the same letter - "Anna" and "Ginseng".

By- Er. Gauri Shankar Rai


Ques 16.

Count the sum of prime digits in a given number

Input: 2345678910
Output: 17

Explaination: 2+3+5+7 = 17

Ques 17.
Write a Java program that creates three threads. First thread
displays “Good Morning” every one second, the second thread
displays “Hello” every two seconds and the third thread displays
“Welcome” every three seconds.

Ques 18.
Use inheritance to create an exception super class called
EexceptionA and exception sub class ExceptionB and ExceptionC,
where ExceptionB inherits from ExceptionA and ExceptionC
inherits from ExceptionB. Write a java program to demonstrate
that the catch block for type ExceptionA catches exception of type
ExceptionB and ExceptionC.

Ques 19
Write Java program(s) which uses the exception handling features
of the language, creates exceptions and handles them properly,
uses the predefined exceptions, and create own exceptions

By- Er. Gauri Shankar Rai


Ques 20
Write a java program to split a given text file into n parts. Name
each part as the name of the original file followed by .part where n
is the sequence number of the part file.

By- Er. Gauri Shankar Rai

You might also like