Question
Using Java Define a class of Students with the following properties and actions: a string name, an integer age, a Boolean variable indicating whether or
Using Java 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 students 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 students name and gender are set to the values provided.
To set the Boolean value, we use a support method that takes the students 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)
Create a TestStudent class in which youll create instances:
Create a student instance with default values Repeatedly asks the user for the students name, birthyear, gender, and major, until the user enters DONE to indicate no more student to enter For each student entered, create an instance of the Student class. Print the total number of Students in the class Call the toString() method to print the data for each instance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started