Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java, give a complete definition of a class called OCCStudent that has the fo

ID: 3863225 • Letter: I

Question

In Java, give a complete definition of a class called OCCStudent that has the following fields (aka: instance variables):

fullName

userName

cNumber

gPA

age

Include accessor methods for each instance variable and mutator methods for each (except C-number).

Add methods for the OCCStudent to

Create a new OCCStudent (constructor method)

Test whether two OCCStudent objects are equal (have the same full name, user name, C-number, age and GPA)

Tests whether two OCCStudent objects have the same name

Tests whether two OCCStudent objects are the same age

Tests whether one OCCStudent object is older than another

Tests whether one OCCStudent object is younger than another

Write a driver (test) program, which is another Java class in the same project, to demonstrates each method, with at least one true and one false case for each of the methods tested. Please name the driver (OCCStudentDemo).

OCC Student Class E Fields ea age a Number e a fullName gPA. userName El Methods equals getAge getCNumber getFull Name getGPA. getUser Name solder issameAge sYounger OCC Student setAge setFullName setGPA setuserName ToString

Explanation / Answer

OCCStudent.java

public class OCCStudent {
   //Declaring instance variables
   private String fullName;
   private String userName;
   private int cNumber;
   private double gPA;
   private int age;
  
   //Parameterized constructor
   public OCCStudent(String fullName, String userName, int cNumber,
           double gPA, int age) {
       super();
       this.fullName = fullName;
       this.userName = userName;
       this.cNumber = cNumber;
       this.gPA = gPA;
       this.age = age;
   }
  
   //getters and setters
   public String getFullName() {
       return fullName;
   }
   public void setFullName(String fullName) {
       this.fullName = fullName;
   }
   public String getUserName() {
       return userName;
   }
   public void setUserName(String userName) {
       this.userName = userName;
   }
   public int getcNumber() {
       return cNumber;
   }
   public void setcNumber(int cNumber) {
       this.cNumber = cNumber;
   }
   public double getgPA() {
       return gPA;
   }
   public void setgPA(double gPA) {
       this.gPA = gPA;
   }
   public int getAge() {
       return age;
   }
   public void setAge(int age) {
       this.age = age;
   }
   public boolean isOlder(OCCStudent stud)
   {
       if(this.age<stud.getAge())
           return false;
       else
           return true;
         
   }
     
   //Checking whether two students ages are sane or not
   public boolean isSameAge(OCCStudent stud)
   {
       if(this.age==stud.getAge())
           return true;
       else
           return false;
         
   }
     
   public boolean isYounger(OCCStudent stud)
   {
       if(this.age<stud.getAge())
           return true;
       else
           return false;
            
   }
   //Checking whether two students Objects are sane or not
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       OCCStudent other = (OCCStudent) obj;
       if (age != other.age)
           return false;
       if (cNumber != other.cNumber)
           return false;
       if (fullName == null) {
           if (other.fullName != null)
               return false;
       } else if (!fullName.equals(other.fullName))
           return false;
       if (Double.doubleToLongBits(gPA) != Double.doubleToLongBits(other.gPA))
           return false;
       if (userName == null) {
           if (other.userName != null)
               return false;
       } else if (!userName.equals(other.userName))
           return false;
       return true;
   }
  
   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return "fullName=" + fullName + ", userName=" + userName
               + ", cNumber=" + cNumber + ", gPA=" + gPA + ", age=" + age;
   }

}

_________________

OCCStudentDemo.java

public class OCCStudentDemo {

   public static void main(String[] args) {
       //Creating Student1 Object by passing values as arguments
OCCStudent stud1=new OCCStudent("Kane Willaims", "Williams", 1234, 4.5,29);
//Displaying the Student 1 Object info
System.out.println("Student 1 Info# "+stud1.toString());
       //Creating Student2 Object by passing values as arguments
OCCStudent stud2=new OCCStudent("Ricky Pointing", "Ricky", 2345, 4.0,25);
//Displaying the Student 2 Object info
System.out.println("Student 2 Info# "+stud2.toString());
       //Creating Student3 Object by passing values as arguments
OCCStudent stud3=new OCCStudent("Jonty Rodes", "Micky", 1111, 3.5,27);
//Displaying the Student 3 Object info
System.out.println("Student 3 Info# "+stud3.toString());
       //Creating Student4 Object by passing values as arguments
OCCStudent stud4=new OCCStudent("Kane Willaims", "Williams", 1234, 4.5,29);
//Displaying the Student 4 Object info
System.out.println("Student 4 Info# "+stud4.toString());
       //Creating Student5 Object by passing values as arguments
OCCStudent stud5=new OCCStudent("Sachin Tendulkar", "Sachin", 5555, 5.0,29);
//Displaying the Student 5 Object info
System.out.println("Student 5 Info# "+stud5.toString());
  
//Comparing student1 and Student 4 Objects
if(stud1.equals(stud4))
System.out.println("Student 1 and Student 2 are same");
else
System.out.println("Student 1 and Student 2 are not same");

//checking student1 is older than Student2 or not
if(stud1.isOlder(stud2))
System.out.println("Student 1 is older than Student 2");    
else
   System.out.println("Student 1 is not older than Student 2 ");

//checking student2 is older than Student3 or not
if(stud2.isYounger(stud3))
System.out.println("Student 2 is younger than Student 3");    
else
   System.out.println("Student 2 is not younger than Student 3");

//checking student4 has same age as Student5 or not
if(stud4.isSameAge(stud5))
System.out.println("Student 4 has same age as Student 5");    
else
   System.out.println("Student 4 has not same age as Student 5");
  
   }

}

____________________

Output:

Student 1 Info#
fullName=Kane Willaims, userName=Williams, cNumber=1234, gPA=4.5, age=29
Student 2 Info#
fullName=Ricky Pointing, userName=Ricky, cNumber=2345, gPA=4.0, age=25
Student 3 Info#
fullName=Jonty Rodes, userName=Micky, cNumber=1111, gPA=3.5, age=27
Student 4 Info#
fullName=Kane Willaims, userName=Williams, cNumber=1234, gPA=4.5, age=29
Student 5 Info#
fullName=Sachin Tendulkar, userName=Sachin, cNumber=5555, gPA=5.0, age=29
Student 1 and Student 2 are same
Student 1 is older than Student 2
Student 2 is younger than Student 3
Student 4 has same age as Student 5

________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote