1 Replies - 495 Views - Last Post: 01 January 2009 - 04:18 PM Rate Topic: -----

#1 qualityowns  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-November 08

Need some help with this program

Posted 01 January 2009 - 03:29 PM

Write a program that asks the user for the length and width of a house, and how many houses there are. The program then calculates and prints the total square footage of all of the houses(each house is identical)

import java.util.Scanner;
public class House {
	public static void main(String[] args) {
		double width, length, area;
		int HowManyhouses; 
			Scanner i=new Scanner(System.in); 
		System.out.println("Please Enter Length");
		length= i.nextDouble();
		System.out.println("Please Enter Width");
		width= i.nextDouble();
		System.out.println("How Many Houses Are There?");
		HowManyhouses= input.nextInt();
		area= length*width;
		System.out.println(area);	
}
}



I only know how to calculate the average for one house but how do i calculate the area for all of the houses and to make it identical?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another program i need help with.

Write a program that asks for a test grade from the user.
The program will then output a letter grade according to the following range of values.
A: 90+
B: 80-89
C: 70-79
D: 65-69
F: 0-64
Error: when the input was negative (this is the default case)

import java.util.Scanner;
public class 2 {
	public static void main(String[] args) {
		double test;
		int x=0;
		Scanner i =new Scanner(System.in); 
			
		System.out.println("Enter a grade");
		test = i.nextDouble();
		
		if(x>90) 
			System.out.println("A");
		else if(x<=89 && x>=80) 
		
			System.out.println("B");
		else if(x<=79 && x>=70) 
		
			System.out.println("C");
		else if(x<=69 && x>=65) 
		
			System.out.println("D");
		else if(x<=64 && x>=0)
		
			System.out.println("F");
		else if(x<0) 
			System.out.println("Error");
			
		}
		}



Something's wrong in this program and i don't know what the mistake is.

This post has been edited by qualityowns: 01 January 2009 - 04:14 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need some help with this program

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Need some help with this program

Posted 01 January 2009 - 04:18 PM

so you work out the area for 1 house
area=length*width;

so now make a new vairable called total area and multiply the number of houses by the area of each house
double totalArea = howManyHouses * area;

System.out.println(totalArea);

P.s, if a moderator reads this, the code button is now prompting me a scripted window, which then links me to the hyperlink insert. Think the code button is messed up.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1