I am new to Java and relatively to programming. I have been working on this problem for a week and can't seem to get it. I am trying to create an object in a test class from a class that contains int type parameters and 1 array parameter in the constructor, getter and setter methods in the class from which the object is being created. I think the problem is when I am trying to pass the arguments into the parameters of the object but I am not sure.
Also, This is my first time using this site, let me know if I am suppose to format this text box differently. I read something about the code button for readability, I tried it but not sure if it worked?
// Constructor
public House(int numberOfFloors, int numberOfWindows, int bathrooms, int[] numberOfRooms) {
super(numberOfFloors, numberOfWindows);
numberOfBathrooms = bathrooms;
rooms = numberOfRooms;
}
// Accessor/Getter
public int[] getRooms() {
return rooms;
}
// Mutator/Setter
public void setRooms(int[] rooms){
this.rooms = rooms;
}
// toString
public String toString() {
String result;
result = "This House has " + numberOfBathrooms + " bathrooms, and "
+ rooms + " rooms. " + super.toString();
return result;
}
// Object
House myHouse = new House(2, 9, 3, new int[]{28, 45, 65, 23, 45});
System.out.println(myHouse);
// Output
// This House has 3 bathrooms, and [I@2a139a55 rooms.
Ryan