Write a java class called House with the following two private attributes, and three methods: Attributes: 1) type (String) 2) height (int) The valid values of attribute "type" are: "Cabin", "Bungalow", and "High Rise". A house can be upgraded to the next type. For example, a house of type "Cabin" can be upgraded to "Bungalow" which can be later upgraded to "High Rise". A house is never downgraded. Methods: 1) constructor that takes accepts two input parameters to initialize the attributes if input parameters are valid. The constructor should "Throw IllegalArgumentException" with a reasonable message (Invalid House type or Invalid height) if input parameter for house type is invalid or input parameter for height is less than or equal to 0. The constructor should include try/catch blocks and the catch block should print the exception message and terminate program with "System.exit(1);". 2) upgrade method that takes no input parameters. It doubles the height of a house of type Cabin or Bungalow, then revises the value of type to next value (i.e., Cabin to Bungalow, Bungalow to High Rise, and High Rise remains the same). For example, upgrade() method will update a house of type "Cabin" with height 200 to next type "Bungalow" with height value of 400. For example, upgrade() method will update a house of type "Bungalow" with height 400 to next type "High Rise" with height value of 800. If the type of house is "High Rise", the upgrade() method should throw an IllegalArgumentException with message "High Rise house cannot be upgraded". The upgrade() method should include try/catch blocks, and the catch block should print the message and allow the program to continue executing. 3) toString method which returns a string with first character of type and height. e.g., tostring() should return a "C200" if the house is of "Cabin" with height 200. tostring() should return a "B500" if the house is of "Bungalow" with height 500. tostring() should return a "H1000" if the house is of "High Rise" with height 1000.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The programming language used is Java

Write a java class called House with the following two private attributes, and three
methods:
Attributes:
1) type (String)
2) height (int)
The valid values of attribute "type" are: "Cabin", "Bungalow", and "High Rise".
A house can be upgraded to the next type. For example, a house of type "Cabin" can
be upgraded to "Bungalow" which can be later upgraded to "High Rise". A house is
never downgraded.
Methods:
1) constructor that takes accepts two input parameters to initialize the attributes if
input parameters are valid. The constructor should "Throw
IllegalArgumentException" with a reasonable message (Invalid House type or Invalid
height) if input parameter for house type is invalid or input parameter for height is
less than or equal to 0. The constructor should include try/catch blocks and the
catch block should print the exception message and terminate program with
"System.exit(1);".
2) upgrade method that takes no input parameters. It doubles the height of a house
of type Cabin or Bungalow, then revises the value of type to next value (i.e., Cabin to
Bungalow, Bungalow to High Rise, and High Rise remains the same).
For example, upgrade() method will update a house of type "Cabin" with height
200 to next type "Bungalow" with height value of 400.
For example, upgrade() method will update a house of type "Bungalow" with
height 400 to next type "High Rise" with height value of 800.
If the type of house is "High Rise", the upgrade() method should throw an
IllegalArgumentException with message "High Rise house cannot be upgraded".
The upgrade() method should include try/catch blocks, and the catch block should
print the message and allow the program to continue executing.
3) toString method which returns a string with first character of type and height.
e.g., tostring() should return a "C200" if the house is of "Cabin" with height 200.
tostring() should return a "B500" if the house is of "Bungalow" with height 500.
tostring() should return a "H1000" if the house is of "High Rise" with height
1000.
Transcribed Image Text:Write a java class called House with the following two private attributes, and three methods: Attributes: 1) type (String) 2) height (int) The valid values of attribute "type" are: "Cabin", "Bungalow", and "High Rise". A house can be upgraded to the next type. For example, a house of type "Cabin" can be upgraded to "Bungalow" which can be later upgraded to "High Rise". A house is never downgraded. Methods: 1) constructor that takes accepts two input parameters to initialize the attributes if input parameters are valid. The constructor should "Throw IllegalArgumentException" with a reasonable message (Invalid House type or Invalid height) if input parameter for house type is invalid or input parameter for height is less than or equal to 0. The constructor should include try/catch blocks and the catch block should print the exception message and terminate program with "System.exit(1);". 2) upgrade method that takes no input parameters. It doubles the height of a house of type Cabin or Bungalow, then revises the value of type to next value (i.e., Cabin to Bungalow, Bungalow to High Rise, and High Rise remains the same). For example, upgrade() method will update a house of type "Cabin" with height 200 to next type "Bungalow" with height value of 400. For example, upgrade() method will update a house of type "Bungalow" with height 400 to next type "High Rise" with height value of 800. If the type of house is "High Rise", the upgrade() method should throw an IllegalArgumentException with message "High Rise house cannot be upgraded". The upgrade() method should include try/catch blocks, and the catch block should print the message and allow the program to continue executing. 3) toString method which returns a string with first character of type and height. e.g., tostring() should return a "C200" if the house is of "Cabin" with height 200. tostring() should return a "B500" if the house is of "Bungalow" with height 500. tostring() should return a "H1000" if the house is of "High Rise" with height 1000.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education