Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Please help !

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help !

    So i got this assignment

    Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.
    Here what i did, i am not sure if this is what the assignment want, but this is the best method i could come up with

    //Khang Le
    import java.util.Scanner;
     
     
    public class InputAreaVolume {
     
    	public static void main(String[] args) {
     
    	  // Cube
    	    System.out.print("Enter edge measurement of cube: ");
    	    double edge = extracted().nextDouble();
    	    double CubeArena = 6 * edge * edge;
    	    double CubeVolume = edge * edge * edge;
    	    System.out.println(" The area of the cube is: " + CubeArena);
    	    System.out.println(" The volume of the cube is: " + CubeVolume);
     
    	 // Sphere
    	    System.out.print("Enter radius measurement of sphere: ");
    	    double radius = extracted().nextDouble();
    	    double SphereArena = 4 * 3.14 * radius * radius;
    	    double SphereVolume = Math.round(3.14 * radius * radius * radius * 4/3) ;
    	    System.out.println(" The area of the sphere is: " + SphereArena);
    	    System.out.println(" The volume of the sphere is: " + SphereVolume);
     
    	 // Cylinder
    	    System.out.print("Enter radius measurement of cylinder: ");
    	    double cylinder = extracted().nextDouble();
    	    System.out.print("Enter height measurement of cylinder: ");
    	    double height = extracted().nextDouble();
    	    double CylinderArena = 2 * 3.14 * cylinder * height + 2 * 3.14 * cylinder * cylinder;
    	    double CylinderVolume = 3.14 * cylinder * cylinder * height;
    	    System.out.println(" The area of the cylinder is: " + CylinderArena);
    	    System.out.println(" The volume of the cylinder is: " + CylinderVolume);
     
    	  // Tetrahedron
    	    System.out.print("Enter edge measurement of tetrahedron: ");
    	    double tetrahedron = extracted().nextDouble();	    
    	    double TetrahedronArena = Math.round( Math.sqrt(3) * tetrahedron * tetrahedron);
    	    double TetrahedronVolume =Math.round((tetrahedron * tetrahedron * tetrahedron) / (6 * Math.sqrt(2)));
    	    System.out.println(" The area of the tetrahedron is: " + TetrahedronArena);
    	    System.out.println(" The volume of the tetrahedron is: " + TetrahedronVolume);
     
     
     
    	}
     
    	private static Scanner extracted() {
    		return new Scanner(System.in);
    	}
    }

    What do you guys think? Did i do it right? Is there anything i could do to improve?

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Please help !

    Also posted here.

    Please give your threads titles that indicate the topic or the type of help needed.