Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:01:52+00:00 2026-05-23T12:01:52+00:00

I’m making a program that makes a fractal, and the user is suppose to

  • 0

I’m making a program that makes a fractal, and the user is suppose to choose what colors they what the fractal to be. The only problem is that the color variable won’t work outside the “if” statement. Here’s my code: (Problem in public void fractalEngine down by where pen colors are being set. Those verifiedChoice variables are initiated inside an if statement and don’t seem to carry over to the rest of the code.)

import java.awt.*;
import java.util.Scanner;

class anotherClass
{
    World worldObj = new World();
    Turtle m = new Turtle(100, 340, worldObj);
    Scanner in = new Scanner(System.in);

    public void hello()
    {
        System.out.println("This program is a fractal engine");
        System.out.println("A fractal shape is a geometric shape that represents"); 
        System.out.println("the whole shape, no matter what level of scale");
        System.out.println();
        System.out.println("Your fractal picture will have three different colors,");
        System.out.println("Please pick three of the following:");
        System.out.println("RED, GREEN, BLUE, ORANGE, BLACK, YELLOW, MAGENTA, PINK");
        System.out.println("NOTE: Type your choices just like they appear.");
        System.out.println();
    }


    public void fractalEngine(int pxLength, String fractalRule)
    {
        System.out.println("Choice #1 out of 3: ");
        String choice1 = in.nextLine();
        if(choice1.equals("RED") || choice1.equals("GREEN") || choice1.equals("BLUE") || choice1.equals("ORANGE") || choice1.equals("BLACK") || choice1.equals("YELLOW") || choice1.equals("MAGENTA") || choice1.equals("PINK"))
        {
            System.out.println("Your first choice has been set to " + choice1);
            String verifiedChoice1 = choice1;
        }
        else
        {
            System.out.println("That choice is not valid, your first choice will now be red");
            String verifiedChoice1 = "RED";
        }



        System.out.println("Choice #2 out of 3: ");
        String choice2 = in.nextLine();
        if(choice2.equals("RED") || choice2.equals("GREEN") || choice2.equals("BLUE") || choice2.equals("ORANGE") || choice2.equals("BLACK") || choice2.equals("YELLOW") || choice2.equals("MAGENTA") || choice2.equals("PINK"))
        {
        System.out.println("Your second choice has been set to " + choice2);
        String verifiedChoice2 = choice2;
        }
        else
        {
            System.out.println("That choice is not valid, your second choice will now be green");
            String verifiedChoice2 = "GREEN";
        }



        System.out.println("Choice #3 out of 3: ");
        String choice3 = in.nextLine();
        if(choice3.equals("RED") || choice3.equals("GREEN") || choice3.equals("BLUE") || choice3.equals("ORANGE") || choice3.equals("BLACK") || choice3.equals("YELLOW") || choice3.equals("MAGENTA") || choice3.equals("PINK"))
        {
            System.out.println("Your thrid choice has been set to " + choice3);
            String verifiedChoice3 = choice3;
        }
        else
        {
            System.out.println("That choice is not valid, your thrid choice will now be blue");
            String verifiedChoice3 = "BLUE";
        }

        m.setHeading(0);
        String subData = "";   
        m.turn(30);
        for(int n = 0; n < fractalRule.length() ; n=n+1)            
        {
            subData = fractalRule.substring(n, n+1);                 

            if(subData.equalsIgnoreCase("F"))
                m.forward(pxLength);
            else if(subData.equals("+"))
                m.turn(120);
            else if(subData.equals("-"))
                m.turn(300);
            else if(subData.equals("1"))
                m.setPenColor(verifiedChoice1);
            else if(subData.equals("2"))
                m.setPenColor(verifiedChoice2);
            else if(subData.equals("3"))
                m.setPenColor(verifiedChoice3);
            else if(subData.equalsIgnoreCase("Q"))              
                m.hide();

        }
    }
}

public class complexFractal
{

    public static void main(String[] args)
    {
       int lineLength = 15;
       String rule = "1F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F2+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F3+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-F-F-F+F-F-F-F+F-F+F-F+F-F-F-F+F-FQ";

       anotherClass ac = new anotherClass();

       ac.hello();
       ac.fractalEngine(lineLength, rule);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:01:52+00:00Added an answer on May 23, 2026 at 12:01 pm

    Inside your public void fractalEngine(int pxLength, String fractalRule) just declare the local variables right after the { symbol:

    public void fractalEngine(int pxLength, String fractalRule) {
        String verifiedChoice1  = "";
        String verifiedChoice2  = "";
        String verifiedChoice3  = "";
    
        //Logic here..
    
    }
    

    These local variables is only visible inside the method block and cannot be visible outside of the method.

    Just make sure you remove the String word that you mentioned inside your if statement and it can be used locally inside your method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.