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 - Java Tutorial
From the course: Learning Java 11
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Classes in Java4m 55s
-
(Locked)
Constructors in Java6m 50s
-
(Locked)
Creating a class in Java3m 57s
-
(Locked)
Creating instances in Java4m 57s
-
(Locked)
Instance methods vs. class methods2m 52s
-
(Locked)
Using instance methods in Java2m 47s
-
(Locked)
Instance and class variables in Java3m 56s
-
(Locked)
Review: Classes vs. instances1m 57s
-
(Locked)
Challenge: Student profile2m 1s
-
(Locked)
Sample solution: Student profile3m 26s
-
(Locked)
-