Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. The program 8 is called: SquareFootage
  2.  
  3.  
  4. Write a program that will determine the square footage of three houses
  5.  
  6. Look to page 2 for a sample output of the program.
  7.  
  8. You will read in information from the user to fill up your objects' instance variables.
  9.  
  10. Here, I will explain what to do in a step-by-step process on what to include in your code. Test after each step:
  11.  
  12.  
  13.  
  14. STEP ONE: This is the initial "setup" of your new class SquareFootage:
  15.  
  16.  
  17.  
  18. In main, create 3 objects of type SquareFootage: house1, house2, and house3. Do not send any arguments to the constructor (there are no parameters in this constructor.)
  19.  
  20.  
  21.  
  22. At the top of the program, right below the class definition, define 4 instance variables: houseName is a String; length, width, and sqfoot are positive doubles.
  23.  
  24.  
  25.  
  26. Create a Constructor to assign the values of the instance variables houseName, length, width, and sqfoot
  27.  
  28. These are then assigned within the constructor:
  29. into the instance variable houseName, read in the house name (make these up, like "Town Home", or "Guest House")
  30. into the instance variable length: read in the length of the house as a positive double
  31. into the instance variable width: read the width of the house as a positive double
  32. into the instance variable sqfoot: compute the square footage (length times width) as a double
  33.  
  34.  
  35. What you should have so far: (Write this program in small pieces! Make them work, then go on to the next step.
  36.  
  37.  
  38.  
  39. public class SquareFootage (
  40.  
  41. // Declare your instance variables HERE up at the top of this class as private
  42.  
  43.  
  44.  
  45. /**
  46.  
  47. * Include your Constructor(s) just below your instance variable declarations
  48.  
  49. */
  50.  
  51.  
  52.  
  53. public static void main (String [] args) {
  54.  
  55. // declare & initialize your objects to be the same type as the name of the class
  56.  
  57. }
  58.  
  59. }
  60.  
  61.  
  62. STEP TWO: Create Methods you will need to read in doubles and string values into your instance variables
  63.  
  64. getString(String parameter) returns a String (see my samples. Do not allow an empty string)
  65.  
  66. getDouble(String parameter) returns a positive double
  67.  
  68.  
  69.  
  70. By this point, you should be able to read in the values needed to instantiate (construct) your objects.
  71.  
  72.  
  73.  
  74. STEP THREE: Write a toString() method so that you can see what your objects contain. Each call to the toString() method will return a string that you can print out using a println or printf. In this case, you'll write a formatted String. Use the String.format() method to build your formatted string. (These usually don't have pretty output. They are usually used to "dump" out the contents of the objects so that you can see what is in them.)
  75.  
  76.  
  77.  
  78. (The dashed line and codes are here just to help you with counting spaces for setting it up!)
  79.  
  80. ====================================================================================
  81.  
  82. 15s 5.2f 5.2f 5.2f
  83.  
  84. Bird House has length of 0.75 and a width of 0.75 for square footage of 0.56
  85.  
  86.  
  87.  
  88.  
  89.  
  90. Here is an example of how to write a toString() method that will return a formatted String :
  91.  
  92.  
  93.  
  94. public String toString() {
  95.  
  96. return String.format("%35s %10d %10d", this.name, this.score1, this.score2);
  97.  
  98. }
  99.  
  100.  
  101.  
  102. STEP FOUR: Write the method that will display the chart header. Match the sample output.
  103.  
  104.  
  105.  
  106. STEP FIVE: Chart your results and compute the costs:
  107.  
  108. Invoke the same method three times, once for each object, that will: Display the content of the object (matches the chart) Note: In this method, you will also compute the cost of each house based on $80 per square foot and $110 per square foot depending on the square footage of each of the objects.
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. Match the output:
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. Welcome to YOURNAME's design program.
  125.  
  126. This program will compute the cost of building three houses.
  127.  
  128.  
  129.  
  130. Enter the data for the first house...
  131.  
  132. Model type of the house: Guest House
  133.  
  134. Length of house: -2
  135.  
  136. You must enter a positive number.
  137.  
  138. Length of house: 30
  139.  
  140. Width of house: 20
  141.  
  142.  
  143.  
  144. Enter the data for the second house...
  145.  
  146. Model type of the house: Mouse House
  147.  
  148. Length of house: 2
  149.  
  150. Width of house: 1
  151.  
  152.  
  153.  
  154. Enter the data for the third house...
  155.  
  156. Model type of the house: Bird House
  157.  
  158. Length of house: .75
  159.  
  160. Width of house: .75
  161.  
  162.  
  163.  
  164. Guest House has length of 30.00 and a width of 20.00 for square footage of 600.00
  165.  
  166. Mouse House has length of 2.00 and a width of 1.00 for square footage of 2.00
  167.  
  168. Bird House has length of 0.75 and a width of 0.75 for square footage of 0.56
  169.  
  170.  
  171.  
  172. ===========================================================================================
  173.  
  174. How much to Build Each home: Designed for YOUR NAME
  175.  
  176.  
  177.  
  178. Square Footage Cost at $80 per ft. Cost at $110 per ft.
  179.  
  180. ===========================================================================================
  181.  
  182.  
  183.  
  184. Guest House 600.0 48000.00 66000.00
  185.  
  186. Mouse House 2.0 160.00 220.00
  187.  
  188. Bird House 0.6 45.00 61.88
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement