TCS IRA JAVA 14TH FEB CODING/SBQ QUESTION AND SOLUTIONS

 

HELLO DORAEMON,IN THIS BLOGPOST,I HAVE SHARED THE QUESTION ASKED IN 14 TH FEBUARY OF IRA.

ABOUT THIS QUESTION:

YOU CAN REFER TO THE BASIC OF THIS QUESTION  LIKE INPUT FORMAT AND THE PARAMETERS TO PERFORM CERTAIN OPERATIONS.

THE DIFFICULTY LEVEL OF THIS QUESTIONS IS 8/10.BECAUSE IT HAS TO BE HANDLED WITH CERTAIN CASE LIKE FINDING THE THIRD MINIMUM PRICE.

APPROACH TO SOLVE:

STEP 1:GET THE REQUIRED INPUT

STEP2:PASS THEM TO THE OBJECT CLASS AND CREATE THE OBJECT STRUCTURE.

STEP3:DEFINE TWO FUNCTIONS IN MAIN CLASS

STEP4:PASS THE CREATED OBJECT AND THE CATEGORY

STEP5:ITERATE THROUGH THE OBJECT LIST AND COMPARE THE CATEGORY ,ADD THEIR PRICE AND OUTPUT THE TOTAL AMOUNT.ALSO CREATE A VARIABLE C TO COUNT NUMBER OF ITEMS FOUND OVER THE GIVEN CATEGORY.

STEP 6:DEFINE ANOTHER FUNCTION IN THE MAIN CLASS AND CREATE AN ARRAY OF SIZE C AND THEN ITERATE THE LIST AGAIN AND SORT THE PRICE VALUES.

STEP7:USE ARRAYS.SORT() TO SORT THE LIST AND STORE THE LAST ELEMENT OF THE ARRAY.

STEP8:ITERATE AGAIN THROUGH THE LIST AND FIND THE ITEM ID WHICH HAS THE THIRD MINIMUM PRICE AND RETURN THE ITEMID AND PRICE.


1. Java IRA SBQ Market Management

Create a class Market with below attributes:

 Market id-int

itemName - String

category: String

price-int

available- 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 - find TotalPriceForGivenCategory and findAvailableltemWithThird MinimumPrice in Solution class. find TotalPriceForGivenCategory method: This method will take array of Market objects and a String value as an input parameter It will return the total price of Market from array of Market objects for the given category(String parameter passed). If no Market with the given category is present in the array of Market objects, then the method should return 0.

findAvailableitemWithThird MinimumPrice method: This method will take array of Market objects as an input parameter and returns the available Market object with the third lowest price from the given array of objects. If no Market object with the above condition is present in the array of Market objects, then the method should return null;

 Note : No two Market will have the same price

All the searches should be case insensitive.

The above mentioned static methods should be called from the main method. For findTotalPriceForGivenCategory method - The main method should print the returned total price as it is if the returned value is greater than 0 or it should print "No item available with the given category" Eg: 100 where 100 is the total price

For findAvailableltem With Third MinimumPrice and price from the returned Market object if the returned values If the returned value is null then it should print "No such item available".

ALL

Eg: 111 150 where 111 is the itemld and 150 is the price Before calling these static methods in main, use Scanner object to read the values of four Market objects referring attributes in the above mentioned attribute sequence. Next, read the value of String parameter for capturing Category Consider below sample input and output

 Input 1:

111

rose

flower

100

true

222

tomato

vegetables

70

true

333

potato

vegetables

50

true

444

beans

vegetables

20

true

vegetables

Output:

 140

222

 70

Input2 :

111

Rose

Flower

100

False

222

Tomato

Vegetables

70

False

333

Potato

Vegetables

50

False

444

Beans

Vegetables

20

False

Fruit

 

Output:

No item available with the given category

No such item available



Sample code snippet for reference: Please use below code to build your Solution,

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.

HEY GUYS TRY TO SOLVE IT BY THE ABOVE GIVEN APPROACH AND IF YOU COULDN'T THEN REFER TO MY BELOW VIDEO SO THAT YOU CAN UNDERSTAND HOW TO DEFINE A OBJECT AND HOW TO CREATE AN OBJECT STRUCTURE.



AND I HAVE SOLVED USING MY APPROACH,IF YOU FIND AND ANY APPROACH PLEASE PUT IT IN THE COMMENTS SECTION.

HOPE THIS BLOG IS HELPFUL AND ALSO HAVE A LOOK AT OTHER USEFUL POST IN OUR WEBSITE.

Post a Comment

0 Comments