Question
First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private:
A. Title of the student (eg Mr, Miss, Ms, Mrs etc)
B. A first name (given name)
C. A last name (family name/surname)
D. Student number (ID) – an integer number (of type long)
E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class from JAVA)
The student class will have at least the following constructors and methods:
(i) two constructors - one without any parameters (the default constructor), and one with parameters to give initial values to all the instance variables.
(ii) only necessary set and get methods for a valid class design.
(iii) method to write the output of all the instance variables in the class to the screen (which will be overridden in the respective child classes, as you have more instance variables that required to be output).
(iv) an equals method which compares two student objects and returns true if they have the same student names, and the same date of birth, otherwise it returns false.
You may add other methods in the Student class as you see appropriate.
Design, code in Java, test and document (at least) three classes – a CourseWorkStudent class, a ResearchStudent class (which both derive from the Student class) and a Client program.
For coursework students:
(a) There are two assignments, each marked out of a maximum of 100 marks and equally weighted. The marks for each assignment are recorded separately.
(b) There is weekly practical work. The marks for this component are recorded as a total mark obtained (marked out of a maximum of 20 marks) for all practical work demonstrated during the semester.
(c) There is one final examination that is marked out of a maximum of 100 marks and recorded separately.
(d) An overall mark (to be calculated within the class)
(e) A final grade, which is a string (think of a way to avoid code duplication for calculating this)
The final grade, for coursework students, is to be awarded on the basis of an overall mark, which is a number in the range 0 to 100 and is obtained by calculating the weighted average of the student's performance in the assessment components. The criteria for calculating the weighted average is as defined below:
The two assignments together count for a total of 50% (25% each) of the final grade, the practical work is worth 20%, and the final exam is worth 30% of the final grade.
For research students:
(a) There is a proposal component (marked out of a maximum of 100 marks).
(b) One final oral presentation (marked out of a maximum of 20 marks).
(c) One final thesis (marked out of a maximum of 100 marks).
(d) An overall mark (to be calculated within the class)
(f) A final grade, which is a string (think of a way to avoid code duplication for calculating this)
The final grade, for research students, is to be awarded on the basis of an overall mark, which is a number in the range 0 to 100 and is obtained by calculating the weighted average of the student's performance in the assessment components. The criteria for calculating the weighted average is as defined below:
The proposal component is worth 30% of the final grade, the final oral presentations are worth a total of 10%, and the final thesis is worth 60% of the final grade A grade is to be awarded for coursework and research students as follows: An overall mark of 80 or higher is an HD, an overall mark of 70 or higher (but less than 80) is a D, an overall mark of 60 or higher (but less than 70) is a C, an overall mark of 50 or higher (but less than 60) is a P, and an overall mark below 50 is an N.
The client program will allow entry of these data for several different student into an ArrayList and then perform some analysis and queries.
Your client class (program) will provide the user with a menu to perform the following operations. You will need to think of a way to ask the user whether they are dealing with the coursework student or research student. You will also need to load the information of the students from a text file (student.txt) before displaying the menu. You only need one ArrayList and one menu for this.
Quit (exit the program)
2. Add (to the ArrayList) all the marks information about a coursework or research student by reading it from another text file and determine the student’s overall mark and grade.
You will need to consider how to deal with the different assessment components for the coursework and research students. You may use two different text files, one for coursework students and another for research students. The program should read the correct text file for this purpose.
Use Exception Handling if the student cannot be found in the ArrayList.
Given student number (ID), remove the specified student and relevant information from the ArrayList. It is always good to ask the user to confirm again before removing the record. For confirmation, output the student number (ID) and the name to the user.
Output from the ArrayList the details (all information including the overall mark and the grade) of all students currently held in the ArrayList.
Compute and output the overall mark and grade for coursework or research students
Determine and display how many coursework or research 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
Given a coursework or research student number (ID), view all details of the student with that number. If the student is not found in the ArrayList, an appropriate error message is to be displayed
Given a coursework or research student’s name (both surname and given name – ignoring case), view all details of that student. If the student is not found in the ArrayList, an appropriate error message is to be displayed. If more than one student having the same name, display all of them.
Sort the ArrayList of the student objects into ascending order of the students’ numbers (IDs), and output the sorted array - implement an appropriate sorting algorithm for this, and explain why such algorithm is selected (in internal and external documentation).
Output the sorted ArrayList from (9) to a CSV file. If the ArrayList is not sorted, this option cannot be selected.
Note that the program will loop around until the user selects the first option (Quit).
Set up a student ArrayList of N student objects, and test it with N = 10 (at least). You have to store your test data in a file so that your program can read them.
The client class should be well-structured and should have the essential methods in addition to the main method.
The interaction with the user can be via the command line (i.e., no graphical user interface is expected).
Devise suitable test data to test all sections of program code. You will need to provide all the test data used.
Your program should also include a method (e.g., StudentInfo( )) to output your student details (name, student number, mode of enrolment, tutor name, tutorial attendance day and time) at the start of program results.
Note: The question requires you to use an ArrayList. Also, the sorting algorithm used must be coded within your program and not called from any Java libraries. You should not use any Java libraries for sorting algorithm, date and output to CSV file (e.g. FileWriter). You are required to use only materials covered in the lecture notes and the textbook to complete this assignment.
package loan;
import java.io.*;
import java.util.*;
// Defines class Student
class Student
{
// Instance variables to store student information
String title;
String firstName;
String lastName;
long id;
int day, month, year;
// Default constructor to assign default values to instance variables
Student()
{
title = firstName = lastName = "";
id = day = month = year = 0;
}
// Parameterized constructor to assign parameter values to instance variables
Student(String title, String firstName, String lastName, long id,
int day, int month, int year)
{
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.day = day;
this.month = month;
this.year = year;
}
// Getter methods
String getTitle()
{
return title;
}
String getFirstName()
{
return firstName;
}
String getLastName()
{
return lastName;
}
long getId()
{
return id;
}
int getDay()
{
return day;
}
int getMonth()
{
return month;
}
int getYear()
{
return year;
}
String getDOB()
{
return day + "/" + month + "/" + year;
}
// Setter methods
void setTitle(String title)
{
this.title = title ;
}
void setFirstName(String firstName)
{
this.firstName = firstName;
}
void setLastName(String lastName)
{
this.lastName = lastName;
}
void setId(long id)
{
this.id = id;
}
void setDOB(int day, int month, int year)
{
this.day = day;
this.month = month;
this.year = year;
}
// Overload toString() method to return student information
public String toString()
{
return "\n Name: " + title + " " + firstName + " " + lastName +
"\n ID: " + id + "\n DOB: " + getDOB();
}
// Overriding equals() to compare parameter object name and DOB with
// instance object name and DOB
// Returns true if same other wise returns false
public boolean equals(Object other)
{
// Checks if the parameter object other is equals to implicit object
if (other == this)
return true;
// Checks if parameter object other is not an instance of Student class
if (!(other instanceof Student))
return false;
// Type cast parameter object other to Student class object
Student stu = (Student) other;
// Concatenates to get complete name for instance object
String insName = title + firstName + lastName;
// Concatenates to get complete name for parameter object
String othName = stu.title + stu.firstName + stu.lastName;
// Checks name and DOB if same returns true
if(insName.equalsIgnoreCase(othName) &&
getDOB().equalsIgnoreCase(stu.getDOB()))
return true;
// Otherwise returns false
else
return false;
}
}// End of class Student
// Defines derived class CourseWorkStudent extended from super class Student
class CourseWorkStudent extends Student
{
// Instance variable to store marks
double assignment1, assignment2;
double practicalWork;
double finalExamination;
double weightedAverage;
String grade;
// Default constructor to assign default values to instance variables
CourseWorkStudent()
{
// Calls the base class default constructor
super();
assignment1 = assignment2 = practicalWork = finalExamination =
weightedAverage = 0.0;
grade = "";
}
// Parameterized constructor to assign parameter values to instance variables
CourseWorkStudent(String title, String firstName, String lastName, long id,
int day, int month, int year, double as1, double as2, double pw, double fe)
{
// Calls the base class parameterized constructor
super(title, firstName, lastName, id, day, month, year);
assignment1 = as1;
assignment2 = as2;
practicalWork = pw;
finalExamination = fe;
weightedAverage = 0.0;
grade = "";
}
// Method to calculate weighted average and grade
void calculate()
{
weightedAverage += (assignment1 * 0.25) + (assignment2 * 0.25);
weightedAverage += practicalWork * 0.20;
weightedAverage += finalExamination * 0.30;
if(weightedAverage >= 80.0)
grade = "HD";
else if(weightedAverage >= 70.0)
grade = "D";
else if(weightedAverage >= 60.0)
grade = "C";
else if(weightedAverage >= 50.0)
grade = "P";
else
grade = "N";
}
double getWeightedAverage()
{
return weightedAverage;
}
// Overload toString() method to return course work student information
public String toString()
{
String result = super.toString();
result += "\n Assignment1: " + assignment1 +
"\n Assignment2: " + assignment2 +
"\n Practical Work: " + practicalWork +
"\n Final Examination: " + finalExamination +
"\n Weighted Average: " + weightedAverage + "\n Grade: " + grade;
return result;
}
}// End of class CourseWorkStudent
// Defines derived class ResearchStudent extended from super class Student
class ResearchStudent extends Student
{
// Instance variable to store marks
double proposalComponent;
double oralPresentations;
double finalThesis;
double weightedAverage;
String grade;
// Default constructor to assign default values to instance variables
ResearchStudent()
{
// Calls the base class default constructor
super();
proposalComponent = oralPresentations = finalThesis = weightedAverage = 0.0;
grade = "";
}
// Parameterized constructor to assign parameter values to instance variables
ResearchStudent(String title, String firstName, String lastName, long id,
int day, int month, int year, double pc, double op, double ft)
{
// Calls the base class parameterized constructor
super(title, firstName, lastName, id, day, month, year);
proposalComponent = pc;
oralPresentations = op;
finalThesis = ft;
weightedAverage = 0.0;
grade = "";
}
// Method to calculate weighted average and grade
void calculate()
{
weightedAverage += proposalComponent * 0.30;
weightedAverage += oralPresentations * 0.10;
weightedAverage += finalThesis * 0.60;
if(weightedAverage >= 80.0)
grade = "HD";
else if(weightedAverage >= 70.0)
grade = "D";
else if(weightedAverage >= 60.0)
grade = "C";
else if(weightedAverage >= 50.0)
grade = "P";
else
grade = "N";
}
double getWeightedAverage()
{
return weightedAverage;
}
// Overload toString() method to return research student information
public String toString()
{
String result = super.toString();
result += "\n Proposal Component: " + proposalComponent +
"\n Oral Presentations: " + oralPresentations +
"\n Final Thesis: " + finalThesis +
"\n Weighted Average: " + weightedAverage + "\n Grade: " + grade;
return result;
}
}// End of class ResearchStudent
public class StudentResult
{
Scanner sc = new Scanner(System.in);
ArrayList <Student> students = new ArrayList<Student>();
ArrayList <Student> courses = new ArrayList<Student>();
// Method to read the file contents and stores it in
// instance arrays
void readStudents()
{
// Scanner class object declared
Scanner readStuF = null;
// try block begins
try
{
// Opens the file for reading
readStuF = new Scanner(new File("student.txt"));
// Loops till end of the file to read records
while(readStuF.hasNextLine())
{
String stu = readStuF.nextLine();
String []eachStu = stu.split(" ");
students.add(new Student(eachStu[0], eachStu[1],
eachStu[2], Long.parseLong(eachStu[3]),
Integer.parseInt(eachStu[4]), Integer.parseInt(eachStu[5]),
Integer.parseInt(eachStu[6])));
}// End of while loop
}// End of try block
// Catch block to handle file not found exception
catch(FileNotFoundException fe)
{
System.out.println("\n ERROR: Unable to open the file for reading.");
}// End of catch block
// Closer the file
readStuF.close();
}// End of method
int searchStudentID(long id)
{
for(int c = 0; c < students.size(); c++)
if(id == students.get(c).getId())
return c;
return -1;
}
void searchStudentName(String name)
{
int found = -1;
for(int c = 0; c < courses.size(); c++)
{
if(name.equalsIgnoreCase(courses.get(c).getLastName()))
{
System.out.println(courses.get(c));
found = c;
}
}
if(found == -1)
System.out.println("\n ERROR: No student found on name: " + name);
}
void add()
{
// Scanner class object declared
Scanner readCourseF = null;
Scanner readResearchF = null;
// try block begins
try
{
// Opens the file for reading
readCourseF = new Scanner(new File("courseWorkStudent.txt"));
readResearchF = new Scanner(new File("researchStudent.txt"));
// Loops till end of the file to read records
while(readCourseF.hasNextLine() || readResearchF.hasNextLine())
{
String course = readCourseF.nextLine();
String []eachCour = course.split(" ");
int position = searchStudentID(Long.parseLong(eachCour[0]));
if(position != -1)
courses.add(new CourseWorkStudent(
students.get(position).getTitle(),
students.get(position).getFirstName(),
students.get(position).getLastName(),
students.get(position).getId(),
students.get(position).getDay(),
students.get(position).getMonth(),
students.get(position).getYear(),
Double.parseDouble(eachCour[1]),
Double.parseDouble(eachCour[2]),
Double.parseDouble(eachCour[3]),
Double.parseDouble(eachCour[4])));
String reserch = readResearchF.nextLine();
String []eachReserch = reserch.split(" ");
position = searchStudentID(Long.parseLong(eachReserch[0]));
if(position != -1)
courses.add(new ResearchStudent(students.get(position).getTitle(),
students.get(position).getFirstName(),
students.get(position).getLastName(),
students.get(position).getId(),
students.get(position).getDay(),
students.get(position).getMonth(),
students.get(position).getYear(),
Double.parseDouble(eachReserch[1]),
Double.parseDouble(eachReserch[2]),
Double.parseDouble(eachReserch[3])));
}// End of while loop
calculateGrade();
}// End of try block
// Catch block to handle file not found exception
catch(FileNotFoundException fe)
{
System.out.println("\n ERROR: Unable to open the file for reading.");
}// End of catch block
// Closer the file
readCourseF.close();
readResearchF.close();
}
void calculateGrade()
{
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof CourseWorkStudent)
{
CourseWorkStudent cw = (CourseWorkStudent)courses.get(c);
cw.calculate();
}
}
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof ResearchStudent)
{
ResearchStudent rs = (ResearchStudent)courses.get(c);
rs.calculate();
}
}
}
void showCourseWordStudent()
{
System.out.print("********** Course Work Student Information **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof CourseWorkStudent)
{
CourseWorkStudent cw = (CourseWorkStudent)courses.get(c);
System.out.println(cw);
}
}
}
void showResearchStudents()
{
System.out.print("********** Research Student Information **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof ResearchStudent)
{
ResearchStudent rs = (ResearchStudent)courses.get(c);
System.out.println(rs);
}
}
}
void showCourseWordStudentBelowAboveAvg()
{
double total = 0.0;
int counter = 0;
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof CourseWorkStudent)
{
CourseWorkStudent cw = (CourseWorkStudent)courses.get(c);
total += cw.getWeightedAverage();
counter++;
}
}
double avg = total / counter;
System.out.print("********** Course Work Student below average **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof CourseWorkStudent)
{
CourseWorkStudent cw = (CourseWorkStudent)courses.get(c);
if(cw.getWeightedAverage() < avg)
System.out.println(cw);
}
}
System.out.print("********** Course Work Student above average **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof CourseWorkStudent)
{
CourseWorkStudent cw = (CourseWorkStudent)courses.get(c);
if(cw.getWeightedAverage() > avg)
System.out.println(cw);
}
}
}
void showResearchStudentBelowAboveAvg()
{
double total = 0.0;
int counter = 0;
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof ResearchStudent)
{
ResearchStudent re = (ResearchStudent)courses.get(c);
total += re.getWeightedAverage();
counter++;
}
}
double avg = total / counter;
System.out.print("********** Research Student below average **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof ResearchStudent)
{
ResearchStudent re = (ResearchStudent)courses.get(c);
if(re.getWeightedAverage() < avg)
System.out.println(re);
}
}
System.out.print("********** Research Student above average **********");
for(int c = 0; c < courses.size(); c++)
{
if(courses.get(c) instanceof ResearchStudent)
{
ResearchStudent re = (ResearchStudent)courses.get(c);
if(re.getWeightedAverage() > avg)
System.out.println(re);
}
}
}
void removeStudent()
{
System.out.print("\n Enter student id to remove: ");
long id = sc.nextLong();
int pos = searchStudentID(id);
if(pos == -1)
System.out.println("\n ERROR: No sutdent found having ID: " + id);
else
courses.remove(pos);
}
int menu()
{
System.out.print("\n\n ************** MENU ************** ");
System.out.print("\n\t 1 - Quit \n\t 2 - Add \n\t 3 - Remove Student" +
"\n\t 4 - Show All \n\t 5 - Show Coursework \n\t 6 - Research" +
"\n\t 7 - Coursework Below or Above average" +
"\n\t 8 - Research Below or Above average" +
"\n\t 9 - Search Student by ID \n\t 10 - Search Student by name" +
"\n\t\t What is your choice? ");
return sc.nextInt();
}
public static void main(String []s)
{
StudentResult sr = new StudentResult();
sr.readStudents();
do
{
switch(sr.menu())
{
case 1:
System.exit(0);
case 2:
sr.add();
break;
case 3:
sr.removeStudent();
break;
case 4:
sr.showCourseWordStudent();
sr.showResearchStudents();
break;
case 5:
sr.showCourseWordStudent();
break;
case 6:
sr.showResearchStudents();
break;
case 7:
sr.showCourseWordStudentBelowAboveAvg();
break;
case 8:
sr.showResearchStudentBelowAboveAvg();
break;
case 9:
System.out.print("\n Enter sutdent ID to search: ");
long id = sr.sc.nextLong();
int pos = sr.searchStudentID(id);
if(pos == -1)
System.out.println("\n ERROR: No sudent found on ID: " + id);
else
System.out.println(sr.students.get(pos));
break;
case 10:
System.out.print("\n Enter sutdent surname name to search: ");
String name = sr.sc.next();
sr.searchStudentName(name);
break;
default:
System.out.print("\n Invalid choice!!");
}
}while(true);
}
}
using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...
Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...
In Java, Please do not forget the ToString method in the Student class! In this exercise, you will first create a Student class. A Student has two attributes: name (String) and gradePointAverage (double). The class has a constructor that sets the name and grade point average of the Student. It has appropriate get and set methods. As well, there is a toString method that prints the student's name and their grade point average (highest is 4.0) You will then write...
Write a program in Java according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "print" - prints the student records (first name, last name, grade). "sortfirst" - sorts the student records by first name. "sortlast" - sorts the student records by last name. "sortgrade" - sorts the...
Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...
Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...
Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name Test Score ...
Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...
I need #5 done i cant seem to understand it. it must be written in c++ 4. Numeric Processing Write a program that opens the file "random.txt", reads all the numbers from the file, and calculates and displays the following: a. The number of numbers in the file. b. The sum of all the numbers in the file (a running total) c. The average of all the numbers in the file numFile.cpp Notes: Display the average of the numbers showing...
Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1 Semester: 403 Course Title Programming Submission 27-06-2020 Total Points 8 Date Submission Instructions: • This is an individual assignment. • Please submit your program (Java fle) in Blackboard. You can create one java project, named as Assignment1_id and add separate java file for each question. You can name your javá files as 01.02.... etc. • Make sure that you include your student ID name...
> Hi, this error occurs when i try to run it, any idea why?
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at A2.ClientProgram.readStudents(ClientProgram.java:57)
at A2.ClientProgram.main(ClientProgram.java:553)
Command execution failed."
Zenage Thu, Apr 8, 2021 9:28 PM