Question: Getting Started Create a new project in Eclipse, following the lab guidelines. Create the following new Java classes, in the default package: ( Use these
Getting Started
Create a new project in Eclipse, following the lab guidelines. Create the following new Java classes, in the default package: (Use these names exactly!)
House.java
School.java
Student.java
School.java
Place the following code as the main method in School.java
public static void main( String[] args ) {
School hogwarts = new School( "Hogwarts School of Witchcraft and Wizardry" ); House gryffindor = new House( "Gryffindor", "RED" ); House slytherin = new House( "Slytherin", "GREEN" ); House hufflepuff = new House( "Hufflepuff", "YELLOW" ); House ravenclaw = new House( "Ravenclaw", "BLUE" ); Student harryPotter = new Student( "Harry Potter", 2 ); Student ronaldWeasley = new Student( "Ron Weasley", 2 ); Student dracoMalfoy = new Student( "Draco Malfoy", 2 ); Student lunaLovegood = new Student( "Luna Lovegood", 1 ); Student cedricDiggory = new Student( "Cedric Diggory", 3 ); gryffindor.addStudent( harryPotter ); gryffindor.addStudent( ronaldWeasley ); slytherin.addStudent( dracoMalfoy ); ravenclaw.addStudent( lunaLovegood ); hufflepuff.addStudent( cedricDiggory ); hogwarts.addHouse( gryffindor ); hogwarts.addHouse( slytherin ); hogwarts.addHouse( hufflepuff ); hogwarts.addHouse( ravenclaw ); System.out.println( hogwarts );
}
Now that School.java has a main method, it will be the class to run our application. Note that this code will not compile until you have coded its dependencies. Follow the remaining instructions for each class in this lab in order to get your code to compile - do not change the given main method.
School
This class will run our application. It will also represent a School object, which we will define as having:
A name, represented as a String
Four houses, stored as an array of House objects (i.e. House[])
A toString() method, which calls upon the toString() method in House.java to return as a String all needed information.
An addHouse(..) method, which takes as a paramter a House object and returns nothing.
This class must have a constructor and getters and setters to accommodate its variables.
House
This class will represent a House object, which we will define as having:
A name, represented as a String
A color, represented as a String
An array of Students, with a maximum capacity of 10.
A toString() method which returns a String representation of all Students in the House
For the sake of this lab, a house will have a maximum of 10 students. This class must have a constructor and getters and setters to accommodate its variables.
Student
This class will represent a Student object, which we will define as having:
A name, represented as a String
A year, represented as an integer (for example, a student in their first year would store the value 1).
A toString() method which returns a String representation of all Students in the House
This class must have a constructor and getters and setters to accommodate its variables.
As this lab is meant to review regular arrays in Java, no other data structure may be used to store the objects required. (No ArrayLists are permitted, for example).
Output
Once your code compiles, you will be able to examine the output of your program. The output of your program must match the format of the sample below. This sample is the result of running the School.java class with the given main method.
Hogwarts School of Witchcraft and Wizardry ------------------------------------------------------- Gryffindor (RED) - Harry Potter, Year 2 - Ron Weasley, Year 2 Slytherin (GREEN) - Draco Malfoy, Year 2 Hufflepuff (YELLOW) - Cedric Diggory, Year 3 Ravenclaw (BLUE) - Luna Lovegood, Year 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
