Design a class with the following specifications:

Java Programming Language (Article) (Program)

87

Given Input & Expected Output:

Enter student name: Rumman Ansari
Enter age: 25
Enter marks: 89
Name: Rumman Ansari
Age: 25
Marks: 89.0
Stream allocated: Arts and Animation
Press any key to continue . . .

Program:

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();
    }
}

Output:

Enter student name: Rumman Ansari
Enter age: 25
Enter marks: 89
Name: Rumman Ansari
Age: 25
Marks: 89.0
Stream allocated: Arts and Animation
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.