In the Exercises in Chapter 7, you designed a class named House that holds the s
ID: 3635493 • Letter: I
Question
In the Exercises in Chapter 7, you designed a class named House that holds the street address, asking price, number of bedrooms, and number of baths in a house. Design a class named SoldHouse that descends from House and includes fields that hold the selling price and the ration of the selling price to the asking price. The SoldHouse class contains a method that sets the selling price and computes the ration by dividing the selling price by the asking price. The class also contains methods to get the selling price and the ratio.Explanation / Answer
Hope this helps, please rate! //house class public class House { public int askingPrice; public String streetAddress; public int numBedrooms; public int numBaths; public House(){ } public int getAskingPrice() { return askingPrice; } public void setAskingPrice(int askingPrice) { this.askingPrice = askingPrice; } public String getStreetAddress() { return streetAddress; } public void setStreetAddress(String address) { this.streetAddress = address; } public int getNumBedrooms() { return numBedrooms; } public void setNumBedrooms(int bedrooms) { this.numBedrooms = bedrooms; } public int getNumBaths() { return numBaths; } public void setNumBaths(int baths) { this.numBaths = baths; } } //soldHouse class import java.util.Scanner; public class soldHouse { public int sellingPrice; public Double ratio; public void setSellingPrice(int price){ this.sellingPrice = price; } public void calculateRatio(int askingPrice){ ratio = (double) (sellingPrice/askingPrice); } public double getRatio(){ return ratio; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); House house = new House(); System.out.print("Enter the adress for the house: "); house.setStreetAddress(sc.nextLine()); System.out.print("Enter the asking price for the house: "); house.setAskingPrice(sc.nextInt()); System.out.print("Enter the number of bedrooms: "); house.setNumBedrooms(sc.nextInt()); System.out.print("Enter the number of baths: "); house.setNumBaths(sc.nextInt()); System.out.println("The add for the house is: "); System.out.println(house.getStreetAddress()); System.out.println(house.getNumBedrooms()+" bedroom, "+house.getNumBaths()+" bath"); System.out.println("Asking price: " + house.getAskingPrice()); } }