Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java second semester course description : Refresh concepts taught in CSIS-1400.

ID: 3662631 • Letter: J

Question

java second semester course

description:

Refresh concepts taught in CSIS-1400.
You will write a program that keeps track of a list of students and exposes a given set of choices with a menu. Do so by implementing at least two classes: Student and StudentApp

ad student :

The class Student represents a student. Notice that neither count nor sNumber are passed to the constructor. These two fields also have no set method (mutator).

Student - firstName String lastName String - sNumber int major: String gpa double -count int + «constructor» Student () + «constructor» Studen (fName String, IName: String, maj : String, gpa double ) +getFirstName ): String +setFirstName( fName String) +getLastName): String + setLastName (IName: String) + getSNumber ()int + getMajor () : String + setMajor ( maj: String) + getGpa () : double + setGpa ( gpa : double ) + toString): String

Explanation / Answer

Student.java

public class Student

{

private final int startStudentNumber=123;

private String studentNumber;

private String firstName;

private String lastName;

private String major;

private double gpa;

private static int count=0;

public Student()

{

//default constructor

}

public Student(String firstName, String lastName, String major, double gpa)

{

this.firstName=firstName;

this.lastName=lastName;

this.major=major;

this.gpa=gpa;

studentNumber=”S” +(startStudentNumber + count);

count++;

}

public String getStudentNumber()

{

return studentNumber;

}

public String getFirstName()

{

return firstName;

}

public void setFirstName(String firstName)

{

this.firstName=firstName;

}

public void setGpa(double gpa)

{

this.gpa=gpa;

}

public int getCount()

return count;

}

public String to String()

{

return getStudentNumber()+” “+getFirstName)+” “+getLastNme()+”(“+getMajor()+”)gpa”+getGpa()+”s”;

}

}

StudentApp.java

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class StudentApp

{

public static void main(String args[])

{

List<Student> students = new ArrayList<Student>();

Scanner sc = new Scanner(System.in);

int option;

String firstName,lastName,major;

double gpa;

while(true)

{

System.out.println(“MENU”);

System.out.println(“1.Add a student ”+”2.Search a student”+”3.Delete a student ”+”5.Display total students ”+”6.Exit”);

option=sc.nextInt();

switch(option)

{

case 1:

System.out.println(“First Name:”);

firstName=sc.next();

System.out.println(“Last name:”)

last Name = sc.next();

System.out.println(“Major:”);

major=sc.next();

System.out.println(“GPA”);

Gpa=sc.nextDouble();

Student student=new Student(firstName,lastName,major,gpa);

students.add(student);

break;

case2:

String findStudentID;

System.out.println(“Find student with ID”);

findStudentID = sc.next();

boolean isFound= false;

for(Student st:students)

{

if(st.getStudentNumber()equalsIgnoreCase(findStudentID))

{

System.out.println(st);

isFound=true;

}

}

if(!isfound)

{

System.out.println(“Student Not found !!Check the student Id again”);

}

break;

Case 3:

String deleteStudentID;

System.out.println(“delete student with student ID”);

deleteStudentID = sc.next();

Student deleteStudent=null;

for(Student st:students)

{

if(st.getStudentNumber().equalsIgnoreCase(deleteStudentiD))

{

deleteStudent = st;

break;

}

}

if(deleteStudent!=null)

{

students.remove(deleteStudent);

System.out.println(deleteStudent+”has been deleted”);

}

else

{

Sysetm.out.println(“Student not found with the given student Id”);

}

break;

case 4:

Sysetm.out.println(“Students Details”);

for(Student st:students)

{

System.out.println(st);

}

break;

Case 5:

System.out.println(“Total Number of Students :”+students.size());

break;

default:

System.out.println(“Invalid choice”);

}

if(option==5)

break;

}

}

}