0

For some reason, line 67 is saying, "variable ddOption may not have been initialized. However, on lines 80 & 93, that variable is used and works just fine. Any idea of what's wrong here? (I omitted some of the code in the middle section.

//ShapeCalculator.java

import java.util.Scanner;

public class ShapeCalculator
{
    public static void main(String[] args)
    {
        //initialize Scanner
        Scanner input = new Scanner(System.in);

        //variable declarations
        int userDefinedDimension;
        int ddOption;
        int dddOption;
        double pi = 3.14;
        //circle variables
        int diam;
        double circum;
        double circleArea;
        //square variables
        int squareSide;
        int squarePerim;
        int squareArea;
        //triangle variables
        int triangleSideOne;
        int triangleSideTwo;
        int triangleSideThree;
        int trianglePerim;
        int triangleArea;
        int triangleBase;
        int triangleHeight;

        //prompt user for 2 or 3 dimensional shape
        System.out.print("Enter a 2 or a 3 for the amount of dimensions your desired shape has: ");
        userDefinedDimension = input.nextInt();

        ///////determine what to do with user's input//////////
        if (userDefinedDimension < 2 || userDefinedDimension > 3)
        {
            do
            {
                System.out.print("Please enter a valid number.  It must be 2 or 3: ");
                userDefinedDimension = input.nextInt();
            }
            while (userDefinedDimension < 2 || userDefinedDimension > 3);
        }
        if (userDefinedDimension == 2)
        {
            System.out.println("\n\nChoose one of the following options by entering the number indicated:");
            System.out.println("Circle - 1");
            System.out.println("Square - 2");
            System.out.println("Triangle - 3");
            ddOption = input.nextInt();
        }
        if (userDefinedDimension == 3)
        {
            System.out.println("\n\nChoose one of the following options by entereing the number indicated:");
            System.out.println("Sphere - 1");
            System.out.println("Cube - 2");
            System.out.println("Tetrahedron - 3");
            dddOption = input.nextInt();
        }//end dimension choosing

        /////////////two dimensional options////////////
        //circle area & circumference
        if (ddOption == 1)
        {
        }//end circle data
        //square area & circumference
        if (ddOption == 2)
        {
        }//end square data
        //triangle area & circumference
        if (ddOption == 3)
        {
        }//end triangle data
    }


}
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kahaj
0

*shakes head at self* I just need sleep. I forgot to set the value of ddOption and dddOption to 0 when declaring them. Did that & it works great.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.