/** * Author: Tan Jun Qi * Student ID: 33872846 * Unit: ICT 167 Principles of computer Science * Lecturer: Aaron Yeo * */ public class Postgraduate extends Student { int assignment; int presentation; int exam; double overallmark; public Postgraduate(String type,String title,String firstname,String lastname,long StuID,int day,int month,int year, int assignment, int presentation, int exam) { super(type,title, firstname, lastname, StuID, day, month, year); this.assignment = assignment; this.presentation = presentation; this.exam = exam; Overallmark(); } public void Overallmark() // overide from super class { double totala = assignment*0.3; // times 30% double present = presentation*0.2; //time 20% double texam = exam*0.5; // times 50% double total = totala+present+texam; // add together overallmark = total; } public double getOverallmark() { return overallmark; // overide from super clasee } public void print() { super.print(); super.grade(overallmark); System.out.println("The assignment mark is "+assignment); System.out.println("The presentation is "+presentation); System.out.println("The exam mark is "+exam); System.out.printf("The overallmark is %.2f\ngS",overallmark); System.out.println("The grade is "+grade); } public int getAssignment() { return assignment; } public void setAssignment(int assignment) { this.assignment = assignment; } public int getPresentation() { return presentation; } public void setPresentation(int presentation) { this.presentation = presentation; } public int getExam() { return exam; } public void setExam(int exam) { this.exam = exam; } } /** *Author: Tan Jun Qi * Student ID: 33872846 * Unit: ICT 167 Principles of computer Science * Lecturer: Aaron Yeo * */ public class UndergradeStudent extends Student{ int assignment1; int assignment2; int assignment3; int practical; int exam; double overallmark; public UndergradeStudent(String type, String title,String firstname, String lastname,long stuID,int day, int month, int year,int assignment1, int assignment2, int assignment3,int practical, int exam) { super(type, title, firstname,lastname,stuID, day, month, year); this.assignment1 = assignment1; this.assignment2 = assignment2; this.assignment3 = assignment3; this.practical = practical; this.exam = exam; Overallmark(); // calculate marks when object created } public UndergradeStudent() { } public void Overallmark() { // overide from super class double ass1 = assignment1*0.15; // 15% double ass2 = assignment2*0.15;//15% double ass3 = assignment3*0.15;//15% double exam1 = exam*0.45;//45* double prac = practical*0.1;//10% double overallmark = ass1+ass2+ass3+exam1+prac; // adding them up this.overallmark = overallmark; // assigned to instance variable } public double getOverallmark() { //overide from super class return overallmark; } public void print() { super.print(); super.grade(overallmark); System.out.println("The mark for assignment 1 is "+assignment1); System.out.println("The mark for assignment 2 is "+assignment2); System.out.println("The mark for assignment 3 is "+assignment3); System.out.println("The mark for practical is "+practical); System.out.println("The mark for exam is "+exam); System.out.printf("The overallmark is %.2f\n",overallmark); System.out.println("The grade is "+grade); } public int getAssignemnt1() { return assignment1; } public void setAssignemnt1(int assignemnt1) { this.assignment1 = assignemnt1; } public int getAssignment2() { return assignment2; } public void setAssignment2(int assignment2) { this.assignment2 = assignment2; } public int getAssignment3() { return assignment3; } public void setAssignment3(int assignment3) { this.assignment3 = assignment3; } public int getPractical() { return practical; } public void setPractical(int practical) { this.practical = practical; } public int getExam() { return exam; } public void setExam(int exam) { this.exam = exam; } } import java.util.*; /** * Author: Tan Jun Qi * Student ID: 33872846 * Unit: ICT 167 Principles of computer Science * Lecturer: Aaron Yeo */ public class Student { String title; String firstname; String lastname; long stuID; int year; int month; int day; String grade; String type; public Student (String type, String title,String firstname, String lastname,long stuID,int day, int month, int year) { // Constructor used to create student object this.title = title; this.firstname = firstname; this.lastname = lastname; this.stuID = stuID; this.year = year; this.month=month; this.day=day; this.type = type; } public Student() { } public String getType() { return type; } public void Overallmark() // it would polymorph into either Undergrad or student if its empty { } public void grade(double overallmark) { // assignning grade t0 parameter overallmark if(overallmark>=80) { grade = "HD"; } else if(overallmark>=70) { grade = "D"; } else if(overallmark>=60) { grade = "C"; } else if (overallmark>=50) { grade = "P"; } else if (overallmark<50) { grade = "N"; } } public boolean equals(Student s1, Student s2) { boolean equals = false; if(s1.getStuID()==s2.getStuID()) { equals = true; } return equals; } public void sort(ArrayList stu) { boolean swap = true; while(swap) { swap = false; for(int i =1;i Ustu = new ArrayList(); // create arraylist of student object // Reading the file to the arraylist try{ String fileName = "student.txt"; File file = new File(fileName); // create a new file Scanner inputstream = new Scanner(file);// ready to read from the new created file while(inputstream.hasNextLine())//whille there is next line of records { String line = inputstream.nextLine(); // read the line of record String [] linearray = line.split(","); // Store the individual data from file seperated by commas. String status = linearray[0]; // Determining if the student is recorded as post or under. String title = linearray[1]; String firstname = linearray[2]; String lastname = linearray[3]; long Stuid = Long.parseLong(linearray[4]); int day = Integer.parseInt(linearray[5]); int month = Integer.parseInt(linearray[6]); int year = Integer.parseInt(linearray[7]); if(status.equals("Under")) { int ass1 = Integer.parseInt(linearray[8]); int ass2 = Integer.parseInt(linearray[9]); int ass3 = Integer.parseInt(linearray[10]); int prac = Integer.parseInt(linearray[11]); int exam = Integer.parseInt(linearray[12]); Ustu.add (new UndergradeStudent(status,title,firstname,lastname,Stuid,day,month, year,ass1,ass2,ass3,prac,exam)); // creating object undergradestudent with the constructor and store in arraylist undercount++; } else if(status.equals("Graduate")) { int assignment = Integer.parseInt(linearray[8]); int presentation = Integer.parseInt(linearray[9]); int exam = Integer.parseInt(linearray[10]); Ustu.add(new Postgraduate(status,title,firstname,lastname,Stuid,day,month ,year,assignment,presentation,exam)); // creating object postgraduate and store in arraylist postcount++; } } } catch (FileNotFoundException e) // if file cannot be found { System.out.println("File not found"); } while(addchoice!=1) { System.out.println(""); Menu(); // show the menu from the method addchoice=read.nextInt(); // prompt for the method choice read.nextLine(); // cleaning the scanner switch(addchoice) { case 1: { System.out.println("-----------Exit system--------/"); break; } case 2: { Addstudent(addchoice,choice,Ustu); // call from method to add student manually or from file break; } case 3: { for(Student s: Ustu) { // loop all student in arraylist s.print(); // print all object in arraylist System.out.println(""); } break; } case 4: { double sum=0; double sum1=0; double avg=0; double avg1=0; int ucount=0; int gcount=0; for(int i = 0;i=Uavg) { // if less than total overall marks Ucount++; // count student } } else if(Ustu.get(i) instanceof Postgraduate) { track = Ustu.get(i).getOverallmark(); if(track>=Pavg) { Pcount++; } } } System.out.println("The number of undergraduate student that has more than the overallmark is " +Ucount+ "and Postgraduate is "+Pcount); break; } case 6: { boolean found = false; System.out.println("Please enter the student ID to search"); long search = read.nextLong(); for(int i = 0;i stu) { Scanner read = new Scanner(System.in); System.out.println("Do you want to read from another file (yes or no)"); String addchoice = read.nextLine(); if(addchoice.equalsIgnoreCase("yes")) { System.out.println("please enter the file name to enter"); String filename = read.nextLine(); File file1 = new File(filename); try{ Scanner inputstream = new Scanner(file1); while(inputstream.hasNextLine()) { String line = inputstream.nextLine(); // read the line of record String [] linearray = line.split(","); // Store the individual data from file seperated by commas. String status = linearray[0]; // Determining if the student is recorded as post or under. String title = linearray[1]; String firstname = linearray[2]; String lastname = linearray[3]; long Stuid = Long.parseLong(linearray[4]); int day = Integer.parseInt(linearray[5]); int month = Integer.parseInt(linearray[6]); int year = Integer.parseInt(linearray[7]); if(status.equals("Under")) { int ass1 = Integer.parseInt(linearray[8]); int ass2 = Integer.parseInt(linearray[9]); int ass3 = Integer.parseInt(linearray[10]); int prac = Integer.parseInt(linearray[11]); int exam = Integer.parseInt(linearray[12]); stu.add (new UndergradeStudent(status,title,firstname,lastname,Stuid,day,month, year,ass1,ass2,ass3,prac,exam)); } else if(status.equals("Graduate")) { int assignment = Integer.parseInt(linearray[8]); int presentation = Integer.parseInt(linearray[9]); int exam = Integer.parseInt(linearray[10]); stu.add(new Postgraduate(status,title,firstname,lastname,Stuid,day,month ,year,assignment,presentation,exam)); } } System.out.println(""); System.out.println("Record added successfully"); } catch(FileNotFoundException e) { System.out.println("file not found"); System.exit(0); } } System.out.println("Do you want to manually add student? (yes or no)"); String mchoice = read.nextLine(); if(mchoice.equalsIgnoreCase("yes")&&choice==2 && type ==1) { System.out.println("Enter how many undergrad students do you want to add?"); int num = read.nextInt(); int count = 1; read.nextLine(); while(count<=num) { String status = "Under"; System.out.println("Please enter the Salutation for the new undergrad student"); String title = read.nextLine(); System.out.println("Please enter the firstname of the undergrad student"); String first = read.nextLine(); System.out.println("Please enter the lastname of the undergrad student"); String last = read.nextLine(); System.out.println("Please enter the student ID"); long ID = read.nextLong(); read.nextLine(); System.out.println("Please enter the day of birth"); int day = read.nextInt(); read.nextLine(); System.out.println("Please enter the month of birth"); int month = read.nextInt(); read.nextLine(); System.out.println("Please enter the year of birth"); int year = read.nextInt(); read.nextLine(); System.out.println("Please enter the mark for assignment1"); int ass1 = read.nextInt(); read.nextLine(); System.out.println("please enter the mark for assignment2"); int ass2 = read.nextInt(); read.nextLine(); System.out.println("Please enter the mark for assignment2"); int ass3 = read.nextInt(); read.nextLine(); System.out.println("please enter the mark for practical"); int prac = read.nextInt(); read.nextLine(); System.out.println("Please enter the mark for exam"); int exam = read.nextInt(); read.nextLine(); stu.add(new UndergradeStudent(status,title,first,last,ID,day,month,year,ass1,ass2,ass3,prac,exam)); count++; } } else if (mchoice.equalsIgnoreCase("yes")&&choice==2 && type ==2) { System.out.println("How many post graduate students do you want to enter?"); int num2 = read.nextInt(); int count2 = 1; String status = "Graduate"; while(count2<=num2) { System.out.println("Please enter the Salutation for the new postgraduate student"); String title = read.nextLine(); System.out.println("Please enter the firstname of the postgraduate student"); String first = read.nextLine(); System.out.println("Please enter the lastname of the postgraduate student"); String last = read.nextLine(); System.out.println("Please enter the student ID"); long ID = read.nextLong(); read.nextLine(); System.out.println("Please enter the day of birth"); int day = read.nextInt(); read.nextLine(); System.out.println("Please enter the month of birth"); int month = read.nextInt(); read.nextLine(); System.out.println("Please enter the year of birth"); int year = read.nextInt(); read.nextLine(); System.out.println("Please enter the mark for group assignment"); int groupass = read.nextInt(); read.nextLine(); System.out.println("please enter the mark for group presentation"); int grouppre = read.nextInt(); read.nextLine(); System.out.println("Please enter the mark for exam"); int exam = read.nextInt(); stu.add(new Postgraduate(status,title,first,last,ID,day,month,year,groupass,grouppre,exam)); count2++; } } } }