Computer Applications
Design a class with the following specifications:
Class name: Student
Member variables:
name — name of 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.
Java
Java Classes
ICSE 2023
111 Likes
Answer
import java.util.Scanner;
public class Student
{
private String name;
private int age;
private double mks;
private String stream;
public void accept()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter student name: ");
name = in.nextLine();
System.out.print("Enter age: ");
age = in.nextInt();
System.out.print("Enter marks: ");
mks = in.nextDouble();
}
public void allocation()
{
if (mks < 75)
stream = "Try again";
else if (mks < 200)
stream = "Arts and Animation";
else if (mks < 300)
stream = "Commerce and Computer";
else
stream = "Science and Computer";
}
public void print()
{
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Marks: " + mks);
System.out.println("Stream allocated: " + stream);
}
public static void main(String args[]) {
Student obj = new Student();
obj.accept();
obj.allocation();
obj.print();
}
}Variable Description Table
Program Explanation
Output

Answered By
55 Likes
Related Questions
Name the following:
(a) What is an instance of the class called?
(b) The method which has same name as that of the class name.
Write the value of n after execution:
char ch ='d'; int n = ch + 5;Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order. Display the sorted array and original array.
Define a class to overload the function print as follows:
void print() - to print the following format
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.