HELLO DORAEMONS,
IN THIS BLOGPOST ,I HAVE SHARED THE RECENTLY ASKED JAVA QUESTION AND SOLUTION WHICH IS CERTAINLY USEFUL WHEN YOU WANT TO PRACTICE.HOPE THIS BLOG IS USEFUL TO YOU
Create a class Toy with the below attributes:
toyld - int
toyName - String
category - String
price - double
discount - 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 - findAveragePricePerCategory and findToyWithHighestPrice in Solution class.
findAveragePricePerCategory method: This method will take two input parameters - array of Toy objects and String parameter. The method will return the average price of toys without deducting discount for given category(String parameter passed) from array of Toy object. If no Toy with the given category is present in the array of Toy objects, then the method should return
findToyWithHighestPrice method: This method will take two input parameters · Array of Toy objects and String parameter.
This method will take two input parameters - Array of Toy objects and String parameter. Method will return the Toy object with the highest price after deducting the discount for the given category (String parameter passed). If no Toy with the given Category is present in the Array of Toy objects, then the method should return null.
Formula to calculate the discount value: Discount = (Price of the toy * Discount on the
Toy)/100;
Note:
1. No two Toy object would have the same price.
2. All the searches should be case insensitive.
3. There has to be atleast 2 toys for the given category
The above mentioned static methods should be called from the main method.
For findAveragePricePerCategory method - The main method should print the average price of the toys as it is, if the returned value is greater than 0, or it should print "Category doesn't exist".
For Example: 112.5
where 112.5 is the average price of toys for the given category. For findToyWithHighestPrice method - The main method should print the Toyld, ToyName and
Category from the returned Toy object as shown in the below example if the returned value is not null. If the returned pile i the return If the returned value is null then it should print "No Match found for the Category". For Example:
102
SoftBall
Doll
where 102 is the Toy Id, SoftBall is the Toy Name and Doll is the Category Before calling these static methods in main, use Scanner object to read the values of Five Toy objects referring attributes in the above mentioned attribute sequence. Next, read the input value for Category to be passed in findAveragePricePerCategory method as input parameter. Atlast, read another input value for Category to be passed in findToyWithHighestPrice method as input parameter.
Consider below sample input and output:
SAMPLE INPUT 1
101
ludo
puzzle
100.0
10.0
102
softball
game
150.0
12.0
103
football
game
95.0
2.0
104
teddy bear
doll
1525.0
12.0
105
rubriks cube
puzzle
1500.0
15.0
game
puzzle
output:
122.5
105
rubriks cube
puzzle
sample output 2:
101
ludo
puzzle
100.0
10.0
102
softball
game
150.0
12.0
103
football
game
95.0
2.0
104
teddy bear
doll
1525.0
12.0
105
rubriks cube
puzzle
1500.0
15.0
electronics
Doodles
Output:
Category doesn’t exist
No match found for the Category
HOPE THIS IS HELPFUL TO YOU GUYS.IF YOU LIKE MY WORK ,CONSIDER SUBSCRIBING TO MY CHANNEL AND FOLLOW MY BLOGPOST FOR MORE UPDATES
0 Comments