main.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
private static String[] name;
public static boolean readFile(String filename) {
File file = new File("studentdata.txt");
try {
Scanner scan = new Scanner(file);
while (scan.hasNextLine() ) {
System.out.println(scan.nextLine().split(","));
addNewStudent(id, firstName, lastName, mathsMark1, mathsMark2, mathsMark3, englishMark1, englishMark2, englishMark3);
}
scan.close();
}
catch (FileNotFoundException e)
{ System.out.println("Failedto readfile");
}
return true;
}
private static void addStudent(int id, String firstName, String lastName,int mathsMark1, int mathsMark2, int mathsMark3, int englishMark1, int englishMark2, int englishMark3) {
Student student = new Student(id, firstName, lastName, mathsMark1, mathsMark2, mathsMark3, englishMark1, englishMark2, englishMark3);
AssessmentMarks mathMarks = new AssessmentMarks("Mathematics", mathsMark1, mathsMark2, mathsMark3);
AssessmentMarks englishMarks = new AssessmentMarks("englishs", englishMark1, englishMark2,englishMark3);
student.mathsMarks = mathMarks;
student.englishMarks = englishMarks;
List<Student> students = new ArrayList<>();
students.add(student);`enter code here`
}
private static void displayReportByMarks() {
System.out.printf("Name " + " " + " " + "Maths " + " " + "A1" + " " + "A2" + " " + "A3" + " " + "Mark " + " " + "English" + " " + "A1" + " " + "A2" + " " + "A3" + "Mark", "\n ");
System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------\n");
System.out.printf("getFullName " + " " + " " + " " + " " + "getMark(mathsMark1)" + " " + "getMark(mathsMark2)" + " " + "getMark(mathsMark3)" + " " + "getAverageMark(mathsMark1, mathsMark2, mathMark3)" + " " + " " + " " + "getMark(englishMark1)" + " " + "getMark(englishMark2)" + " " + "getMark(englishMark3)" + " " + "getAverageMark(englishMark1, englishMark2, englishMark3)", "\n ");
}
private static void displayReportByGrades() {
System.out.printf("Name " + " " + " " + "Maths " + " " + "A1" + " " + "A2" + " " + "A3" + " " + "Grade " + " " + "English" + " " + "A1" + " " + "A2" + " " + "A3" + "Grade", "\n ");
System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------\n");
System.out.printf("getFullName " + " " + " " + " " + " " + "getGrade(mathsMark1)" + " " + "getGrade(mathsMark2)" + " " + "getGrade(mathsMark3)" + " " + "getAverageGrade(getAverageMark(mathsMark))" + " " + " " + " " + "englishMark1" + " " + "englishMark2" + " " + "englishMark3" + " " + "getAverageGrade(getAverageMark(englishMarks))" , "\n ");
}
private static void displayMenu() {
System.out.println("Student Report System");
System.out.println("-----------------------\n");
System.out.println("1) Display student marks");
System.out.println("2) Display student grades");
System.out.println("3) Add new student");
System.out.println("4) Remove student");
System.out.println("5) Exit");
System.out.println("");
System.out.println("Your option selection is: ");
System.out.println("");
}
private static int selectMenuOption() {
int userSelected ;
do {
userSelected = MenuData();
switch(userSelected) {
case 1:
System.out.println("");
userSelected1();
break;
case 2:
System.out.println("");
userSelected2();
break;
case 3:
System.out.println("");
userSelected3();
break;
case 4:
System.out.println("");
userSelected4();
break;
case 5:
System.out.println("");
userSelected5();
break;
default:
System.out.println("");
System.out.println("Invalid selection, please enter an integer value between 1 and 5");
System.out.println("");
break;
}
}
while(userSelected >5);
}
private static int MenuData() {
return 0;
}
private static void userSelected5() {
Exit();
}
private static String Exit() {;
return("Good Bye");
}
private static void userSelected4() {
removeStudent() ;
}
private static void userSelected3() {
addNewStudent();
}
private static void userSelected2() {
displayReportByGrades();
}
private static void userSelected1() {
displayReportByMarks();
}
private static void addNewStudent() {
int id;
String firstName;
String lastName;
int mathsMark1;
int mathsMark2;
int mathsMark3;
int englishMark1;
int englishMark2;
int englishMark3;
Scanner SC= new Scanner(System.in);
System.out.print("Enter ID: ");
id=SC.nextInt();
System.out.print("Enter First Name: ");
firstName=SC.nextLine();
System.out.print("Enter Last Name: ");
lastName=SC.nextLine();
System.out.print("Enter math mark1: ");
mathsMark1=SC.nextInt();
System.out.print("Enter math mark2: ");
mathsMark2=SC.nextInt();
System.out.print("Enter math mark3: ");
mathsMark3=SC.nextInt();
System.out.print("Enter english mark1: ");
englishMark1=SC.nextInt();
System.out.print("Enter english mark2: ");
englishMark2=SC.nextInt();
System.out.print("Enter english mark3: ");
englishMark3=SC.nextInt();
Student student = new Student(id, firstName, lastName);
AssessmentMarks mathMarks = new AssessmentMarks("Mathematics", mathsMark1, mathsMark2, mathsMark3);
AssessmentMarks englishMarks = new AssessmentMarks("englishs", englishMark1, englishMark2,englishMark3);
student.mathsMarks = mathMarks;
student.englishMarks = englishMarks;
List<Student> students = new ArrayList<>();
students.add(student);
private static void removeStudent(){
private static <id> void removeStudent(id, studentToBeRemoved) {
int id;
Scanner SC= new Scanner(System.in);
System.out.print("Enter ID of the student you want to delete ");
id=SC.nextInt();
int id = studentToBeRemoved.getId();
id current = head;
if (head.getId() == id) {
head = head.getNext();
size--;
return true;
}
while (current.getNext() != null) {
id next = current.getNext();
if (next.getId() == id) {
current.setNext(next.getNext());
size--;
return true;
}
current = next;
}
return false;
}
AssessmentMarks.java
public class AssessmentMarks {
private String courseName;
private int assessment1;
private int assessment2;
private int assessment3;
private double mark;
private String userGrade;
public AssessmentMarks(String name, int mark1, int mark2, int mark3) {
courseName = name;
assessment1 = mark1;
assessment2 = mark2;
assessment3 = mark3;
}
public void setMark(int assessmentNumber, int mark) {
this.mark = assessmentNumber;
}
public int getMark(int assessmentNumber) {
return assessmentNumber ;
}
public int getAverageMark() {
return (assessment1 + assessment2 + assessment3) / 3;
}
public String getGrade(int assessmentNumber) {
if (assessmentNumber < 40)
System.out.println("D");
if ((assessmentNumber >= 41) && (assessmentNumber < 49))
System.out.println("C-");
if ((assessmentNumber >= 50) && (assessmentNumber < 59))
System.out.println("C");
if ((assessmentNumber >= 60) && (assessmentNumber < 69))
System.out.println("C+");
if ((assessmentNumber >= 70) && (assessmentNumber < 74))
System.out.println("B-");
if ((assessmentNumber >= 75) && (assessmentNumber < 79))
System.out.println("B");
if ((assessmentNumber >= 80) && (assessmentNumber < 84))
System.out.println("B+");
if ((assessmentNumber >= 85) && (assessmentNumber < 89))
System.out.println("A-");
if ((assessmentNumber >= 90) && (assessmentNumber < 94))
System.out.println("A");
if ((assessmentNumber >= 95) && (assessmentNumber <= 100))
System.out.println("A+");
return getGrade(assessmentNumber);
}
public String getAverageGrade() {
double averageMark = getAverageMark();
if (averageMark < 40)
System.out.println("D");
if ((averageMark >= 41) && (averageMark < 49))
System.out.println("C-");
if ((averageMark >= 50) && (averageMark < 59))
System.out.println("C");
if ((averageMark >= 60) && (averageMark < 69))
System.out.println("C+");
if ((averageMark >= 70) && (averageMark < 74))
System.out.println("B-");
if ((averageMark >= 75) && (averageMark < 79))
System.out.println("B");
if ((averageMark >= 80) && (averageMark < 84))
System.out.println("B+");
if ((averageMark >= 85) && (averageMark < 89))
System.out.println("A-");
if ((averageMark >= 90) && (averageMark < 94))
System.out.println("A");
if ((averageMark >= 95) && (averageMark <= 100))
System.out.println("A+");
return getAverageGrade();
}
public String markToGrade(int mark) {
if (mark < 40)
System.out.println("D");
if ((mark >= 41) && (mark < 49))
System.out.println("C-");
if ((mark >= 50) && (mark < 59))
System.out.println("C");
if ((mark >= 60) && (mark < 69))
System.out.println("C+");
if ((mark >= 70) && (mark < 74))
System.out.println("B-");
if ((mark >= 75) && (mark < 79))
System.out.println("B");
if ((mark >= 80) && (mark < 84))
System.out.println("B+");
if ((mark >= 85) && (mark < 89))
System.out.println("A-");
if ((mark >= 90) && (mark < 94))
System.out.println("A");
if ((mark >= 95) && (mark <= 100))
System.out.println("A+");
return markToGrade(mark);
}
public String CourseName (String name) {
return courseName = name;
}
public String getCourseName () {
return courseName;
}
student.java
class Student {
private int id;
private String firstName;
private String lastName;
public AssessmentMarks mathsMarks;
public AssessmentMarks englishMarks;
public Student(int id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getFullName() {
return firstName + " " + lastName;
}
}
What I have tried:
design and build a console application that manages a student database. This application will store student information along with their assessment marks. The user will be shown a menu that allows them to add students, remove students, and display a report that shows the student's grade equivalent to their mark. The application will read a text file ‘studentdata.txt’ containing the data for several students. The data will be stored using classes and abstract data types.
I create three main, student, and assessmentmarks. not sure about the programme construction. any idea why it is not compiled and do I create classes correctly?