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 Assume that, Maximum “students” count can be 10. DriverMain.java and Solution.java attached.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

--------------Answer question below:--------------

In Java:

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

Assume that,

Maximum “students” count can be 10.

DriverMain.java and Solution.java attached.

1- import java.util.*;
2
3 //Your program will be evaluated by this DriverMain class and several test cases.
4
5- public class DriverMain {
public static void main(String[] args) {
6-
7
string name;
int rollNo;
int n = e;
student[] students = new student[10];
10-
11
classRoom classRoom = new ClassRoom();
12
scanner input = new scanner (Ssystem.in);
13
while(true){
try{
name = input.nextline();
14
15
16
rollNO = Integer.parseInt(input.nextLine());
17
}catch(Exception e){
18
break;
19
20
if(name.equals("))
21
break;
22
23
classRoom.addstudent(name, rollNO);
24
n++;
25
students = classRoom.getAllstudents ();
for (int i = 0; i « n; i++) {
if(students[i]!=null)
26
27
28-
System.out.print(students[i].getRol1NO() +
+ students[i].getName ());
29-
if (i < n - 1)
30
31
System.out.println();
32
33
34 1
Transcribed Image Text:1- import java.util.*; 2 3 //Your program will be evaluated by this DriverMain class and several test cases. 4 5- public class DriverMain { public static void main(String[] args) { 6- 7 string name; int rollNo; int n = e; student[] students = new student[10]; 10- 11 classRoom classRoom = new ClassRoom(); 12 scanner input = new scanner (Ssystem.in); 13 while(true){ try{ name = input.nextline(); 14 15 16 rollNO = Integer.parseInt(input.nextLine()); 17 }catch(Exception e){ 18 break; 19 20 if(name.equals(")) 21 break; 22 23 classRoom.addstudent(name, rollNO); 24 n++; 25 students = classRoom.getAllstudents (); for (int i = 0; i « n; i++) { if(students[i]!=null) 26 27 28- System.out.print(students[i].getRol1NO() + + students[i].getName ()); 29- if (i < n - 1) 30 31 System.out.println(); 32 33 34 1
1- import java.util.*;
2
3- class student {
4
private string name;
5
private int rollNo;
7
public string getName() {
return name;
}
10
11-
public void setName (String name) {
12
this.name = name;
13
}
14
15-
public int getrollNo() {
16
return rollNo;
17
}
18
public void setrollNo(int rollNo) {
this.rollNO = rol1No;
19-
20
21
}
22 };
23
24 //Write your code in the ClassRoom Class
25
26 - class classRoom {
27
28
private int i;
29
private student[] students;
30
31
public void addstudent(string name, int rollNo) {
32
}
33
public student[] getAllstudents () {
}
35 };
34
Transcribed Image Text:1- import java.util.*; 2 3- class student { 4 private string name; 5 private int rollNo; 7 public string getName() { return name; } 10 11- public void setName (String name) { 12 this.name = name; 13 } 14 15- public int getrollNo() { 16 return rollNo; 17 } 18 public void setrollNo(int rollNo) { this.rollNO = rol1No; 19- 20 21 } 22 }; 23 24 //Write your code in the ClassRoom Class 25 26 - class classRoom { 27 28 private int i; 29 private student[] students; 30 31 public void addstudent(string name, int rollNo) { 32 } 33 public student[] getAllstudents () { } 35 }; 34
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Passing Array as Argument
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education