Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Java Programming Question. Please read carefully the following instructions Driver Program: public class TestHouse { public static void main(String[] args) { // TODO Auto-generated

A Java Programming Question. Please read carefully the following instructions

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Driver Program:

public class TestHouse {

public static void main(String[] args) { // TODO Auto-generated method stub // create some Houses House h1=new House (-5,'*','+'); House h2 = new House ( 7, '^','+' ); House h3= new House ( 12, 'W', 'o' ); House h4 = new House( 50 , '$' , '-'); // display original Houses

System.out.println ( "h1 has size = " + h1.getSize() + " units."); h1.Draw(); System.out.println ( "h2 has size = " + h2.getSize() + " units."); h2.Draw(); System.out.println ( "h3 has size = " + h3.getSize() + " units."); h3.Draw(); System.out.println ( "h4 has size = " + h4.getSize() + " units."); h4.Draw(); System.out.println ();

h1.Shrink(); // demonstrate shrink h2.Shrink(); h3.Grow(); // and grow h4.Grow(); System.out.println ( "h1 now has size = " + h1.getSize() + " units."); System.out.println ( "h2 now has size = " + h2.getSize() + " units."); System.out.println ( "h3 now has size = " + h3.getSize() + " units."); System.out.println ( "h4 now has size = " + h4.getSize() + " units.");

// demonstrate perimeter System.out.println ( "h2 has perimeter = " + h2.Perimeter() + " units."); System.out.println ( "h3 has perimeter = " + h3.Perimeter() + " units."); // and area System.out.println ( "h2 has area = " + h2.Area() + " square units."); System.out.println ( "h3 has area = " + h3.Area() + " square units.");

h1.Draw(); h1.Grow(); // show that fill character System.out.println ( "h1 grows:"); // appears only when size h1.Draw(); // is at least 3 h1.Grow(); System.out.println ( "... and grows:"); h1.Draw(); System.out.println ();

h1 = h2; // demonstrate the default overload of the // assignment operator System.out.println ( "h1 now has size = " + h1.getSize() + " units."); h1.Draw();

// demonstrate the changing of border and fill characters h2.setBorder('@'); h2.setFill('-'); System.out.println ( "h2 now looks like:"); h2.Draw(); System.out.println ( ); h2.setBorder((char)200); // illegal border h2.setFill((char) 212); // illegal fill System.out.println ( "h2 now looks like:"); h2.Draw(); System.out.println ();

System.out.println ( "Here is a summary on h3:"); // demonstrate summary h3.Summary();

}

} Sample Output:

-5 is an invalid size. Setting size to 3

50 is an invalid size. Setting size to 30

h1 has size = 3 units.

*

* *

* + *

* + + *

* * + * *

* + *

* * *

h2 has size = 7 units.

^

^ ^

^ + ^

^ + + ^

^ + + + ^

^ + + + + ^

^ + + + + + ^

^ + + + + + + ^

^ ^ + + + + + ^ ^

^ + + + + + ^

^ + + + + + ^

^ + + + + + ^

^ + + + + + ^

^ + + + + + ^

^ ^ ^ ^ ^ ^ ^

h3 has size = 12 units.

W

W W

W o W

W o o W

W o o o W

W o o o o W

W o o o o o W

W o o o o o o W

W o o o o o o o W

W o o o o o o o o W

W o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o o W

W W o o o o o o o o o o W W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W o o o o o o o o o o W

W W W W W W W W W W W W

h4 has size = 30 units.

$

$ $

$ - $

$ - - $

$ - - - $

$ - - - - $

$ - - - - - $

$ - - - - - - $

$ - - - - - - - $

$ - - - - - - - - $

$ - - - - - - - - - $

$ - - - - - - - - - - $

$ - - - - - - - - - - - $

$ - - - - - - - - - - - - $

$ - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ $ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $ $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - $

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

2 is an invalid size. Setting size to 3

31 is an invalid size. Setting size to 30

h1 now has size = 3 units.

h2 now has size = 6 units.

h3 now has size = 13 units.

h4 now has size = 30 units.

h2 has perimeter = 36 units.

h3 has perimeter = 71 units.

h2 has area = 63.712812921102035 square units.

h3 has area = 266.4278579257493 square units.

*

* *

* + *

* + + *

* * + * *

* + *

* * *

Your task is to code up a solution using an ahiect-oriented approach that will generate the above figure on the screen. The problem details are specified below Problem Description House Dimensions A house can be visualized as a triangle sitting on top of a square. An example of this is shown in the figure below. The specifications of a house can be found below. 1. The base of a house is a square and can be of any arbitrary length. The minimum length is 3 and the maximum length is 30. 2. The roof of a house is an equilateral triangle i.e a triangle where all 3 sides have equal length here to search 5 6 8 9 Alt Alt Ctri 3. The roof will always overhang the base by one-unit length on each side, so the length of the triangle's side will be 2 more than the length of the square's side. 4. The figure below shows a house with base size 5 ere to search + 6 8 9 Alt Alt Ctri Class Description 1. You should construct a House class, that will use the above blueprint to generate a house, when instantiated. 2. A house has 3 (private) attributes ere to search Pria 5 6 8 Alt Alt Ctrn Adobe Acrobat Reader DC hwi-description(1.. , Class Description 1. You should construct a House class, that will use the above blueprint to generate a house, when instantiated 2. A house has 3 (private) attributes. Size - refers to the base size of the house (integer). Example: 3 a. b. Border Character - refers to the character to draw the border of the house with (char) Example * Fill Character - refers to the character to fill the inside of the house with (char) c. Example: + he size should range between 3 and 30. If an attempt is made to set the size less than 3 the size should default to 3. Likewise, if an attempt is made to set the size larger than 30 the size should default to 30 The border and fill characters can be any character within the ASCII range 33-126. To refresh your knowledge on ASCII values, please revisit Chapter 4, Section 4.3 Basical If an attempt is made to set the border or fill characters to anything other than the characters that associated with the above ASCII values, the border character should default to and the fill character should default to + lly, the high-level idea is that each character has an integer value associated with it. 5. You should specify the accessors and mutators for all attributes of the House class. 6. You should code the functions void GrowO and void ShrinkO which increment and decrement the base size of the house by 1 respectively. If this causes the dimension of the house to go out of the range specified above, the size should not change Type here to search Ri e @ 5 6 8 9 Alt at Reader DC scription (1.. x 7. You should code the functions double Area) and double Perimeter) that return the ar and perimeter of a house. To compute these values, please refer to the Appendix. 8. You should code the function void Draw(0, which will display a picture of the house on the screen. Use the border character to draw the border of the house. Use the fill characters to draw the internal characters. When printing the border and fill characters, also print an additional blank space after each character to make the house look more proportional. For example, the following is what should be displayed when drawinga house of base size 5, border character and fill character ere to search Prtac 5 6 7 8 9 n+ A 9. Please note this must be done using nested loops. This is very similar to how you solved problems in CS116, where you were asked to print a triangle, or a diamond of a given 10. Note that the bottom of the roof and the top of the base will be on a shared line the size ang area will be border characters, but everything internal will be fills. See the sample outputs below to see exactly how this should look. ide a function called void Summary0 that will displays all the relevant information about a house, it's base size, area , perimeter and a picture of what it looks like 11. Provi to search 73% 5 6 8 9 G HH 12. A sample driver program has been provided with this assignment, that will help you understand how each of these above functions/attributes are used. If done correctly, your House class should automatically work with this program. You are not allowed to make any changes to the driver program. 13. I have also provided the output to my driver program. If done correctly, your output 14. You are allowed to code additional utility functions in the House class that will help you should match mine. Minor differences in output are OK with this assignment, but the above functions are mandatory and must be defined in your program. Documentation Please make sure your code is properly documented For each method that you write, please add a few lines on top, specifying the purpose of the method, what the input parameters represent and what the function is returning. Please use meaningful variable names. When writing a loop or some non-trivial logic, please write a short commer your logic, . In general, remember that your code tells me, what the program does, your comments and general documentation tells me why you wrote it a particular way Submission e to search Pr18 6 8 9 A/t Alt Ctri Adobe Acrobat Reader DC dow Help hw1 description (1... x Please make sure your code is properly documented For each method that you write, please add a few lines on top, specifying the purpose of the method, what the input parameters represent and what the function is returning Please use meaningful variable names. hen writing a loop or some non-trivial logic, please write a short comment explaining your logic n general, remember thal your code tells me, what the program does, your com general documentation tells me why you wrote it a particular way Submission Please submit your House class under HWI on Canvas. Please use House java as your class and filename. Type here to search 5 6 8 Alt Alt Ctri Appendix Square Area (A) of square with side a A = a2 Perimeter (P) of square with side a p 4.a Triangle Area (A) of equilateral triangle with side a V3 Aa2 4 Perimeter (P) of equilateral with side a P 3.a Type here to search F10 3 5 6

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions