English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Question 3a) Write an algorithm that calculates the volume of a house and the cost of heating the house. The house is assumed to have the shape of a box with a prism on top as roof. The dimensions of the house: Width, Length, Height, and RoofSide are given in meters. The cost of heating one cubic meter (1 m3) of the house is $0.34 (for a month).




Question 3b) Java Implementation of 3a). The dimensions of the house are input from the keyboard (you can assume the user inputs valid values, positive real numbers). The volume of the house and the cost of heating are displayed on the screen.


k the question shows a picture of a house ... a rectangular prism wit a triangular prism on top. All dimensions of the house are shown except the height of the triangle. So you have to calculate the height to find the volume and then find the cost. i know how to do part A but need help wit part B.

2006-10-09 08:34:03 · 2 answers · asked by moooona1987 2 in Computers & Internet Programming & Design

//program compute heat--this program calculates the volume of the house and from that compute// cost of heat.
import java.io.*
class ITI1120B
{
public static void main (string args[])
{
//DECLARE VARIABLE/DATA DICTIONARY
double roofside,height1,length,width,cost/m3 ; // given numbers
double volume ; // intermediate, height of roof , H2
double cost ; // result, volume, cost of heat/month
// PRINT OUT IDENTIFICATION INFORMATION
system.out.println() ;
system.out.println ( "ITI 1120 Fall 2006, Assignment 2, Question 3b");
system.out.println("Name: Muna Jaddou , Student# 3807312 and Mohamed Zaki ,Student#4154845")
System.out.println();

//READ IN GIVENS AND MODIFIEDS
// ITI1120.readDouble()

//BODY OF ALGORITHM


this is what i have so far

2006-10-09 08:47:52 · update #1

2 answers

Hi there,

I've had to make a few assumptions in this program, as I've not seen the exact question. My first assumption (and the only really important one) is that we're given both the total height of the entire building, plus the height of a single wall (a practical and easy calculation from an engineering standpoint...at least they SHOULD know how tall the entire thing is...). To determine the height of the pyramid on top, we subtract the houses rectanglular height from the total height of the building.

Anyways, on to the code:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double cubeBase = 0;
double cubeWidth = 0;
double cubeHeight = 0;

double pyramidHeight = 0;

double totalHouseHeight = 0;

System.out.println( "Welcome to little house on the Java! \n\n" );

System.out.println( "What is the total height of the building?" );
totalHouseHeight = input.nextInt();

System.out.println( "What is the total height of a single wall?" );
cubeHeight = input.nextInt();

System.out.println( "What is the width of the building?" );
cubeWidth = input.nextInt();

System.out.println( "What is the base of the building?" );
cubeBase = input.nextInt();

pyramidHeight = totalHouseHeight - cubeHeight;

double totalArea = areaOfHouse(cubeBase, cubeWidth, cubeHeight, pyramidHeight);

System.out.printf("Total area: %.2f\n\n", totalArea);

double heatingCost = (totalArea * 0.34);
System.out.printf("The cost of heating for exactly 1 month: $%.2f\n\n", heatingCost);

System.out.println("Press any key to continue...");
input.next();
}

static double areaOfHouse(double cB, double cW, double cH, double pH)
{
double totalArea;
double houseCube = (cB*cW*cH); // The area of the cubical portion of the house is Lenght * Width * Height
double housePyramid = (((cB*cW)*pH)/3); //The area of a pyramid is one-third the area of the base, times the height
totalArea = houseCube + housePyramid;
return totalArea;
}

}

Hope this helps! (I did compile and confirm this as working code on NetBeans IDE 5.0)

2006-10-09 11:55:56 · answer #1 · answered by addtheninth 2 · 0 0

What do you have for part B so far?

2006-10-09 15:42:34 · answer #2 · answered by edmusic04 1 · 0 0

fedest.com, questions and answers