/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication3; /** * * @author pensyarah */ public class Student { private String fName; private String lName; private String matricNo; private int age; private double GPA; private static int countNoOfStudent = 0; public static int getCountNoOfStudent() { return countNoOfStudent; } public Student() { age = 20; countNoOfStudent++; } public Student (String fName , String l, String m, int a) { this.fName = fName ; lName= l; matricNo= m; age = a; countNoOfStudent++; } public Student (String f, String l, String m) { //fName = f; //lName= l; //matricNo= m; //this(); this(f, l, m, 20); } //setter methods public void setFName(String f) { fName = f; } public void setLName(String l) { lName= l; } public void setMatricNo(String m) { matricNo= m; } public void setAge(int a) { if (a < 0) System.out.println("Invalid age"); else age= a; } public void setGPA(double g) { GPA= g; } //getter methods public String getFName() { return fName; } public String getLName() { return lName; } public String getMatricNo() { return matricNo; } public int getAge() { return age; } public double getGPA() { return GPA; } public double calculateGPA() { //put the formula here return 0.0; } public void displayAllInfor() { System.out.println("First Name" + fName + " "); System.out.println("Last Name" + lName + " "); System.out.println("Matric Number" + matricNo + " "); System.out.println("Age" + age + " "); System.out.println("GPA" + GPA + " "); } public String toString() { String str = ""; str += "First Name: " + fName + "\n"; str += "Last Name: " + lName + "\n"; str += "Matric Number: " + matricNo + "\n"; str += "Age: " + age + "\n"; str += "GPA: " + GPA + "\n"; return str; } }