This is the first code I've written. It's for an intro to Java course. Could you look over it and let me know of things I could improve before handing it in?
For reference, I've also provided what I'm being graded on at the bottom.
import java.util.Scanner;
public class LB01Smith {
public static void main(String[] args) {
System.out.println("This program computes the volume and surface area of a sphere, cube, and tetrahedron using a given dimension.");
System.out.println("Next, the program will compute the dimension of a sphere, cube, and tetrahedron using a given volume.");
Scanner input = new Scanner(System.in);
String usersName;
String upperCaseName;
System.out.print("Please enter your name, then press ENTER: ");
usersName = input.nextLine();
upperCaseName = usersName.toUpperCase();
System.out.println("Hello, " + upperCaseName + ", nice to meet you!");
System.out.print(" ");
double length = 0;
double volume = 0;
double cubeVolume = 0;
double cubeSurfaceArea = 0;
double sphereVolume = 0;
double sphereSurfaceArea = 0;
double tetVolume = 0;
double tetSurfaceArea = 0;
double cubeSide = 0;
double sphereDiameter = 0;
double tetSide = 0;
final double PI = Math.PI;
final double SQRT_2 = Math.sqrt(2);
final double SQRT_3 = Math.sqrt(3);
System.out.print("Please enter a dimension for volume calculation, then press ENTER: ");
length = input.nextDouble();
cubeVolume = (length * length * length);
cubeSurfaceArea = 6 * (length * length);
sphereVolume = PI / 6 * (length * length * length);
sphereSurfaceArea = 4 * PI * ((length / 2) * (length / 2));
tetVolume = (length * length * length ) / (6 * SQRT_2);
tetSurfaceArea = SQRT_3 * (length * length);
System.out.println("");
System.out.println("The Volume of your CUBE is : " + cubeVolume);
System.out.println("The Surface Area of your CUBE is : " + cubeSurfaceArea);
System.out.println("");
System.out.println("The Volume of your SPHERE is : " + sphereVolume);
System.out.println("The Surface Area of your SPHERE is : " + sphereSurfaceArea);
System.out.println("");
System.out.println("The Volume of your TETRAHEDRON is : " + tetVolume);
System.out.println("The Surface Area of your TETRAHEDRON is : " + tetSurfaceArea);
System.out.println("");
System.out.print("Now, please enter a volume for side or diameter calculation, then press ENTER: ");
volume = input.nextDouble();
cubeSide = Math.pow(volume, (1.0/3.0));
float roundedValue = Math.round(cubeSide);
sphereDiameter = Math.pow(volume / PI * 6, (1.0/3.0));
tetSide = SQRT_2 * Math.pow(3 * volume, (1.0/3.0));
System.out.println("");
System.out.println("The Side of your CUBE is : " + roundedValue);
System.out.println("");
System.out.println("The Diameter of your SPHERE is : " + sphereDiameter);
System.out.println("");
System.out.println("The Side of your TETRAHEDRON is : " + tetSide);
System.out.println("");
System.out.println("Closing Program...");
input.close();
System.out.println("The program has ended. Thank you, " + upperCaseName + ", Goodbye.");
}
}
( __ / 1 ) You name your program LB01LastName, where you change the LastName to your own last name.
( __ / 2 ) Submit a copy of your source code (the .java file) .
( __ / 2 ) Your program tells the user what the program does.
( __ / 3 ) Your program prompts the user for a length dimension.
( __ / 6 ) Your program declares and uses constants for the square root of two, square root of three, and pi.
( __ / 6 ) Your program correctly calculates the volume and surface area of the cube.
( __ / 6 ) Your program correctly calculates the volume and surface area of the sphere with that length as its diameter.
( __ / 6 ) Your program correctly calculates the volume and surface area of the regular tetrahedron.
( __ / 6 ) Your program outputs the results of the area calculations.
( __ / 6 ) Your program outputs the results of the volume calculations.
( __ / 3 ) Your program prompts the user for a volume.
( __ / 6 ) Your program correctly calculates the side length of a cube with that volume.
( __ / 6 ) Your program correctly calculates the diameter of a sphere with that volume.
( __ / 6 ) Your program correctly calculates the side length of a tetrahedron with that volume.
( __ / 6 ) Your program outputs the results of the length calculations.
( __ / 2 ) Your program tells the user that it is terminating.
( __ / 6 ) Your code is easy to read because you followed the programming style outlined in section 1.10 of the text by Y. Daniel Lang.and made appropriate use of spaces, indentation, and blank lines.
( __ / 6 ) You followed the naming conventions outlined in section 2.8 of the text by Y. Daniel Lang.and used a class name that starts with a capital letter, variable names that are full and descriptive and start with a lower case letter, and constant names that are in all capital letters.
( __ / 6 ) Your code is well documented as outlined in section 1.10 of the text by Y. Daniel Lang.and has javadoc style comments before the class and main method.
( __ / 5 ) Your code is efficiently written.
( __ / 5 ) Extra Credit: Have your program prompt the user for a common area and then calculate the dimension for each shape to have that area.