Loading...
Loading...
A cricket analyst starts the new season from last season's numbers and adds each new match to the copy. Last season's record must not change.
Write a class Player with fields name, runs and matches, a constructor Player(String name, int runs, int matches), a copy constructor Player(Player other) that calls the first with this(...), and void addMatch(int r).
LAST name runs/matches and NOW name runs/matches.Example
Input
Rohit 450 12 3 50 0 101
Output
LAST Rohit 450/12 NOW Rohit 601/15
The copy grows to 601 runs in 15 matches; last season stays 450 in 12.
Try the problem first. Open one hint at a time.
Player now = last; makes a second reference to the same object, not a copy.
The copy constructor reads other.name, other.runs and other.matches and passes them to the full constructor.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor