Programming and Problem Solving with Java

(やまだぃちぅ) #1
3.7 Value-Returning Class Methods | 125

Now look at the same class with proper formatting:


//**
// HouseCost application
// This application computes the cost per square foot of
// living space for a house, given the dimensions of
// the house, the number of stories, the size of the
// nonliving space, and the total cost less land
//**


public classHouseCost
{
public static voidmain(String[] args)
{
final doubleWIDTH = 30.0; // Width of the house
final doubleLENGTH = 40.0; // Length of the house
final doubleSTORIES = 2.5; // Number of full stories
final doubleNON_LIVING_SPACE = 825.0; // Garage, closets, etc.
final doublePRICE = 150000.0; // Selling price less land


doublegrossFootage; // Total square footage
doublelivingFootage; // Living area
doublecostPerFoot; // Cost/foot of living area

grossFootage = LENGTH * WIDTH * STORIES; // Compute gross footage
livingFootage = grossFootage–NON_LIVING_SPACE; // Compute net footage
costPerFoot = PRICE / livingFootage; // Compute cost per usable foot

System.out.println(“Cost per square foot is “ + // Output result
costPerFoot);
}
}


Need we say more?
Appendix F discusses coding style. We suggest you use it as a guide when you are
writing your own code.

Free download pdf