Calculating Area

From CompSciWiki
Revision as of 13:15, 1 April 2010 by TimC (Talk | contribs)

Jump to: navigation, search

{{1010PrAD|ProblemName=Calculate Area

|Problem= It's time to replace the carpet in your living room, but how much will it cost? The carpet you want costs $5 per square foot plus an installation fee of $500. Write a program that accepts as input the length and width (as integers) of a room. Calculate the total cost of carpeting by multiplying the square footage by the price per square foot, plus installation. Your program will print the total square footage and the total cost.

|SideSection= float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

|Solution=

|SolutionCode=
import java.io.*;
import javax.swing.*;

public class CalculateArea
{
	public static void main(String[] args)
	{
		final int COST_PSF = 5;

		String input;
		int length;
		int width;
		int area;
		int totalCost;

		input = JOptionPane.showInputDialog("Input length:");
		length = Integer.parseInt(input);

		input = JOptionPane.showInputDialog("Input width:");
		width = Integer.parseInt(input);

		area = length * width;
		totalCost = area * COST;

		System.out.println("Total area: " + area);
		System.out.println("Total cost: $" + totalCost);
	}
}
}}