0% found this document useful (0 votes)
324 views24 pages

Oops 5 Ques

Uploaded by

gauri.rai
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)
324 views24 pages

Oops 5 Ques

Uploaded by

gauri.rai
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
You are on page 1/ 24

Ques 1.

******************************************************************
Create a class Phone with below attributes:

phoneId - int
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.

Gauri Shankar Rai


getPhoneIdBasedOnOs method:
----------------------------------
This method will take a String parameter os, along with the array
of Phone objects.
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".

Gauri Shankar Rai


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.

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

Gauri Shankar Rai


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

Ques 2.
*****************************************************************
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.


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

Gauri Shankar Rai


Implement one static method: findStudentByGradeAndMonth
Solution Class.

findStudentByGradeAndMonth Method:

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.

Gauri Shankar Rai


3. No need to count the Student array if return not null just
print the array length.

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

Consider the below input and output:

input1:

111
Arijit
Math
B
22/09/2023
101
Priyanka
English
A
30/03/2022
107

Gauri Shankar Rai


Shreosi
History
C
13/05/2022
105
Tatan
Physics
A
27/03/2022
A
3

output1:

Priyanka
English
Tatan
Physics
2

Gauri Shankar Rai


input2:

111
Sohel
Math
B
22/09/2022
101
Priyanka
English
A
30/03/2022
107
Gopa
History
C
12/05/2022
105
Kamal
Physics
A
27/03/2022
A
7

Gauri Shankar Rai


output 2:

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

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:

Gauri Shankar Rai


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.

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.

Gauri Shankar Rai


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
true
345
SSS Agency
Gold
30000
false
987
Cox and Kings
Diamond
40000
true
888
Global Tours
Silver

Gauri Shankar Rai


20000
false
987
Diamond
-------------------------------
Output
-------------------------------
50000
Cox and Kings:40000

Ques 4.
******************************************************************
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).

Gauri Shankar Rai


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

Gauri Shankar Rai


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.

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

Gauri Shankar Rai


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
Aman Mittal
Prepaid
914.25
true
222
Rekha Kumar
Prepaid
1425.75
false
333
Samyra Gupta
Prepaid
1305.00
true

Gauri Shankar Rai


444
Mohit Saxena
Postpaid
1300.50
false
false
Prepaid

Output:

222#Rekha Kumar
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

Gauri Shankar Rai


//code to call required method

//code to display the result

public static Bill[] findBillWithMaxBillAmountBasedOnStatus( /*


required parameters to be added */ ) {
//method logic
}
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.

Gauri Shankar Rai


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:

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 5.
******************************************************************
create the class Song with below attributes.

songId - int
title - String

Gauri Shankar Rai


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:
----------------------------------------------------
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.
Gauri Shankar Rai
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.

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,

Gauri Shankar Rai


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.

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

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

2150
In time
Justin Timberlake
4
250
Cry Me
Justin Timberlake
3

Gauri Shankar Rai


1200
Mirrors
Justin Timberlake
5
1300
That's the way it is
celion dion
5
500
Ashes
celion dion
3
celion dion
Justin Timberlake

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

8.0
250
Cry Me
2150
In time
1200
Gauri Shankar Rai
Mirrors

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

2150
Cry Me
Justin Timberlake
3
1000
Why Not
Enrique Iglesius
5
1200
Mirrors
Justin Timberlake
5
1300
That's the way it is
Celion Dion
5
500
Ashes
Gauri Shankar Rai
celion Dion
3
Bryan Adams
Michael Larkson

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

There are no songs with given artist


There are no songs with given artist

Gauri Shankar Rai

You might also like