Loading...
Loading...
Loading...
A student asks for re-evaluation. The office copies the marksheet and changes some marks on the copy; the original must stay as it is. Write Marksheet (name, int[] marks) with a copy constructor that gives the copy its own array.
Original: <name> <marks> = <total> and Revalued: <name> <marks> = <total>.Example
Input
Kavya 3 78 64 91 1 2 72
Output
Original: Kavya 78 64 91 = 233 Revalued: Kavya 78 72 91 = 241
Subject 2 goes from 64 to 72 on the copy only: 233 + 8 = 241.
Try the problem first. Open one hint at a time.
this.marks = other.marks; copies only the reference: the original would change too.
Clone the array in the main constructor and chain the copy constructor to it with this(other.name, other.marks).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor