Create a program with a collection of students from the class. Remember that stu
ID: 3905559 • Letter: C
Question
Create a program with a collection of students from the class. Remember that students in the class are unique, and can therefore only be in the collection once. The Student object has a First and Last name and a score. Each of these students will be added to a Group object with one other student, and these Groups will be in an ordered collection by the first/last name of student 1 in the group. Also, each student will contain chat responses. Each Student should have a separate collection of chat responses, each with at least 5 different responses. The responses should be ordered, as conversation responses. Per-student responses should be unique, but the same responses can be repeated in different student objects, for example both Student 1 and Student 4 can say "Hi", but only once each. Use these Students to create conversation pairs and display the conversation between each pair as output. This is in preparation for a chat client which will begin with next weeks' labs, so make sure to use good Object Oriented principles in your design, so that you can use the methods and classes you create this week in upcoming labs. Remember also to use the correct collection types for the requirements. In Java...no test cases required...
Explanation / Answer
Student class:
package student;
import java.util.Date;
import java.util.Scanner;
class Student {
public String name, course;
public int marks[] = new int[5];
public int roll;
public String adm_date;
public static int student_count = 0;;
public static void student_number()
{
System.out.println("Number of students admitted : " + student_count);
}
public int ret_roll() {
return roll;
}
public void admission() {
Scanner sc = new Scanner(System.in);
Date date = new Date();
System.out.println("STUDENT DETAILS ");
System.out.println(" Enter name: ");
name = sc.nextLine();
System.out.println(" Enter course name: ");
course = sc.nextLine();
adm_date = date.toString();
System.out.println("Admission Date:" + adm_date);
student_count++;
roll = student_count;
System.out.println("Roll: "+ roll);
}
void get_marks() {
Scanner sc = new Scanner(System.in);
boolean flag;
for (int i = 0; i < 5;) {
flag = true;
do{
if(!flag){
System.out.println("Wrong input.");
}
System.out.println("Enter marks in subject " + (i + 1) + ":");
marks[i] = sc.nextInt();
flag = false;
}while((marks[i] > 100) || (marks[i] < 0) );
i++;
}
}
void marksheet() {
int j;
System.out.println("STUDENT DETAILS");
System.out.println("NAME : " + name);
System.out.println("ROLL NUMBER : " + roll);
System.out.println("COURSE : " + course);
System.out.println("ADMISSION DATE : " + adm_date);
for (j = 0; j < 5; j++){
System.out
.println("MARKS IN SUBJECT " + (j + 1) + " : " + marks[j]);
}
}
String get_name() {
return name;
}
String get_admission_date() {
return adm_date;
}
};
StudentList class:
package student;
import java.util.*;
public class StudentList {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size;
System.out.println(" Enter the maximum number of student:");
size = sc.nextInt();
int i = 0;
boolean flag = false;
Student list[] = new Student[size];
char choice;
while (!flag) {
System.out
.println(" *******************STUDENTS ADMISSION******************** ");
System.out.println("1. Admission");
System.out.println("2. Enter marks");
System.out.println("3. Display marksheet");
System.out.println("4. Total number of students");
System.out.println("6. EXIT");
System.out.println("Enter choice: ");
choice = sc.next().charAt(0);
switch (choice) {
case '1':
if (i >= size) {
System.out.println("Maximum student capacity reached");
break;
}
list[i] = new Student();
list[i].admission();
list[i].get_marks();
i++;
break;
case '2': {
int j, k;
System.out
.println("Enter the student roll number whose marksheet is to be prepared: ");
k = sc.nextInt();
for (j = 0; j < Student.student_count; j++) {
if (list[j].ret_roll() == k) {
list[j].get_marks();
break;
}
}
if (j == Student.student_count)
System.out.println("Student not admitted yet ");
break;
}
case '3': {
int j, k;
System.out
.println("Enter the student roll number whose marksheet is to be displayed: ");
k = sc.nextInt();
for (j = 0; j < Student.student_count; j++) {
if (list[j].ret_roll() == k) {
list[j].marksheet();
break;
}
}
if (j == Student.student_count)
System.out.println("Student not admitted yet ");
break;
}
case '4':
System.out.println("Total students: ");
Student.student_number();
break;
case '6':
System.out.println("Thank You");
flag = true;
break;
default:
System.out.println(" Invalid choice");
}
}
sc.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.