ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2023 ICSE Computer Science Paper



Share with a Friend

Solved 2023 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object Based Program - Student Stream Allocation - ICSE 2023 Computer Science

Question 3
Design a class with the following specifications:

Class name: Student
Member variables:
name – name of the student
age – age of student
mks – marks obtained
stream – stream allocated
(Declare the variables using appropriate data types)

Member methods:
void accept(): Accept name, age and marks using methods of Scanner class.
void allocation() – Allocate the stream as per following criteria:

mks

stream

>= 300

Science and Computer

>= 200 and < 300

Commerce and Computer

>= 75 and < 200

Arts and Animation

< 75

Try again

 

void print() – Display student name, age, mks and stream allocated.

Call all the above methods in main() method using an object.

 

import java.util.Scanner; class Student{ String name; int age; int mks; String stream; public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Student name: "); name = in.nextLine(); System.out.print("Age: "); age = Integer.parseInt(in.nextLine()); System.out.print("Marks obtained: "); mks = Integer.parseInt(in.nextLine()); stream = ""; } public void allocation(){ if(mks >= 300) stream = "Science and Computer"; else if(mks >= 200) stream = "Commerce and Computer"; else if(mks >= 75) stream = "Arts and Animation"; else stream = "Try again"; } public void print(){ System.out.println("Student name: " + name); System.out.println("Age: " + age + " years"); System.out.println("Marks obtained: " + mks); System.out.println("Stream allocated: " + stream); } public static void main(String[] args) { Student obj = new Student(); obj.accept(); obj.allocation(); obj.print(); } }

Output

 
 OUTPUT  1: 
Student name: Anand Rao
Age: 21
Marks obtained: 385
Student name: Anand Rao
Age: 21 years
Marks obtained: 385
Stream allocated: Science and Computer

 OUTPUT  2: 
Student name: Ajay Singh
Age: 20
Marks obtained: 290
Student name: Ajay Singh
Age: 20 years
Marks obtained: 290
Stream allocated: Commerce and Computer