64.3k views
5 votes
Given a Student class, create a class with following characteristics:

The class name should be ClassRoom. Private variable students array to maintain the list of Student objects.
Function addStudent with input parameter name (string) and rollNo(int) adds a new student in "students" list.

Method getAllStudents should return all the students in ClassRoom.

Input
Jack

1
Jones
2
Marry
3
where,

First & Second line represent a student’s name and roll number. And so on.

Output

1 - Jack
2 - Jones
3 - Marry

User Hafichuk
by
4.8k points

1 Answer

1 vote

Answer:

ssume that,

Maximum “students” count can be 10.

*Driver Class*

*Solution class*

import java.util.*;

class Student {

private String name;

private int rollNo;

public String getName() {}

public void setName(String name) {}

public int getRollNo() {}

public void setRollNo(int rollNo) {}

};

class ClassRoom {

private int i;

private Student[] students;

public void addStudent(String name, int rollNo) {}

public Student[] getAllStudents() {}

};

User Shoheikawano
by
5.3k points