This project will simulate the Student class and test basic…

$25.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

This project will simulate the Student class and test basic data structure skill like searching, sorting, insertion ; by performing following operation:
1. Inserting
2. Searching
3. Sorting

Source Code:
/***
* Title: Student class
* @author
* Date:
* File Name: Student.java
*/

public class Student {
private String title;
private String firstName;
private String lastName;
private long id;
private int day;
private int month;
private int year;
private int assignment1;
private int assignment2;
private double weeklyMark;
private double finalExam;
private double finalMarks;
private String grade;

Student() {

}

/***
*
* @param title
* @param firstName
* @param lastName
* @param id
* @param day
* @param month
* @param year
* @param assignment1
* @param assignment2
* @param weeklyMark
* @param finalExam
* @param finalMarks
* @param grade
*/
public Student(String title, String firstName, String lastName, long id,
int day, int month, int year, int assignment1, int assignment2,
double weeklyMark, double finalExam) {
super();
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.day = day;
this.month = month;
this.year = year;
this.assignment1 = assignment1;
this.assignment2 = assignment2;
this.weeklyMark = weeklyMark;
this.finalExam = finalExam;

}

/**
* @return the title
*/
public String getTitle() {
return title;
}

/**
* @param title
* the title to set
*/
public void setTitle(String title) {
this.title = title;
}

/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}

/**
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}

/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}

/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}

/**
* @return the id
*/
public long getId() {
return id;
}

/**
* @param id
* the id to set
*/
public void setId(long id) {
this.id = id;
}

/**
* @return the day
*/
public int getDay() {
return day;
}

/**
* @param day
* the day to set
*/
public void setDay(int day) {
this.day = day;
}

/**
* @return the month
*/
public int getMonth() {
return month;
}

/**
* @param month
* the month to set
*/
public void setMonth(int month) {
this.month = month;
}

/**
* @return the year
*/
public int getYear() {
return year;
}

/**
* @param year
* the year to set
*/
public void setYear(int year) {
this.year = year;
}

/**
* @return the assignment1
*/
public int getAssignment1() {
return assignment1;
}

/**
* @param assignment1
* the assignment1 to set
*/
public void setAssignment1(int assignment1) {
this.assignment1 = assignment1;
}

/**
* @return the assignment2
*/
public int getAssignment2() {
return assignment2;
}

/**
* @param assignment2
* the assignment2 to set
*/
public void setAssignment2(int assignment2) {
this.assignment2 = assignment2;
}

/**
* @return the weeklyMark
*/
public double getWeeklyMark() {
return weeklyMark;
}

/**
* @param weeklyMark
* the weeklyMark to set
*/
public void setWeeklyMark(double weeklyMark) {
this.weeklyMark = weeklyMark;
}

/**
* @return the finalMarks
*/
public double getFinalMarks() {
return finalMarks;
}

/**
* @param finalMarks
* the finalMarks to set
*/
public void setFinalMarks(double finalMarks) {
this.finalMarks = finalMarks;
}

/**
* @return the finalExam
*/
public double getFinalExam() {
return finalExam;
}

/**
* @param finalExam
* the finalExam to set
*/
public void setFinalExam(double finalExam) {
this.finalExam = finalExam;
}

/**
* @return the grade
*/
public String getGrade() {
return grade;
}

/**
* @param grade
* the grade to set
*/
public void setGrade(String grade) {
this.grade = grade;
}

public void computeMark() {
finalMarks = (assignment1 + assignment2) * .40 + weeklyMark * .10
+ finalExam * .50;
}

public void setFinalGrade() {
if (finalMarks >= 80.0) {
grade = “HD”;
} else if (finalMarks >= 70.0 && finalMarks < 80.0) { grade = "D"; } else if (finalMarks >= 60.0 && finalMarks < 70.0) { grade = "C"; } else if (finalMarks >= 50.0 && finalMarks < 60.0) { grade = "P"; } else { grade = "N"; } } public boolean equals(Student st) { if (firstName.equals(st.getFirstName()) && lastName.equals(st.getLastName()) && id == st.getId() && day == st.getDay() && month == st.getMonth() && year == st.getYear()) { return true; } return false; } public String toString(){ return "Student ID: "+id+"\n"+ "Name: "+title+""+firstName+""+lastName+"\n" + "DOB: "+day+"/"+month+"/"+year+"\n" + "Marks in Assignment1: "+assignment1+"\n" + "Marks in Assignment2: "+assignment2+"\n" + "Marks in practical: "+weeklyMark+"\n" + "Marks in final exam: "+finalExam+"\n" + "Marks in overall : "+finalMarks+"\n" + "Grade: "+grade+"\n"; } } /*** * Title: Test program to test Student.java implmenetation * @author * Date: * File Name: StudentTest.java */ import java.util.*; public class StudentTest { public static Student studentList[] = new Student[100]; private static int totalStudent = 0; public static void main(String[] args) { double avg; Scanner input = new Scanner(System.in); int choice = 0; do { displayMenu(); choice = input.nextInt(); switch (choice) { case 1: System.out.println("Thank you!GoodBye!"); System.exit(0); break; case 2: addStudent(); break; case 3: display(); break; case 4: avg = averageMark(); System.out .println("Average overall mark for students: " + avg); break; case 5: computeRank(); break; case 6: distributionGrade(); break; case 7: searchBYID(); break; case 8: searchBYName(); break; case 9: highestMark(); break; case 10: sortByID(); break; case 11: sortByName(); break; default: System.out.println("Input Error, please try again"); } } while (choice != 5); input.close(); System.out.printf("\n"); } /*** * Display the main menu */ private static void displayMenu() { System.out.println("\n--------MENU--------"); System.out.println("Please choose an option"); System.out.printf("\n1. Quit."); System.out.printf("\n2. Add a student."); System.out.printf("\n3. Display all students."); System.out.printf("\n4. Compute average overall mark"); System.out .printf("\n5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark"); System.out.printf("\n6. Display the distribution of grades"); System.out.printf("\n7. Search by Student ID"); System.out.printf("\n8. Search by Student Name"); System.out.printf("\n9. Find highest Mark"); System.out.printf("\n10. Sorting by Student ID"); System.out.printf("\n11. Sorting by Student Surnames"); System.out.print("\nEnter option: "); } /*** * Add Student function */ private static void addStudent() { Scanner input = new Scanner(System.in); String title; String firstName; String lastName; long id; int day; int month; int year; int assignment1; int assignment2; double weeklyMark; double finalExam; double finalMarks; String grade; System.out.printf("\nEnter Student's title: "); title = input.nextLine(); System.out.printf("\nEnter Student's first name: "); firstName = input.nextLine(); System.out.printf("Enter Student's last name: "); lastName = input.nextLine(); System.out.printf("Enter Student's s ID: "); id = Integer.parseInt(input.nextLine()); System.out.printf("Enter Student's s date of birth(DD/MM/YYYY): "); String dob[] = input.nextLine().split("/"); day = Integer.parseInt(dob[0]); month = Integer.parseInt(dob[1]); year = Integer.parseInt(dob[2]); System.out.printf("Enter Student's assignment 1 mark: "); assignment1 = Integer.parseInt(input.nextLine()); System.out.printf("Enter Student's assignment 2 mark: "); assignment2 = Integer.parseInt(input.nextLine()); System.out.printf("Enter Student's weekly practical marks: "); weeklyMark = Double.parseDouble(input.nextLine()); System.out.printf("Enter Student's final exam marks: "); finalExam = Double.parseDouble(input.nextLine()); System.out.printf("\nStudent Added\n"); Student s1 = new Student(title, firstName, lastName, id, day, month, year, assignment1, assignment2, weeklyMark, finalExam); s1.computeMark(); s1.setFinalGrade(); studentList[totalStudent] = s1; totalStudent++; } private static void searchBYID() { Scanner scanner = new Scanner(System.in); System.out.printf("Enter Student's s ID: "); long id = Integer.parseInt(scanner.nextLine()); boolean found = false; for (int index = 0; index < totalStudent; index++) { if (studentList[index].getId() == id) { System.out.println(studentList[index].toString()); found = true; break; } } if (found == false) { System.out.println("Student not found!"); } } private static void searchBYName() { Scanner scanner = new Scanner(System.in); System.out.printf("\nEnter Student's first name: "); String firstName = scanner.nextLine(); System.out.printf("Enter Student's last name: "); String lastName = scanner.nextLine(); boolean found = false; for (int index = 0; index < totalStudent; index++) { if (studentList[index].getFirstName().equalsIgnoreCase(firstName) && studentList[index].getLastName().equalsIgnoreCase( lastName)) { System.out.println(studentList[index].toString()); found = true; break; } } if (found == false) { System.out.println("Student not found!"); } } private static void sortByID() { int j; boolean flag = true; // set flag to true to begin first pass Student temp; // holding variable while (flag) { flag = false; // set flag to false awaiting a possible swap for (j = 0; j < totalStudent - 1; j++) { if (studentList[j].getId() < studentList[j + 1].getId()) // change // to // >
// for
// ascending
// sort
{
temp = studentList[j]; // swap elements
studentList[j] = studentList[j + 1];
studentList[j + 1] = temp;
flag = true; // shows a swap occurred
}
}
}
}

private static void sortByName() {
int N = totalStudent;
int i, j, pos;
Student temp;
for (i = 0; i < N - 1; i++) { pos = i; for (j = i + 1; j < N; j++) { if (studentList[j].getLastName().compareTo( studentList[pos].getLastName()) < 0) { pos = j; } } /* Swap arr[i] and arr[pos] */ temp = studentList[i]; studentList[i] = studentList[pos]; studentList[pos] = temp; } } private static void highestMark() { int j; boolean flag = true; // set flag to true to begin first pass Student temp; // holding variable while (flag) { flag = false; // set flag to false awaiting a possible swap for (j = 0; j < totalStudent - 1; j++) { if (studentList[j].getFinalMarks() < studentList[j + 1] .getFinalMarks()) // change // to // >
// for
// ascending
// sort
{
temp = studentList[j]; // swap elements
studentList[j] = studentList[j + 1];
studentList[j + 1] = temp;
flag = true; // shows a swap occurred
}
}
}

System.out.println(“First Highest Overall Marks Student’s Details: “);
System.out.println(studentList[totalStudent – 1].toString());
System.out.println(“Second Highest Overall Marks Student’s Details: “);
System.out.println(studentList[totalStudent – 2].toString());

}

private static void distributionGrade() {
int HD = 0;
int P = 0;
int D = 0;
int C = 0;
int N = 0;
for (int index = 0; index < totalStudent; index++) { if (studentList[index].getGrade().equals("HD")) { HD++; } else if (studentList[index].getGrade().equals("D")) { D++; } else if (studentList[index].getGrade().equals("P")) { P++; } else if (studentList[index].getGrade().equals("C")) { C++; } else if (studentList[index].getGrade().equals("N")) { N++; } } System.out.println("Number of HD: " + HD); System.out.println("Number of P: " + P); System.out.println("Number of D: " + D); System.out.println("Number of C: " + C); System.out.println("Number of N: " + N); } private static double averageMark() { double overall = 0; for (int index = 0; index < totalStudent; index++) { overall += studentList[index].getFinalMarks(); } return (overall) / totalStudent; } private static void display() { for (int index = 0; index < totalStudent; index++) { System.out.println(studentList[index].toString() + "\n"); } } private static void computeRank() { double avg = averageMark(); int above = 0; int below = 0; for (int index = 0; index < totalStudent; index++) { if (avg > studentList[index].getFinalMarks()) {
below++;
}

if (avg < studentList[index].getFinalMarks()) { above++; } } System.out.println("Number of Above marks Student: " + above); System.out.println("Number of below marks Student: " + below); } } Testing: 1. Add Student 2. Display Student 3. Search by ID --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: 2 Enter Student's title: Mr. Enter Student's first name: Neo Enter Student's last name: Answerson Enter Student's s ID: 45 Enter Student's s date of birth(DD/MM/YYYY): 3/3/1990 Enter Student's assignment 1 mark: 45 Enter Student's assignment 2 mark: 45 Enter Student's weekly practical marks: 67 Enter Student's final exam marks: 90 Student Added --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: 3 Student ID: 45 Name: Mr. Neo Answerson DOB: 3/3/1990 Marks in Assignment1: 45 Marks in Assignment2: 45 Marks in practical: 67.0 Marks in final exam: 90.0 Marks in overall : 87.7 Grade: N --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: 7 Enter Student's s ID: 45 Student ID: 45 Name: Mr. Neo Answerson DOB: 3/3/1990 Marks in Assignment1: 45 Marks in Assignment2: 45 Marks in practical: 67.0 Marks in final exam: 90.0 Marks in overall : 87.7 Grade: N --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: 4 Average overall mark for students: 87.7 --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: 7 Enter Student's s ID: 34 Student not found! --------MENU-------- Please choose an option 1. Quit. 2. Add a student. 3. Display all students. 4. Compute average overall mark 5. how many students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 6. Display the distribution of grades 7. Search by Student ID 8. Search by Student Name 9. Find highest Mark 10. Sorting by Student ID 11. Sorting by Student Surnames Enter option: UML diagram: