subject

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 Jones Marry 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.
Below is the code for the driver class - DriverMain. java
import java. util.*;
//Your program will be evaluated by this DriverMain class and several test case
public class DriverMain {
public static void main(String[] args) {
String name;
int rollNo;
int n = 0;
Student[] students = new Student[10];
ClassRoom classRoom = new ClassRoom();
Scanner input = new Scanner(System. in);
while(true){
name = input. nextLine();
if(name. equals(""))
break;
rollNo = Integer. parseInt(input. nextLine());
classRoom. addStudent(name, rollNo);
n++;
}
students = classRoom. getAllStudents();
for (int i = 0; i < n; i++) {
if(students[i]!=null)
System. out. print(students[i].getRollNo() + " - " + students[i].getName());
if (i < n - 1)
System. out. println();
}
}
}
//Below is the code for the Solution. java
// NOTE - THIS IS WHERE YOU WRITE THE CODE
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) {
// WRITE YOUR CODE HERE
}
public Student[] getAllStudents() {
// WRITE YOUR CODE HERE
}
};

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Write a method named addall that could be placed inside the hashintset class. this method accepts another hashintset as a parameter and adds all elements from that set into the current set, if they are not already present. for example, if a set s1 contains [1, 2, 3] and another set s2 contains [1, 7, 3, 9], the call of s1.addall(s2); would change s1 to store [1, 2, 3, 7, 9] in some order. you are allowed to call methods on your set and/or the other set. do not modify the set passed in. this method should run in o(n) time where n is the number of elements in the parameter set passed in.
Answers: 2
question
Computers and Technology, 23.06.2019 12:00
If you're using an existing powerpoint presentation that will receive new slides based on a word outline, select the a. slide that will appear after the new slides. b. first slide in the presentation. c. slide that will appear before the new slides. d. last slide in the presentation.
Answers: 2
question
Computers and Technology, 23.06.2019 21:00
Will this setup result in what kathy wants to print?
Answers: 2
question
Computers and Technology, 24.06.2019 07:00
Why would a business likely use a java applet - to back up their data files for the business - to create a program that a customer can launch in their web browser - to create music on a powerpoint presentation - to organize files on their company directory
Answers: 3
You know the right answer?
Given a Student class, create a class with following characteristics: The class name should be Class...
Questions
question
Mathematics, 19.02.2021 19:50