Extend your program for managing student data The name of th

Extend your program for managing student data. The name of the class should be StudentData2. an underscore, and your Netted run together; if your NetID is abcde6, your class name should be StudentData2_abcde6. The program should operate through the Eclipse console window. All requirements from assignment 1 remain in effect, except as increased or amended below The requirements are: StudentData2 will have: a main method, in which it creates an instance of StudentData2 and calls that instance\'s prompt method (see 2. below and instance Scanner object to read user input can instance array of Student objects (declaration only) a counter (type int) for the number of Student objects A prompt method with return type void for the user to enter a command (Sting): add: adding a new student record delete deleting a student record modify, modifying a student record read, reading (displaying) one or more student records exit, stop the program After a command is entered, the program will respond as follows: add calls the add method (return type void, takes a Student array and an int as parameters), which displays a prompt asking for the student\'s last name, first name, and ID number delete: calls the delete method (return type void, takes a Student array as its parameter), which displays a prompt asking for the student\'s last name, first name, and ID number modify: calls the modify method (return type void, takes a Student array as its parameter), which displays a prompt asking for the student\'s last name, first name. ID number, new last name, new first name, and new ID number read: calls the read method (return type Student array, takes a Student array as its parameter), which displays a prompt asking for the match field and its value exit stop the program using System exit(0); The StudentData2 class file will contain a second class. Student after the studentData2 declaration: Student should have three private data fields: String lastName. String firstName. and long id Student should have appropriate public get and set methods for each data field. That is. the get methods should return the correct data type and field and the set methods should take the correct data type as a parameter and assign its value to the corresponding field. Student should have a constructor that requires as parameters two Strings (assigned to lastName and firstName) and a long (which will be assigned to id). Additional Constraints The program should be implemented as a single file and Java class. Each of the required commands should be implemented as separate methods (as far as possible) and operate by passing parameters and/or returning values. Comments should be provided for the class and for each variable and method, briefly explaining their usage.

Solution


package studentdata2;

import java.util.Scanner;


public class StudentData2 {

void prompt()
{
System.out.println(\"add: adding a new student record\");
System.out.println(\"delete: deleting a student record\");
System.out.println(\"modify: modifying a student record\");
System.out.println(\"read: reading (displaying) one or more student record\");
System.out.println(\"exit: stop the program\");
}
public static void main(String[] args) {
Student students[]=new Student[50];
StudentData2 ss=new StudentData2();
ss.prompt();
Scanner input=new Scanner(System.in);
int n=0;
System.out.println(\"Enter the command: \");
String command=input.next();
if(command.equalsIgnoreCase(\"add\"))
{
n=ss.add(students,n,input);
}
else if(command.equalsIgnoreCase(\"delete\"))
{
ss.del(students,n,input);
}
else if(command.equalsIgnoreCase(\"modify\"))
{
System.out.println(\"Enter the id to modify: \");
long ID=input.nextLong();
ss.modify(students,n,ID,input);
}
else if(command.equalsIgnoreCase(\"read\"))
{
System.out.println(\"Enter the id to read: \");
long ID=input.nextLong();
Student S=ss.read(students,n,ID);
System.out.println(\"Student details\");
System.out.println(\"First Name: \"+S.getFirstName());
System.out.println(\"Last Name: \"+S.getLastName());
System.out.println(\"ID: \"+S.getID());
}
else if(command.equalsIgnoreCase(\"exit\"))
{
System.exit(0);
}
}

private int add(Student[] students, int n,Scanner input) {
System.out.println(\"Enter first name, last name and id to add\");
students[n++]=new Student(input.next(),input.next(),input.nextLong());
return n;
}

private void del(Student[] students, int n,Scanner input) {
System.out.println(\"Enter id to delete\");
long ID=input.nextInt();
for(int i=0;i<n;i++)
{
if(students[i].getID()==ID)
{
System.out.println(\"Student Deleted\");
System.out.println(\"ID: \"+students[i].getID());
System.out.println(\"First Name: \"+students[i].getFirstName());
System.out.println(\"Last Name: \"+students[i].getLastName());
students[i].setID(0);
students[i].setFirstName(\"\");
students[i].setLastName(\"\");
break;
}
}
}

private void modify(Student[] students, int n, long ID,Scanner input) {
for(int i=0;i<n;i++)
{
if(students[i].getID()==ID)
{
System.out.println(\"Enter new first name, new last name and new id to add\");
students[i].setFirstName(input.next());
students[i].setLastName(input.next());
students[i].setID(input.nextLong());
System.out.println(\"Student modified\");
break;
}
}
}

private Student read(Student[] students, int n, long ID) {
Student S=null;
for(int i=0;i<n;i++)
{
if(students[i].getID()==ID)
{
S=new Student(students[i].getFirstName(),students[i].getLastName(),students[i].getID());
break;
}
}
return S;
}


  
}

class Student
{
private String firstName;
private String lastName;
private long id;
public Student(String first, String last, long ID)
{
firstName=first;
lastName=last;
id=ID;
}
public void setFirstName(String first)
{
firstName=first;
}
public void setLastName(String last)
{
lastName=last;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public void setID(long ID)
{
id=ID;
}
public long getID()
{
return id;
}
}

 Extend your program for managing student data. The name of the class should be StudentData2. an underscore, and your Netted run together; if your NetID is abcd
 Extend your program for managing student data. The name of the class should be StudentData2. an underscore, and your Netted run together; if your NetID is abcd
 Extend your program for managing student data. The name of the class should be StudentData2. an underscore, and your Netted run together; if your NetID is abcd

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site