dt Format View Help sing the question started in the last class, create he follo
ID: 3739754 • Letter: D
Question
dt Format View Help sing the question started in the last class, create he following functions function that takes in two houses and returns true if he style and price of the houses are the same and false therwise function that takes in an array containing several ouses and outputs the name of the most expensive house function that takes in an array containing several houses aximum number of bathrooms that is contained in any of the houses function that takes allows the user to enter in the details of a house nto the current list of houses.Explanation / Answer
Since you have not provided the language of your preference, I am providing the code in Java.
Please find the code for all the definitions below.
CODE
====================
public boolean areSameHouse(House h1, House h2){
return h1.style == h2.style && h1.price == h2.price ? true : false;
}
public void findExpensiveHouse(House houses[]) {
String expensiveHouseName = houses[0].name;
int maxPrice = houses[0].price;
for(int i=1; i<houses.length; i++) {
if(houses[i].price > maxPrice) {
maxPrice = houses[i].price;
expensiveHouseName = houses[i].name;
}
}
System.out.println("Most expensive house's name is " + expensiveHouseName);
}
public int findMaximumBathrooms(House houses[]) {
int bathrooms = houses[0].bathrooms;
for(int i=1; i<houses.length; i++) {
if(houses[i].bathrooms > bathrooms) {
bathrooms = houses[i].bathrooms;
}
}
return bathrooms;
}
public void addHouse() {
String name, style;
double price;
int bathrooms;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the house details: ");
System.out.print("Name: ");
name = sc.next();
System.out.print("Style: ");
style = sc.next();
System.out.print("Price: ");
price = sc.nextDouble();
System.out.print("Number of bathrooms: ");
bathrooms = sc.next();
houses[number ++] = new House(name, style, price, bathrooms);
}
*****NOTE: To get more precise code, you need to provide me the existing implementation of the House class. Based on the code only, I can help you to provide more exact code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.