Assignment #4

This is an inclass and out of class assignment. It will be graded in stages.

Part 1:
Due: Monday March 5 at the start of class!! Nothing to hand in, we will check your program at the start of class.

Part 2:
Due Monday March 12 at the start of class. You must hand in the file Student.java and you should be prepared to demo your program with
the code provided below.

So what has changed from part 1?
    you need to add the following methods:
    public boolean equals(Student otherStudent) - this method should return true if ID, firstName, lastName are the same and the two gpa's differ by no more than 0.0001.
    public int compareTo(Student otherStudent) - this method should return a negative integer if this.ID is less than otherStudent.ID, zero if this.ID is equal to otherStudent.ID and a positive integer if this.ID is greater than otherStudent.ID.
    public String toString() - when outputting a variable of type student, it should appear similar to:
                First Name: JOHN      Last Name: SMITH       ID: 21354       GPA: 3.7
    2 constructors:
    - a zero parameter constructor :  public Student ( ) - this sets ID to minus 1, lastName and firstName to "Not Given" and gpa to 0.0
    - a 4 parameter constructor : public Student(int xID, String xFirstName, String xLastName, double xgpa) that assigns the respective instance elements

You must test your class with the following:

public class TryStudent
{
    public static void main(String [] args)
    {
        Student s1=new Student();
        Student s2=new Student(13245, "john","smith",3.3);
        Student s3=new Student(13245, "john","smith",3.3);
        Student s4=new Student(10000, "jane" , "davis", 3.5);
        Student s5=new Student (33333, "sue", "adams",3.6);

        System.out.println(s1);

        if (s2.equals(s3))
            System.out.println( s2+" is equals to "+s3);
        else
             System.out.println(s2+ " is not equals to "+s3);

        if (s2.equals(s4))
            System.out.println( s2+" is equals to "+s4);
        else
             System.out.println(s2+ " is not equals to "+s4);

        if (  (s3.compareTo(s4)<=0)  &&  (s3.compareTo(s5)<=0)   )
            System.out.println("s3 is the smallest");
        else if (  (s4.compareTo(s3)<=0)  &&  (s4.compareTo(s5)<=0)  )
            System.out.println("s4 is the smallest");
        else
            System.out.println("s5 is the smallest");
    }
}

// END of additions for part 2
-----------------------------------------------------------

What to do:
    Define a class called Student. Student should contain the following instance data:
            int ID
            String firstName
            String lastName
            double gpa

    All instance data should be declared private. The following methods should also be defined:
            - 4 getter methods (getID,getfirstName, getlastName, get gpa)
            - 4 setter methods
            a method called setStudent that accepts 4 parameters to initialize all instance data
            a method called writeOutput to write out an entire student

You should write a driver program called UseStudent:

    public class UseStudent
    {
        public static void main(String [ ] args)
        {
            Student s1=new Student( );
            Student s2=new Student( );

            s1.setStudent(12354 , "Joe",  "Smith" , 3.6   );
            s2.setStudent(21365,  "Mary",  "Jones" , 3.85);

            s1.writeOutput( );      <----- should output     ID: 12354     Last Name: Smith     First Name: Joe        GPA: 3.60
            s2.writeOutput( );      <----- should output     ID:  21365    Last Name: Jones     First Name: Mary     GPA: 3.85

    }

You will receive full credit if your output matches the sample above and no credit otherwise.