Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program 8 is called: SquareFootage Write a program that will determine the square footage of three houses. Look to last page for a sample

The program 8 is called: SquareFootage

Write a program that will determine the square footage of three houses.

Look to last page for a sample output of the program.

You will read in information from the user to fill up your objects' instance variables.

Here, I will explain what to do in a step-by-step process on what to include in your code. Test after each step:

STEP ONE: This is the initial "setup" of your new class SquareFootage:

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.)

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.

Create a Constructor to assign the values of the instance variables houseName, length, width, and sqfoot

These are then assigned within the constructor:

into the instance variable houseName, read in the house name (make these up, like "Town Home", or "Guest House")

into the instance variable length: read in the length of the house as a positive double

into the instance variable width: read the width of the house as a positive double

into the instance variable sqfoot: compute the square footage (length times width) as a double

What you should have so far: (Write this program in small pieces! Make them work, then go on to the next step.

public class SquareFootage (

// Declare your instance variables HERE up at the top of this class as private

/**

* Include your Constructor(s) just below your instance variable declarations

*/

public static void main (String [] args) {

// declare & initialize your objects to be the same type as the name of the class

}

}

STEP TWO: Create Methods you will need to read in doubles and string values into your instance variables

getString(String parameter) returns a String (see my samples. Do not allow an empty string)

getDouble(String parameter) returns a positive double

By this point, you should be able to read in the values needed to instantiate (construct) your objects.

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.)

(The dashed line and codes are here just to help you with counting spaces for setting it up!)

===============================================================

15s 5.2f 5.2f 5.2f

Bird House has length of 0.75 and a width of 0.75 for square footage of 0.56

Here is an example of how to write a toString() method that will return a formatted String:

public String toString() {

return String.format("%35s %10d %10d", this.name, this.score1, this.score2);

}

STEP FOUR: Write the method that will display the chart header. Match the sample output.

STEP FIVE: Chart your results and compute the costs:

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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