Loading...
Loading...
Loading...
A class teacher prints report cards. Write a class Student with name, roll and marks, and override toString() so that System.out.println(s) prints Roll <roll>: <name> (<marks>). Print every student, then the topper (highest marks; on a tie, the one who comes first).
Topper: followed by the topper's card.Example
Input
3 Aarav 12 91 Diya 7 96 Kavya 3 96
Output
Roll 12: Aarav (91) Roll 7: Diya (96) Roll 3: Kavya (96) Topper: Roll 7: Diya (96)
Diya and Kavya tie on 96; Diya comes first, so she stays the topper.
Try the problem first. Open one hint at a time.
Return the text from toString(); do not print inside it.
Keep a topper reference and replace it only when marks are strictly higher.
"Topper: " + topper calls toString() for you.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor