rectangular prism

im stuck i cant writ this program

Page 1 of 1

10 Replies - 5500 Views - Last Post: 03 November 2010 - 02:18 PM Rate Topic: -----

#1 bino87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 10

rectangular prism

Posted 08 September 2010 - 05:27 AM

Java program which asks user fr dimensions of a rectangular prism nd displays the area nd volume nd 6 sides
Is This A Good Question/Topic? 0
  • +

Replies To: rectangular prism

#2 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: rectangular prism

Posted 08 September 2010 - 05:48 AM

Okay? And how are we suppossed to react to that post?
Was This Post Helpful? 0
  • +
  • -

#3 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: rectangular prism

Posted 08 September 2010 - 06:06 AM

This site should help in getting your problem solved.

http://math.about.co...ceareavol_4.htm

Now you just need to convert this to Java code and implement it within your program. If you're having any problems doing that, please post your code and we can help.

DIC has a policy in which we like to see a good faith effort before we start giving out any code. So show us what you've done and we'd be more than happy to assist you the rest of the way!
Was This Post Helpful? 0
  • +
  • -

#4 bino87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 10

Re: rectangular prism

Posted 09 September 2010 - 06:05 AM

im a beginners this is what i wrote help me i kno its wrong
import java.util.Scanner;
public class RectangularPrism {

public static void main(String[] args) {

int length;
int width;
int height;
String units;
int volume;
int surfaceArea;

}

void Get_Input()
{

// 1. Ask user for length, validate input.
Scanner input = new Scanner (System.in);
System.out.println("Enter length > 0 ");
int length = input.nextInt();

// 2. Ask user for width, validate input.
System.out.println("Enter width > 0 ");
int width = input.nextInt();
// 3. Ask user for height, validate input.
System.out.println("Enter height > 0 ");
int height = input.nextInt();
}

int Calculate_volume(int length, int width, int height)
{

Scanner input = new Scanner (System.in);
int volume = length * width * height;
return volume = input.nextInt();
}

int Calculate_surfacearea(int length, int width, int height)
{

Scanner input = new Scanner (System.in);
int surfaceArea = (2 * length * height) + (2 * width * length) + (2 * width * height);
return surfaceArea = input.nextInt();

}
void Display(int volume, int surfaceArea, int length, int width, int height, String units)
{




Edited by macosxnerd101: Welcome to DIC! :) Please, :code:.
Was This Post Helpful? 0
  • +
  • -

#5 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: rectangular prism

Posted 09 September 2010 - 07:00 AM

Please use the code tags when posting code:

:code:
Was This Post Helpful? 0
  • +
  • -

#6 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2778
  • View blog
  • Posts: 15,880
  • Joined: 24-September 08

Re: rectangular prism

Posted 09 September 2010 - 07:08 AM

okay leik, i tink u ment 2 say:

"My problem is that I was assigned a project where I have to find various computations based on the dimensions inputed from the user for a rectangular prism. The dimensions should include: height, width, and length. The computations should include: finding volume, displaying the area of each side, and/or displaying the total surface area of said rectangular prism. I have written some code already, which does/does not compile, and would like help debugging/sytax/logic. Thank you. Here is my code: :code:"
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10777
  • View blog
  • Posts: 40,123
  • Joined: 27-December 08

Re: rectangular prism

Posted 09 September 2010 - 03:23 PM

A few things. First, methods declared outside your main() method and not invoked in it will be ignored at runtime. Second, as main() is static, any methods it invokes must be static.

Now, your Get_Input() method will not work as it doesn't see an input variable. The input variables you declare in your other methods are local to those methods, and are invisible/inaccessible outside of the methods they are declared in. And the same goes for the three variables you declare in Get_Input(). They won't be accessible to the main() method. Also, not good practice to use multiple Scanners

That being said, I'm also not a huge fan of getInput() methods where all the input prompts are crammed into it, as the method isn't modular or reusable.

For your calculate() methods, they shouldn't handle getting input at all. The parameters are the input. Perform calculations on the params, and return a result. That makes them more modular and reusable.

So some skeleton code and logic:
class Main{

   public static void main(String[] args){
      //handle all user input here
   }

   public static double getVolume(int length, int width, int height){
       //return the product of length, width and height
       //and use this as a model for surface area
   }

}


Was This Post Helpful? 1
  • +
  • -

#8 bino87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 10

Re: rectangular prism

Posted 10 September 2010 - 07:41 PM

i did that but i hav variable never read
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10777
  • View blog
  • Posts: 40,123
  • Joined: 27-December 08

Re: rectangular prism

Posted 10 September 2010 - 07:44 PM

What specifically are you referring to? If you are still getting errors, post your *revised* code as well if you made revisions.
Was This Post Helpful? 0
  • +
  • -

#10 Guest_njs*


Reputation:

Re: rectangular prism

Posted 03 November 2010 - 01:30 PM

here's the basic rectangular prism with accessor methods you'll need to add the prompts on your own and add assignment statements for those, good luck

public class RectangularPrism
{
	private double length;
	private double height;
	private double width;

	public RectangularPrism()
	{
		length = 1;
		height = 1;
		width = 1;
	}

	public RectangularPrism(double l,double h,double w)
	{
		length = l;
		height = h;
		width = w;
	}

	public double getLength()
	{
		return length;
	}

	public double getHeight()
	{
		return height;
	}

	public double getWidth()
	{
		return width;
	}

	public double getVolume()
	{
		return length*width*height;
	}

	public double getSurfaceArea()
	{
		return (length*width*2 + length*height*2 + height*width*2);
	}

	public String toString()
	{
		return "Rectangular Prism Stats" + "\n " + "height = " + height + "\n " + "length = " + length + "\n " + "width = " + width + "\n " + "volume = " + getVolume() + "\n " + "surface area = " + getSurfaceArea();
	}
}



Was This Post Helpful? 0

#11 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: rectangular prism

Posted 03 November 2010 - 02:18 PM

Yew, I'm impressed! NOT! Doing someone homework for them does not help them. They are assigned homework so that they learn something. What did the OP just learn? Nothing!.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1