From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sample solution: Student profile

Sample solution: Student profile - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Sample solution: Student profile

(upbeat music) - [Instructor] Let's represent a student's profile in Java using a class. We'll create a new Java file and call it, student profile. In this class, we'll add our attributes. Each attribute or instance variable will have a data type. So we'll start with first name, which will be string. Gpa will be a double. And expected year to graduate will be an int. Next, we'll add our behavior or instance methods. The challenge said to add a function that increments the expected year to graduate instance variable. So we'll write public and then the name of the function, Increment expected graduation year. It will take no parameters. And for the return type, we could have it return the new expected year to graduate value or return nothing, returning void. In this case, we'll say void. In the implementation, we'll be setting the value of the instance variable expected year to graduate. To access this instance variable, we can use the keyword 'this' with the dot operator. For the…

Contents