i wan the code in java program: 1- class House a- a deafault constructor which s
ID: 3702789 • Letter: I
Question
i wan the code in java program:
1- class House
a- a deafault constructor which set the numberOfLog to a default value and also call the inherited class's default constructor.
b- a parameterized constructor which takes in parameter corresponding to the inherited class's instance variables, along with numbers of logs. it should make sure to set the value of the instance variable for both the inherited class and this class, and also check for valid values.
c- override the method printInfo. this should call the inherited class's printInfo along with also printing the number of logs.
2- using the following code and the class house created in question one; write a method return the house with the highest number of square feet given a specific number of rooms. the method should return a house and take in the number of rooms via parameters. if there is no house has that exact number of rooms then, the method should return null. also, before calling on any individual houses in the array of house, make sure it has been constructed.
3- using the following code and the class house created in the previous question; write a method that prints the information for all house's strictly over a given number of square feet. this method will return nothing, take in the number of square feet via parameters, and must check the values in instance variable houses. also before calling method on any individual in the array, make sure it has been constructed.
Explanation / Answer
class House{ //definition of class House starts here
public:
int numberOfLog; // member data is declared
House (){ // default constructor
super(); // calling default constructor of base class
numberOfLog=0; // initialization
}
House(int x, int y, int n){// parameterized constructor
super( x,y); // invoking base class parameterized constructor
numberOfLog= n; // sets instance variable
}
void printInfo(){ // definition of method starts here. Overriding
super.printInfo(); // invoking base class method
System.out.println("number of logs=" + n); displays instance variable's value
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.