ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2010 ICSE Computer Science Paper



Share with a Friend

Solved 2010 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object - Student Marks Program - ICSE 2010 Computer Science

Define a class Student as given below:

Data members/instance variables:
name: to store the student’s name.
age: to store the age.
m1, m2, m3: to store the marks in three subjects.
maximum: to store the highest marks among three subjects.
average: to store the average marks.

Member functions:
(i) A parameterized constructor to initialize the data members.
(ii) To accept the details of a student.
(iii) To compute the average and the maximum out of three marks.
(iv) To display all the details of the student.

Write a main() method to create an object of the class and call the above methods accordingly to enable the task.

import java.util.Scanner; class Student{ String name; int age; int m1; int m2; int m3; int maximum; double average; public Student(String n, int a, int m1, int m2, int m3){ name = n; age = a; this.m1 = m1; this.m2 = m2; this.m3 = m3; maximum = 0; average = 0.0; } public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Name: "); name = in.nextLine(); System.out.print("Age: "); age = Integer.parseInt(in.nextLine()); System.out.print("Marks 1: "); m1 = Integer.parseInt(in.nextLine()); System.out.print("Marks 2: "); m2 = Integer.parseInt(in.nextLine()); System.out.print("Marks 3: "); m3 = Integer.parseInt(in.nextLine()); } public void compute(){ maximum = Math.max(m1, m2); maximum = Math.max(maximum, m3); average = (m1 + m2 + m3) / 3.0; } public void display(){ System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Marks 1: " + m1); System.out.println("Marks 2: " + m2); System.out.println("Marks 3: " + m3); System.out.println("Maximum: " + maximum); System.out.println("Average: " + average); } public static void main(String args[]){ Student obj = new Student("", 0, 0, 0, 0); obj.accept(); obj.compute(); obj.display(); } }

Output

 
 OUTPUT  : 
Name: Ronnie
Age: 21
Marks 1: 56
Marks 2: 67
Marks 3: 78
Name: Ronnie
Age: 21
Marks 1: 56
Marks 2: 67
Marks 3: 78
Maximum: 78
Average: 67.0