Java program which asks user fr dimensions of a rectangular prism nd displays the area nd volume nd 6 sides
rectangular prismim stuck i cant writ this program
Page 1 of 1
10 Replies - 2888 Views - Last Post: 03 November 2010 - 02:18 PM
Replies To: rectangular prism
#2
Re: rectangular prism
Posted 08 September 2010 - 05:48 AM
Okay? And how are we suppossed to react to that post?
#3
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!
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!
#4
Re: rectangular prism
Posted 09 September 2010 - 06:05 AM
im a beginners this is what i wrote help me i kno its wrong
Edited by macosxnerd101: Welcome to DIC!
Please,
.
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!
#5
Re: rectangular prism
Posted 09 September 2010 - 07:00 AM
Please use the code tags when posting code:
#6
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:
"
"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:
#7
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:
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
}
}
#8
Re: rectangular prism
Posted 10 September 2010 - 07:41 PM
i did that but i hav variable never read
#9
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.
#10 Guest_njs*
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();
}
}
#11
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!.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote








|