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

A class of Students was previously defined with the following properties: a stri

ID: 3813388 • Letter: A

Question

A class of Students was previously defined with the following properties: a string name, an integer age, a Boolean variable indicating whether or not the student is an IT major, and a character gender. 2 constructors were also defined: one default constructor and one constructor that takes the name, age, major, and gender to set the data fields. The instance methods were also defined, including the getters and setters. Two instances of the student class were also created; one with set values, and the other taking data from the user. For this activity, you will: Create an instance method called displayInfo(), that will use the getters and setters to print the instance data. Create a running class in which you’ll paste the 2 instances of student class created in the previous activity, then call the displayInfo() method to print the data for each instance. This must be finished in Java: See code to add to below:

import java.time.LocalDate;

class Student
{
     private String name;
     private int age;
     private Boolean IT_major;
     private char gender;
     public static int num; //static variable for number of students
   
     public Student()   //default constructor
     {
         name = "Jon Doe";
         age = 0;
         IT_major = false;
         gender = 'u0000';
         num++;
     }
    public Student(String name,char gender) //parameterized constructor
     {
         this.name = name;
       
       
         this.gender = gender ;
         num++;
       
     }
     public void setAge(int Birth_year,int Current_year) //set age by sending birth year and current year
     {
         age = Current_year - Birth_year;
       
       
     }
     public int getAge()
     {
         return age;
     }
     public void setIT_Major(String major)
     {
        IT_major = Is_IT_major(major); //call Is_IT_major()
     }
     public boolean Is_IT_major(String major) //check if student is IT_major
     {
         if(major.equalsIgnoreCase("IT")|| major.equalsIgnoreCase("Information Technology"))
         return true;
         else
         return false;
     }
     public Boolean getIT_major()
     {
         return IT_major;
     }
     public String toString() //override toString()
     {
       
         return " Student Details:   Name :"+name+" Age : "+ getAge()+ " gender : "+gender +" Is IT Major : "+getIT_major();
     }
  
}
class Test
{
   public static void main (String[] args)
   {
   LocalDate d = LocalDate.of(2017, 04, 07); // LocalDate object
       
       int Current_year = d.getYear();
     
       Student s = new Student("Christina Lewis",'f');
       s.setIT_Major("It");
       s.setAge(2000,Current_year);
     
       System.out.println(s.toString());
       System.out.println("Number of students :"+s.num);

   }
}

Explanation / Answer

HI, Please find my implementation.

Please let me know in case of any issue.

###################################################

public class Student

{

   private String name;

   private int age;

   private Boolean IT_major;

   private char gender;

   public static int num; //static variable for number of students

   public Student() //default constructor

   {

       name = "Jon Doe";

       age = 0;

       IT_major = false;

       gender = 'u0000';

       num++;

   }

   public Student(String name,char gender) //parameterized constructor

   {

       this.name = name;

       this.gender = gender ;

       num++;

   }

   public void setAge(int Birth_year,int Current_year) //set age by sending birth year and current year

   {

       age = Current_year - Birth_year;

   }

   public int getAge()

   {

       return age;

   }

   public void setIT_Major(String major)

   {

       IT_major = Is_IT_major(major); //call Is_IT_major()

   }

   public boolean Is_IT_major(String major) //check if student is IT_major

   {

       if(major.equalsIgnoreCase("IT")|| major.equalsIgnoreCase("Information Technology"))

           return true;

       else

           return false;

   }

   public Boolean getIT_major()

   {

       return IT_major;

   }

  

   public String getName(){

       return name;

   }

  

   public char getGender(){

       return gender;

   }

   public String toString() //override toString()

   {

       return " Student Details: Name :"+name+" Age : "+ getAge()+ " gender : "+gender +" Is IT Major : "+getIT_major();

   }

  

   public void displayInfo(){

       System.out.println("Name: "+getName());

       System.out.println("Age: "+getAge());

       System.out.println("Gender: "+getGender());

       System.out.println("Is It Major: "+getIT_major());

   }

}

##############################################################

import java.time.LocalDate;

public class Test

{

   public static void main (String[] args)

   {

       LocalDate d = LocalDate.of(2017, 04, 07); // LocalDate object

       int Current_year = d.getYear();

       Student s = new Student("Christina Lewis",'f');

       s.setIT_Major("It");

       s.setAge(2000,Current_year);

       s.displayInfo();

       System.out.println("Number of students :"+s.num);

      

       System.out.println();

       Student s1 = new Student("Alex Bob",'m');

       s1.setIT_Major("It");

       s1.setAge(2000,Current_year);

       s1.displayInfo();

       System.out.println("Number of students :"+s.num);

   }

}

/*

Sample run:

Name: Christina Lewis

Age: 17

Gender: f

Is It Major: true

Number of students :1

Name: Alex Bob

Age: 17

Gender: m

Is It Major: true

Number of students :2

*/

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