Full Marks :- 10 OOP’s in Java Time :- 1hr
Task (summary):
Design a Student class that accepts a variable number of subject marks via constructors, computes statistics, and
prints a grade breakdown. All input must come from args[] in main. (Do Not Use Scanner)
Requirements (changes highlighted)
• Fields: rollNo (int), name (String), marks (int[]).
• Constructors (minimum three):
1. Student(int rollNo, String name) — marks default to zero-length array.
2. Student(int rollNo, String name, int[] marks) — initialize with given marks.
3. Copy constructor: Student(Student other) — deep copy of marks.
• Methods:
1. double average() — average of valid marks (if no valid marks, return 0).
2. int highest() and int lowest() — return highest/lowest (if no marks, return -1).
3. double median() —: return median of valid marks (if no marks, return 0).
4. String grade() :
▪ A+ : avg ≥ 90; A : 80 ≤ avg < 90; B : 60 ≤ avg < 80; C : 40 ≤ avg < 60; F : avg < 40
5. void printReport() — print roll, name, marks list, average (2 decimals), median (2 decimals), highest,
lowest, grade.
• Error handling / edge cases (must be implemented):
1. If any mark supplied is outside 0–100, ignore that mark and print a warning message for that mark.
2. If mark parsing fails (non-integer string), ignore and print a warning.
3. If no valid marks exist after filtering, average() = 0 and grade = F — print a note: “No valid marks”.
• Input via main(String[] args):
• Command-line format:
java StudentApp <rollNo> <name> <m1> <m2> ... <mk>
where k can be 0..n.
• Then create a copy using the copy constructor and call printReport() on both original and copy to
show deep-copy worked (i.e., modifying copy’s marks should not affect original).
• After creating the copy, if the copy has at least one valid mark, increase the highest mark in the copy
by 5 points (capped at 100), then print both reports to demonstrate deep copy and that original is
unchanged.
Sample runs
Full Marks :- 10 OOP’s in Java Time :- 1hr
1. With valid marks:
java StudentApp 101 Riya 78 85 90
Expected output (approx):
Original Student Report:
Roll No: 101
Name: Riya
Marks: [78, 85, 90]
Average: 84.33
Median: 85.00
Highest: 90
Lowest: 78
Grade: A
Copy created and highest mark in copy increased by 5 (capped at 100).
Original Student Report:
Roll No: 101
Name: Riya
Marks: [78, 85, 90]
Average: 84.33
Grade: A
Copy Student Report:
Roll No: 101
Name: Riya
Marks: [78, 85, 95] <-- only in copy
Average: 86.00
Median: 95.00
Grade: A+
2. Invalid marks + no marks:
java StudentApp 102 Amit 105 -5 abc
Expected output:
Warning: invalid mark '105' ignored (out of range)
Warning: invalid mark '-5' ignored (out of range)
Warning: invalid mark 'abc' ignored (not an integer)
No valid marks found.
Average: 0.00
Median: 0.00
Grade: F