Question
In this java file, create a default class named Student. The Student class should have a static variable, numStudent, and five instance variables. 1 .
In this java file, create a default class named Student. The Student class should have a static variable, numStudent, and five instance variables.
1. Write the following variables: Static variable
numStudent: the number of the student objects that have been created, static, int, initial value = 0. Instance variables
name: the students full name, String, e.g., John Doe, must be specified when instantiated.
id: the students id, String, created based on numStudent, e.g., the first student objects id should be 1, the second student objects id should be 2.
major: the students major, String, must be specified when instantiated. Page | 2
gpa: the student's current gpa, double, initial value = 0.0.
username: String, each student is assigned an automatically generated username following the rules below:
Get the first letter of the students first name.
Get the first five letters of the students last name. If students last name is less than the required number of letters in length, then use the entire name.
Get the students id
. Concatenate the three sets of letters then convert to lower case to generate the login name.
2. Write the constructor.
3. Implement the Comparable interface. Student should be able to be compared by their gpa.
Test cases: Student s1 = new Student(John Doe, Computer Science); // id is 1, username is jdoe1 Student s2 = new Student(Emily Johnson, Cybersecurity); // id is 2, username is ejohns2 int result = s1.compareTo(s2);
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