Loading...
Loading...
A review app rates movies, restaurants and books. They have nothing in common, and each works out its star rating (0 to 5) in its own way.
Write an interface Rateable with String title() and int stars(). A Movie gets the stars given. A Restaurant gets the average of its food and service scores (integer division). A Book gets one star per 100 likes, at most 5. Print every rating and the average.
movie TITLE stars, restaurant TITLE food service or book TITLE likes (one-word titles).TITLE: s/5, then AVERAGE a where a = total stars / t in integer division.Example
Input
3 movie 3_Idiots 5 restaurant Campus_Canteen 4 3 book Malgudi_Days 320
Output
3_Idiots: 5/5 Campus_Canteen: 3/5 Malgudi_Days: 3/5 AVERAGE 3
The canteen gets (4 + 3) / 2 = 3, the book 320 / 100 = 3; (5 + 3 + 3) / 3 = 3.
Try the problem first. Open one hint at a time.
Each class stores its own input in fields set by its constructor; the interface stays field-free.
Keep the running total of stars() in main through a Rateable variable.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor