Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q4) Write a Java class that represent a building. The building has a number of appartments for rent, some are normal and some are delux.

image text in transcribedimage text in transcribed

Q4) Write a Java class that represent a building. The building has a number of appartments for rent, some are normal and some are delux. The delux appartments are \%20 more expensive than the normal ones. Here is the UML diagram: As shown in the UML diagram, write the class Building that has the attributes: - apts: Total number of appartments in the building. - normal: The number of rented normal appartments in the building. - delux: The number of rented delux appartments in the building. - rent: The monthly rent of a normal appartment. The methods of this class are: - setApts(int apts): void. Sets the value of the attribute apts (since its private) - howManyRented():int. Returns how many appartments are rented. - rentApt(int n, String type):boolean. This method receives an integer n which is the number of appartments we like to rent and their type. Based on the value of type you should increase occupied normal or delux appartments accordingly. But first, you must check if you have n appartments available to rent, If you do then rent the appartments and reurn true, else, return false. - printInfo():void. print all information about the building in an organized manner. After writing class building, write a java class testBuilding to test your building class. In this class you should: 1. Declare an object b of class Building. 2. Read two building attributes: apts and rent from the user. No need to read normal and delux appartments numbers because they start as zero. 3. Ask the user how many delux appartments he would like to rent. If there is availability rent them and display a message stating that n appartments were rented. If not you should display the message "Requested number of appartments exceeds availability" 4. Ask the user how many normal appartments he would like to rent. If there is availability rent them and display a message stating that n appartments were rented. If not you should display the message "Requested number of appartments exceeds availability" 5. Print the building Information. 6. Feel free to try creating additional building objects, read their data and manipulate them. 7. exit. Sample Run 1 Please enter Number of Appartments and rent amount :50 2000 How many delux appartments would you like to rent? 20 20 delux Appartments have been rented How many normal appartments would you like to rent? 15 15 normal Appartments have been rented ================== Building Info ========================== The Building has 50 appartment. Only 35 have been rented. 15 normal appartments with rent =2000.0 SR per month. And 20 delux appartments with rent 2400.0 SR per month Sample Run 2 Enter number of appartments and rent amount :100 10000 How many delux appartments would you like to rent? 70 70 delux Appartments have been rented How many normal appartments would you like to rent? 40 Requested number of appartments exceeds availability The Building has 100 appartment. Only 70 have been rented. 0 normal appartments with rent =10000.0 SR per month. And 70 delux appartments with rent 12000.0 SR per month

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

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago