Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

there is a java ques and coding but I am unable to understand the error and solve it, could you please revise my coding as

there is a java ques and coding but I am unable to understand the error and solve it, could you please revise my coding as soon as possible and help me in the question. or you also can provide the new solution-------JAVA question

--

QUESTION-- might include Arrays, methods/functions, and Classes - to creating a simple Student management system.

The Student Management System has

the ability to insert a new student record, delete

a student record by number, and delete

a student record by name.

In terms of adding

(or insert) a Student, the program should take as input three

values: ,,,.

In order to add a student, the must be Insert. When the Insert

command is entered, the corresponding student number, name and program is added

to the system. All fields are mandatory. Fields are separated by commas and

there are no spaces.

In terms of deleting a student,

there are two commands. Command Delete_by_number, should

delete the student by searching the student number. When deleting by name, the

command Delete_by_name

must be entered.

Delete:

Delete_by_name>,.

When deleting by name, if there

are multiple students with the same name,then all occurrences of the name

should be deleted. Similar to Insert, all fields are mandatory, fields are

separated by commas, and there are no spaces.

The maximum values are:

Student Number: 4 characters

Name: 8 characters

Program: 8 characters

I've provided the starter code

that you must use and add on to. Before submitting, please ensure your program

is functional, has the appropriate validations, comments, and all functions are

complete. I've placed // TO DO comments to show the areas that need to be

complete.

Sample test data:

Enter Students or exit

insert,101,Jeff,Computers

insert,102,Susan,Physics

insert,103,Bob,Biology

insert,104,Ringo,IT

delete_by_number,104

delete_by_name,Susan

exit

ID Number Name Program

1 101 Jeff Computers

2 103 Bob Biology

CODING

import java.util.*;

class Main {

public static void main(String[] args) {

System.out.println("Hello world!");

Scanner in = new Scanner(System.in);

List lst = new ArrayList();

while(in.hasNext()) {

String comm = in.nextLine();

if(comm.equals("exit")) {

break;

}

else {

String[] arr = comm.split(",");

if(arr[0].equals("insert")) {

Student s = new Student(Integer.parseInt(arr[1]), arr[2], arr[3]);

lst.add(s);

}

else if(arr[0].equals("delete_by_number")) {

for(int i = 0; i < lst.size(); i++) {

Student s = lst.get(i);

if(s.getID() == Integer.parseInt(arr[1])) {

lst.remove(i);

break;

}

}

}

else if(arr[0].equals("delete_by_name")) {

for(int i = 0; i < lst.size(); i++) {

Student s = lst.get(i);

if(s.getName().equals(arr[1])) {

lst.remove(i);

i--;

}

}

}

}

}

System.out.println("ID Number Name Program");

for(int i = 0; i < lst.size(); i++) {

Student s = lst.get(i);

System.out.printf("%d %d %s %s ", i, s.getID(), s.getName(), s.getProgram());

}

}

}

STRATER CODE

public class Student { String[][] student; // store the students int studentSize; // number of students added public Student() { // there can be a maximum of 30 students // Number, name, and program are stored for each student student = new String[30][3]; studentSize= 0; // when the object is initialized, the size is 0 } // this function stores the student's number, name, and program in the // Student array public void storeStudents(String number, String name, String program) { // TO DO } // delete the student record from the student array based on the number // provided public void deleteStudentByNumber(String number) { // TO DO } // delete the student record from the student array based on the name // provided. If there are multiple students with the same name, delete // all names public void deleteStudentByName(String name) { // TO DO } // Print the elements in the student array public void printStudents() { // Table headers System.out.printf("%-5s%-10s%-10s%-10s%n","ID","Number","Name","Program"); // TO DO. // //Use printf based on the columns / width defined above } // Returns the numbers of students added public int getStudentSize() { // TO DO return 0; // this is a placeholder only (so that the program compiles } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions