1.12 Homework
Homework
Scenario
Its your first day of class when Mr. Mortenson asks you to identify all the students and list some characteristics about them. Create a class to use as a template to create student objects and create 3 imaginary students.
Instructions
- Create a class
- Instance variables:
String nameint gradeint petsint siblingsMAKE YOUR OWN
- In
main:- Create three student objects.
//Code Here
class Students {
String name;
int grade;
int pets;
int siblings;
String hairColor;
public Student(String name, int grade, int pets, int siblings, String hairColor) {
this.name = name;
this.grade = grade;
this.pets = pets;
this.siblings = siblings;
this.hairColor = hairColor;
}
public void displayStudent() {
System.out.println(name);
System.out.println(grade);
System.out.println(pets);
System.out.println(siblings);
System.out.println(hairColor);
}
}
New Scenario
You find out that one of the students that you created an object for goes by a nickname. Using your knowledge of reference variables, create another object that references back to the same student.
Instructions
-
Use your previous code
-
In
main:- Create a reference variable with a different name that points to the same student.
- Output the instance attributes of this student
//Code Here