Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Working with inheritance and polymorphism Defining, using and handling exceptions Using Javadoc comments Creating Javadoc html file Working with packages Provided files: HousingApplicationFXStart.java HousingUML.pdf

Objectives:

Working with inheritance and polymorphism Defining, using and handling exceptions Using Javadoc comments Creating Javadoc html file Working with packages

Provided files: HousingApplicationFXStart.java HousingUML.pdf PackagesIntro.pdf JavadocIntro.pdf

Lab Assignment description:

1. Use an inheritance to create three java classes that represent: a living space, an apartment and a house (see part 1 below for more information on the class attributes and methods).

2. Create an application or use the provided HousingApplicationFXStart.java application to create apartment and house objects and store them in the array of size is 5. In case the user wants to add more than 5 objects, your program should display an error message indicating that there is no room. In the application, you must use a try and catch statement to catch InvalidBathNumberException. If you are going to use the provided HousingApplicationFxStart file, see part 2 below for more information.

3. Create InvalidBathNumberException class. This class should be instantiated when a user tries to set the number of bathrooms to a value smaller than one. There is an example on page 60 in the textbook that shows how to write an exception class.

Part 1: LivingSpace, Apartment, House classes Write three classes: an abstract class LivingSpace and two concrete classes Apartment class and House class. Use the attached HousingUML.pdf to determine instance variables and instance methods for each class. The living space number of bathrooms must be at least one. Create and throw an exception when number of bathrooms is smaller than one. Method setBaths and the constructors should throw an InvalidBathNumberException when invalid number of bathrooms is provided.

2. Extend the LivingSpace class to create an Apartment class

3. Extend the LivingSpace class to create a House class.

4. Reuse method toString (use keyword super) from the parent class while overriding.

Part 2: Reading input from text fields The HousingApplicationFX class provides GUI components (text fields) for entering objects information. Modify the provided application and provide java instructions to stores the objects in the array and to displays the housing objects. JavaFX text field is an object that allows a user to enter a single line of text. The text fields are for entering housing information (address, number of bedrooms, etc.) TextField class provides getText() method that returns a string containing text entered into the text field To get the address from a text field use method getText: String address = nameTF.getText(); To get the integer value like number of bedrooms you must use a class method parseInt from the Integer class to convert the string to an integer: int bedNum = Integer.parseInt(bedRTF.getText()); To get a double value, for example number of bathrooms; use a class method parseDouble from the Double class to convert the string to a double: double weight = Double.parseDouble(weightTF.getText()); or String weightString = weightTF.getText(); double weight = double.parseDouble(weight);

Part 3: Javadoc and packages Use Javadoc comments in your program. The JavadocHandout.pdf file explains Javadoc documentation style. Javadoc is a tool for generating API documentation in HTML format from doc comments in source code. (Optional: you can generate the Javadoc for your project (In Netbeans use Run -> Generate Javadoc))

3. Use packages. Read the PackagesIntro.pdf" to learn about the packages in Java. Create 3 packages in your project. One to store LivingSpace, Apartment and House classes. One to store exception classe and one to store the application with method main.image text in transcribed

Fit to width Housing Application FX housing: LivingSpace Abstract LivingSpace # address: String # baths: double # # bedRooms: int # sqft: int + + + + + LivingSpace (address: String, baths: double, bedR: Int, sqft int) throws Invalid BathNumberException setAddress (address: String) ) getAddress(); String setBaths(baths: double) throws InvalidBath NumberException getBaths(): double setBedRoomNum(bedR: Int) getBedRoomNum(); int setSqft(sqft: int) getsqft(): Int toString(): String + + + + A Apartment House rentFee: int housePrice:String + + + Apartment address: String, baths: double, bedR int, soft:int, rentFee: int) setRentFeel fees int) getRentFeet); int + toString(): String + + House(address: String, baths: double, bedR: int, soft:int, house Price: int) + SetPriceprices int) + getPrice(): int toString(): String Invalid Bath NumberException Invalid Bath NumberException String Fit to width Housing Application FX housing: LivingSpace Abstract LivingSpace # address: String # baths: double # # bedRooms: int # sqft: int + + + + + LivingSpace (address: String, baths: double, bedR: Int, sqft int) throws Invalid BathNumberException setAddress (address: String) ) getAddress(); String setBaths(baths: double) throws InvalidBath NumberException getBaths(): double setBedRoomNum(bedR: Int) getBedRoomNum(); int setSqft(sqft: int) getsqft(): Int toString(): String + + + + A Apartment House rentFee: int housePrice:String + + + Apartment address: String, baths: double, bedR int, soft:int, rentFee: int) setRentFeel fees int) getRentFeet); int + toString(): String + + House(address: String, baths: double, bedR: int, soft:int, house Price: int) + SetPriceprices int) + getPrice(): int toString(): String Invalid Bath NumberException Invalid Bath NumberException String

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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