I am working on a class assignment and one of the things covered in this weeks text is hardcoding and how it is frowned upon.
My question is if I physically put in a value that is part of the formula, is that considered hardcoding?
example: the volume of a sphere is (4/3) * PI * r^3 should I declare (4/3) as variable in the beginning of my block code? or should I take it a step further and declare the whole formula?
I hope what I am asking makes sense to everyone, and for a little extra information here is the my code:
package area_volume_surfacearea;
/**
* Area_Volume_SurfaceArea (Assignment number 9)
* For CSCI 111
* last modified sept 15 12 p.m.
* @author Jeffrey Quinn
*/
//import Scanner class
import java.util.Scanner;
public class Area_Volume_SurfaceArea
{
/**
* This method finds the Area, Volume and Surface Area of geometric shapes
based off a value that the user inputs (in inches)
*/
public static void main(String[] args)
{
double distance; //the distance the users inputs to be used in the formulas (raidus or side)
double areaCircle; //the area of the circle
double areaSquare; //the area of the square
double volumeSphere; //the volume of the sphere
double volumeCube; //the volume of the cube
double surfaceAreaSphere; // the surface area of the sphere
double surfaceAreaCube; //the surface area of the cube
//declare an instance of Scanner class to read the datastream from the keyboard
Scanner keyboard = new Scanner(System.in);
//get the value of the radius of the circle (in inches)
System.out.println("Please enter a distance (in inches) to be used:");
distance = keyboard.nextDouble();
//calculate area of a circle (in inches)
areaCircle = Math.PI * Math.pow(distance,2);
//calculate area of a square (in inches)
areaSquare = Math.pow(distance,2);
//calculate volume of a sphere (in inches)
volumeSphere = (4/3) * Math.PI * Math.pow(distance,3);
//calculate volume of a cube (in inches)
volumeCube = Math.pow(distance,3);
// calulate surface area of a sphere (in inches)
surfaceAreaSphere = 4 * Math.PI * Math.pow(distance,2);
//calculate surface area of a cube (in inches)
surfaceAreaCube = 6 * Math.pow(distance,2);
//results
System.out.println(" The area of a circle with the radius of " + distance + "in, is " + areaCircle);
System.out.println(" The area of a square whos sides measures " + distance+ "in, is " + areaSquare);
System.out.println(" The volume of a sphere with the radius of " + distance + "in, is " + volumeSphere);
System.out.println(" The volume of a cube whos sides measures " + distance + "in, is " + volumeCube);
System.out.println(" The surface area of a sphere with the radius of " + distance + "in, is " + surfaceAreaSphere);
System.out.println(" The surface area of a cube whos sides measures " + distance + "in, is " + surfaceAreaCube);
} //end main()
}// end class Area_Volume_SurfaceArea