Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

CS152 Project 2 Recursion on Array of Objects Use BlueJ to write a program that reads a list of data for several houses from the

CS152 Project 2

Recursion on Array of Objects

Use BlueJ to write a program that reads a list of data for several houses from the same complex, all located on the same street, from an input file. Houses are stored in an array House[] houseList . Capacity of the list is 70. Actual number of houses in the list depends on the input file. Program should work for input file containing info for any number of houses. Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program are located.

Class House describes one house object and has variables: int houseNumber, int bedrooms (number of bedrooms), int sqFeet, int year (when house was built), and int cost (given in thousands of dollars). Define Houses constructor to accept and initialize all instance variables. Include getter methods only for instance variables needed outside of class House, such as getCost, sqFeet... Provide a toString method that returns one line description of a house as String. Provide method isExpensive() that returns a boolean indicating if the house is expensive or not. Expensive means that house cost is above 300 thousand dollars. Provide method isNew() that returns a boolean indicating if the house is new or not. New house means that house was built in 2015 or more recently.

Class HouseComplex describes funtionality for list of house objects built on the same street. Class will have no instance variables and no constructor. In each method input parameter n is number of occupied positions in the list. Class will only have the following recursive methods:

  • public String toString(House[] list, int n)

//returns String of all houses in the list

  • public void printNewHouses(House[] list, int n)

//prints all new cars in the list

  • public int countExpensive(House[] list, int n)

//returns number of expensive houses in the list

  • public House cheapestHouse(House[] list, int n)

//returns the cheapest house in the list.

  • public ArrayList moderateSize (House[] list, int n)

// returns ArrayList of houses that have

// between 1500 and 2500 square feet (including

// the limits ) EXTRA CREDIT

Only method printNewHouses prints all new houses, all other methods do not print anything. They only return result of specified data type. All methods that return or print several houses should do it by keeping the same relative order of houses as they appear in the original list. (Do not reverse the order.)

Use input file which you will create in notepad. Each line of input file "inData.txt" has houseNumber,bedrooms, sqFeet, year, and cost in that order, and separated by a space. The data for the first two and last two houses in the input file should be as follows:

1 3 1790 2017 310

4 2 1480 2004 280

add additional three rows of house data of your choice .

15 4 2800 1998 320

88 5 4020 2019 460

Class Tester will have main method. In it, read houses from the input file and store them in House[] myHouses. Also count houses as you read from the input file in variable int houseCount. Invoke each of the methods (plus extra credit if you have done it) from HouseComplex class.

Do not forget to append throws IOException to the main method header in class Tester. In addition, you have to provide

import java.io.*;

import java.util.*;

in order to input data from input file and use Scanner class.

SUBMIT a single word or PDF document named p2_yourLastName_CS152 with the following:

  • Your name, class section and project number and date of submission in the upper left corner
  • Copy of the code for each class in separate rectangle
  • Copy of your input file
  • Picture of program run from BlueJ.
  • UML diagram.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions