Loading...
Loading...
A teacher enters each student as name obtained total, like Asha 45 50. For each student print name: P%, where P = obtained × 100 / total in integer division.
Some entries are wrong. Work in this order and print name: <problem>:
marks must be whole numbers if obtained or total is not a whole number,total cannot be zero if the division throws an ArithmeticException,marks out of range if obtained is below 0 or above total (throw an IllegalArgumentException with this message).At the end print Class average: X%, the integer average of the printed percentages, or Class average: none if there are none.
Example 1
Input
4 Asha 45 50 Rahul 30 40 Meena 4O 50 Kiran 55 50
Output
Asha: 90% Rahul: 75% Meena: marks must be whole numbers Kiran: marks out of range Class average: 82%
(90 + 75) / 2 = 82 in integer division.
Example 2
Input
2 Dev 0 0 Sara 10 0
Output
Dev: total cannot be zero Sara: total cannot be zero Class average: none
Try the problem first. Open one hint at a time.
Split each line, keep the name, and parse the two marks inside a try.
Compute the percentage first, so a zero total throws ArithmeticException before the range check.
Add to the sum and the count of valid students only after the line is printed successfully.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor