HNode.java Instructions: HNode.java - node containing a House object. (total of 120 points distributed as shown below)
Question:
HNode.java
Instructions:
HNode.java - node containing a House object. (total of 120 points distributed as shown below) Note that the method UML description is listed below and it should be implemented exactly as it is.
- +HNode( ) - constructor, takes no parameters. (20 points)
- +setNext(HNode n): void (20 points)
- +getNext( ): HNode (20 points)
- +setHouse(House h): void (20 points)
- +getHouse( ): House (20 points)
- +toString( ): String (20 points)
Code you may need !
--------------------------------------------------------------------------
RealEstate.java
import java.util.Scanner;
public class RealEstate { static int index=0; static House[] ArrHouse = new House[1000]; static Scanner sc=new Scanner(System.in); private static void printAllHouses() { for(House h: ArrHouse) { if(h!=null) { System.out.println(h.toString()); } else { break; } } }
private static void printHouse() { System.out.println("Enter maximum cost: "); double cost=sc.nextDouble(); for(House h:ArrHouse) { if(h!=null && h.getPrice()<=cost) { System.out.println(h.toString()); } } }
private static void removeHouse() { System.out.println("Enter mls: "); int mls=sc.nextInt(); for(int i=0;i
private static void addHouse() throws HouseException { House temp=new House(10001,0,0,"nnnn"); int m=0; while(true) { System.out.println("Enter mls: "); int mls=sc.nextInt(); for(House h:ArrHouse) { if(h!=null && h.getMls()==mls) { System.out.println("mls already exists....Enter again"); continue; } else { m=mls; break; } } try { temp.setMls(m); System.out.println("Enter no. of bedrooms: "); int b=sc.nextInt(); temp.setBedrooms(b); System.out.println("Enter price: "); double p=sc.nextDouble(); temp.setPrice(p); sc.nextLine(); System.out.println("Enter name of Seller: "); String s=sc.nextLine(); temp.setSeller(s); ArrHouse[index]=temp; System.out.println("House added"); index++; } catch(Exception HouseException) { System.out.println("wrong input"); continue; } break; } }
public static void main(String[] args) throws HouseException { while(true) { System.out.println(" Welcome to Real Estate Service Choose from the following options: 1. add a house " + "2. remove a house " + "3. print houses that cost less than a given price " + "4. print all the houses " + "0. end this program Enter choice: "); int choice=sc.nextInt(); if(choice==0) { System.out.println("Program ends"); break; } else if(choice==1) { sc.nextLine(); addHouse(); } else if(choice==2) { removeHouse(); } else if(choice==3) { printHouse(); } else if(choice==4) { printAllHouses(); } else { System.out.println("Wrong choice.....Enter again: "); continue; } } } }
--------------------------------------------------------------------------
house.java
class House{ private int mls; private int bedrooms; private double price; private String seller; public House(int mls, int bedrooms, double price, String seller) throws HouseException { setMls(mls); setBedrooms(bedrooms); setPrice(price); setSeller(seller); } //set method public void setMls(int mls) throws HouseException { if (mls >=10001 && mls<=99999) { this.mls=mls; } else{ HouseException me = new HouseException(); me.setMessage("Program terminated!! mls value should be between 10001 and 99999 "); throw(me); } } public void setBedrooms(int bedrooms) throws HouseException { if(bedrooms >= 0 && bedrooms < 6) { this.bedrooms= bedrooms; } else{ HouseException me = new HouseException(); me.setMessage("Program terminated!! bedroom value should be between 0 and 5 "); throw(me); } } public void setPrice(double price) throws HouseException { if(price>=0 && price<=1000000) { this.price=price; } else{ HouseException me = new HouseException(); me.setMessage("Program terminated!! Price value should be between 0 and 1000000 "); throw(me); } } public void setSeller(String seller) throws HouseException{ seller = seller.trim(); if (seller.length() >= 2){ //seller.substring(seller.length() - 2); this.seller=seller; } else{ HouseException me = new HouseException(); me.setMessage("Program terminated!! Seller name is WRONG"); throw(me); } }
// get method public int getMls() { return this.mls; } public int getBedrooms() { return this.bedrooms; } public double getPrice() { return this. price; } public String getSeller() { return this.seller; } // to String public String toString() { String temp = "Mls: " + mls+ " Bedrooms: " + bedrooms+ " Price: $" + String.format("%,.2f", price) + " Seller: " + seller; return temp; } }
--------------------------------------------------------------------------
HouseException.java
class HouseException extends Exception{ String message; public HouseException() { } public void setMessage(String message) { this.message = message; } public String getMessage() { return message; } }
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill