0% found this document useful (0 votes)
8 views9 pages

02 SBQ SmartPhones HashMap Exceptions

The document outlines the creation of a Smartphone class with attributes like productid, brandname, rom, and price, along with a Solution class containing static methods for filtering smartphones by brand and finding the maximum priced smartphone within a given range. It specifies the use of a collection that maintains insertion order and requires case-insensitive string comparison. Additionally, it introduces a custom exception class for handling neon number checks, detailing input and output requirements for both functionalities.

Uploaded by

kadhalbeats25
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)
8 views9 pages

02 SBQ SmartPhones HashMap Exceptions

The document outlines the creation of a Smartphone class with attributes like productid, brandname, rom, and price, along with a Solution class containing static methods for filtering smartphones by brand and finding the maximum priced smartphone within a given range. It specifies the use of a collection that maintains insertion order and requires case-insensitive string comparison. Additionally, it introduces a custom exception class for handling neon number checks, detailing input and output requirements for both functionalities.

Uploaded by

kadhalbeats25
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/ 9

Use the appropriate collection to solve this question.

Create a class Smartphone with the following attributes

productid – int

brandname – String

rom – String

price – double

Include a constructor to initialize these attributes.

In a seperate Solution class with the main method, implement the following
static methods:

 filterTheSmartPhoneByBrandName: This method should take


collection of Smartphone objects and brand(String) parameters
and return the collection of Smartphone objects which prints the
smartphones from the given brand parameter. If the returned
collection of Smartphone objects is empty then return null.

 findTheSmartPhoneWithMaxPriceInGivenPriceRange: This
method should take collection of smartphone objects and two
double parameters (startRange and endRange) and returns a
Smartphone object, which had the maximum price from the give
price range. If no Smartphone object found within the price range
then return null.

The above static methods should be called from the main method.

For filterTheSmartPhoneByBrandName: This main method should print


the collection of Smartphone object (productid, brandname, rom, price). If
the returned collection is not null then print the collection of
Smartphone objects or else, print “No mobile found with mentioned
brand name”.
For findTheSmartPhoneWithMaxPriceInGivenPriceRange: This method
should print the Smartphone object(brandname, rom, price). If the
returned Smartphone object is not null then print the object or else, print
“No mobile found in the given price range”.

Before calling the static methods in the main method, use the scanner
object to read value for no.of Smartphone objects, then for each
Smartphone object read the attributes as per above mentioned sequence.
Next, read one String value and two double values using the scanner object
for capturing the brand, startRange and endRange.

Constraints:

 No two smartphone objects should have same productid.


 Collection should follow insertion order.
 String comparison should be case-insensitive.

For more clarity, refer to the sample input and output testcases which are
provided below.

Sample Testcase 1:
Input:

739

Samsung

4GB

12000

382

Redmi

8GB

14000

839

Samsung
16GB

29000

738

IPhone

16GB

43000

Samsung

25000

50000

Output:

739

Samsung

4GB

12000.0

839

Samsung

16GB

29000.0

IPhone

16GB

43000.0

Sample Testcase 2:
Input:

739

Redmi
4GB

13000

109

Nokia

2GB

4500

291

Samsung

16GB

32000

IPhone

35000

50000

Output:

No mobile found with mentioned brand name

No mobile found in the given price range

Testcase 3:
Input:

8392

IPhone

32GB

112000

3829

IPhone

16GB
71000

2901

IPhone

8GB

40000

1092

Oneplus

32GB

28000

iPhone

10000

25000

Output:

8392
IPhone
32GB
112000.0
3829
IPhone
16GB
71000.0
2901
IPhone
8GB
40000.0
No mobile found in the given price range

Testcase 4:
Input:

1900

Samsung
4GB

13500

1900

Oneplus

4GB

16700

2392

Oneplus

12GB

23000

IPhone

13000

17000

Output:

No mobile found with mentioned brand name

Oneplus

4GB

16700.0

---------------------------------------------------------

Note on using the Scanner object:

Sometimes scanner object does not read the new line character by invoking
methods like nextInt(), nextDouble() etc.

Usually, this is not an issue, but this may be visible by calling nextLine()
method.

Consider the below input values:


1001

Savings

Refer the 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 like “”.

If the above issue is observed, then it is suggested to add one more explicit
call to nextLine() after reading numeric value.

------------------------------------------------------------------------------------------------------------
------
Create a custom exception class named ‘NotNeonException’.

Write a main method in Solution class.

In this main method, read the Integer values and store in the collection of
Integers. From the Integer collection, for each integer value, print the
integer value only if the integer value is neon number. If the integer is
not a neon number, then throw the exception.

First read the integer value for size of collection. Next, read the sequence of
Integer values using Scanner object and store in the collection of type
Integer.

Neon Number:
 A Neon Number is a number where the sum of digits of square of the
number is equal to the number.
 0, 1 and 9 are examples of Neon Numbers.
 Refer the test cases for better understanding.

Constraint:
 Duplicate Student objects are not allowed.
 Insertion order should not be followed.
 During exception handling, catch block should throw the exception in the
specified format: “exception_class_name:<space>message_of_exception”.

Methods Used:
 (exception_variable_name).getClass().getSimpleName()
 (exception_variable_name).getMessage()

For more clarity, refer to the sample input and output test cases.

Sample Test Case 1


Input:
5
888
29
1
8
0

Output:
0
1
NotNeonException: 888 is not a neon number
NotNeonException: 8 is not a neon number
NotNeonException: 29 is not a neon number

Description:
 0 = 0 * 0 = 0 (0 == 0)
 1 = 1 * 1 = 1 (1 == 1)
 888 = 888 * 888 = 7,88,544 = 36 (sum of digits of square) (888 !=
36)
 8 = 8 * 8 = 64 = 10 (sum of digits of square) (8 != 10)
 29 = 29 * 29 = 841 = 13 (sum of digits of square) (29 != 13)

Sample Test Case 2


Input:
3
38
9
45
Output:
NotNeonException: 38 is not a neon number
9
NotNeonException: 45 is not a neon number

Description:
 38 = 38 * 38 = 1444 = 13 (sum of digits of square) (38 != 13)
 9 = 9 * 9 = 81 = 9 (sum of digits of square) (9 == 9)
 45 = 45 * 45 = 2025 = 9 (sum of digits of square) (45 != 9)

Test Case 3
Input:
0
9
1

Output:
0
1
9

Sample Test Case 4


Input:
4
12
1
93
85

Output:
1
NotNeonException: 85 is not a neon number
NotNeonException: 12 is not a neon number
NotNeonException: 93 is not a neon number

You might also like