-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy path2.2.7 New Student Field (Part 2)
38 lines (35 loc) · 1.13 KB
/
2.2.7 New Student Field (Part 2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class Student
{
private String firstName;
private String lastName;
private int gradeLevel;
private int numClubs;
// Add an instance variable called numClubs here.
/**
* This is a constructor. A constructor is a method
* that creates an object -- it creates an instance
* of the class. What that means is it takes the input
* parameters and sets the instance variables (or fields)
* to the proper values.
*
* Check out StudentTester.java for an example of how to use
* this constructor and how to add numClubs to the constructor.
*/
public Student(String fName, String lName, int grade, int iClubs)
{
firstName = fName;
lastName = lName;
gradeLevel = grade;
numClubs = iClubs;
}
/**
* This is a toString for the Student class. It returns a String
* representation of the object, which includes the fields
* in that object.
*/
public String toString()
{
return firstName + " " + lastName + " is in grade " + gradeLevel +
" and is in " + numClubs + " club(s).";
}
}