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

Define a class of Students with the following properties and actions: a string n

ID: 3812738 • Letter: D

Question

Define a class of Students with the following properties and actions: a string name, an integer age, a Boolean variable indicating whether or not the student is an IT major, a character gender, and an integer that tracks the number of students.

The default value for name is “Jon Doe”, for age is 0, for the Boolean variable is false, and for the gender is ‘u0000’.

To compute the student’s age, the year of birth and the current year must be used. The year of birth is provided as parameter. The current year is a class variable obtained thru an instance of LocalDate.

The student’s name and gender are set to the values provided.

To set the Boolean value, we use a support method that takes the student’s major and return true if the major is “IT”, and false otherwise. The setter for this data field must call the support method. Note that the parameter provided could be any case-variation of “IT” (e.g. “it”, “It”, “iT”), or any case-variation of “Information Technology”.

Create an instance method called toString(), that will use the getters and setters to create a String of the instance data (Note that this is similar to the displayInfo() method, except that the data is not printed)

Explanation / Answer

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);

   }
}


Output:

Student Details:                                                                                                                                       

Name :Christina Lewis                                                                                                                                  

Age : 17                                                                                                                                               

gender : f                                                                                                                                             

Is IT Major : true                                                                                                                                     

Number of students :1

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