I made a program that is supposed to ask for a shape and then make a green shape and then ask you if you wanted to make another shape. That didn't work so I changed it to ask if you wanted to make another shape after this one and put the println before the prompt.That didn't work either could anyone tell me whats wrong with the following code.

// The "Shape_Generator" class.
import java.awt.*;
import hsa.Console;

public class Shape_Generator
{
    static Console c;

    public static void main (String[] args)
    {
        c = new Console ();

        int on_off = 1;
        int contin = 1;
        char shape;
        char answr;


        {
            while (contin == 1)
            {
                while (on_off == 1)
                {
                    c.println ("Type in \"r\" for rectangle or \"o\" for oval.");
                    shape = c.readChar ();
                    c.println ("Do you want to make another shape after this one? y or n");
                    answr = c.readChar ();


                    if (shape == 'r')
                    {
                        c.fillRect (100, 100, 100, 100);
                        c.setColor (Color.green);
                        on_off = 0;
                    }

                    if (shape == 'o')
                    {
                        c.fillOval (100, 100, 100, 100);
                        c.setColor (Color.green);
                        on_off = 0;
                    }

                    if (answr == 'y')
                    {
                        on_off = 1;
                    }

                    if (answr == 'n')
                    {
                        contin = 0;
                    }




                }
            }
        }
    }
}

Recommended Answers

All 3 Replies

It's not at all clear what you think you're doing there.
You're never outputting any "shapes" so it's not surprising they're not shown. In fact you can't output them because you don't have any place to output them to (and if you had you'd need a quite different input mechanism than the console).

if I took out the contin varible statements the programs runs fine. It pops up in a new window and ask you to input o for oval or r for rectangle and then creates a shape based on the character typed in. The only problem im having is that it isn't recognized c.setColor and I dont no how to get the contin things to work. I'm a newb at this so don't be too harsh. I've only been in Comp Programming for about 2 weeks at High School Freshman year.

Member Avatar for iamthwee

Looks like you need a swing type application to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.