0% found this document useful (0 votes)
36 views6 pages

Tcs Java Question 1

The document outlines the creation of a Spotify class with specific attributes and methods, including private fields, getters, setters, and a parameterized constructor. It also describes a Solution class with a main method that implements a static method to calculate the average subscription price based on subscription type and group session availability. The document includes instructions for input handling and output formatting, along with sample input and output cases.
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)
36 views6 pages

Tcs Java Question 1

The document outlines the creation of a Spotify class with specific attributes and methods, including private fields, getters, setters, and a parameterized constructor. It also describes a Solution class with a main method that implements a static method to calculate the average subscription price based on subscription type and group session availability. The document includes instructions for input handling and output formatting, along with sample input and output cases.
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/ 6

Note: You need to either Com

Create a class Spotify with the below attributes:

spotifyld - int

profileName - String

subscriptionType - String

subscriptionPrice -double

groupSessionAvailable - String

The above attributesshould be private,write getters,settersand

parameterized constructor as required.

Create class Solution with nain method.

Implement two static methods - findAvgSpotifySubsByType in

Solution class.

findAvgSpotifySubsByType method:

This method will take three input parameters -aray of Spotify


objects and two String parameters.
The method will return the average subscriptionPrice of

Spotify's(as a double value) from array of Spotify objects forthe


given subscription type(String parameter passed) and groupSession
available option(String parameter passed).

If noSpotify with theabove condition is present in the array of


Spotify objects, then themethod should return 0.0.
Note :No two Spotifyobject would havethe samespotifyld.
AIl the searches should be case insensitive.

The above mentioned static method should be called fromthe main


method.

For findAvgSpotifySubsByType method - The main method should


print the retuned average subscriptionPrice of Spotify's as it is,if

the returned value is greater than 0, or it

should print "There are no such Spotify Subscription".

Before calling these static nnethods in man, use Scanner object to


read the values of four Spotify objects referring attributes in the

above mentioned attribute sequence.

Next, read two String values for capturing subscription type and
groupSession available option.

Consider below sample input and output:


Testcasel:

Input:

1001

John

Yearly
1000
Yes
1002
Consider below sample input and output:
Testcasel:

Input:
1001

John

Yearly

1000
Yes
1002
Wick
Monthly
200
Yes
1003
Jack

Yearly

2000

Yes
1004
Jack

Monthly
199
No

Yearly
Yes

Output:
1500.0
Testcase2:

Input:
1001

John

Yearly
1000
Yes
1002
Wick
Monthly
200
Yes

1003

Jack
Yearly

2000
Yes
1004
Jack
Monthly
199
No
Yearly
No

Output:

29°C
Note: You need to eithe

Output:

There are no such Spotify Subscription

Sample code snippet for reference:

Please use below code to build your MyClass.

importjava.util,Scanner:
public class Solution

public statie void main(String[] args)

ilcode to read values

lcode to call required method

code to display the result

llcode the frst method

llcode the class

Note on using Scanner object:


Sometimes scanner does not read the new line characterwhile

invoking methods like nextlnt(), nextDouble) etc.

Usually, this is not an issue, but this may be visible while calling

nextLine(0 immediately after those methods.

Consider below input values:


1001

Savings

Referring below code:

29°C
M
lcodethe first method

llcode the class

Note on using Scanner object:


Sometimes seanner does not read the new line character while

nextInt(). nextDouble) etc,


invokingmethods like
may be wisible while calling
Usually, this isnot an issue, but this

nextLine) immediately afterthose metlhods.

Consider below input values:


1001
Savings

Referring below code:

Scanner sc =new Scanner(System.in):

int x=se.nextlnt( :
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 onemore


explicit call to nextLine)afterreading numeric value.

Kindly use File Name as

Instruction

Kindly mnention class name as MyClass.

You might also like