Note that there are some explanatory texts on larger screens.

plurals
  1. POGuessing game using JOptionPane - Java
    primarykey
    data
    text
    <p>So I have been studying Java for about 8 weeks and for class I had to design a shape guessing game. Yes it is Homework. So I have built my four shape classes with an example of one below. </p> <pre><code>public class square extends shape { //square member variables boolean equalSides = true; // check if sides are equal public boolean isEqual() { return equalSides; } //constructor public square(int numsides, String shapeName, boolean b, String shapehint) { super(numsides, shapeName, shapehint); } } </code></pre> <p>I then created a shape.java class</p> <pre><code>public class shape { int numSides; String shapeName; String shapeHint; public shape(int numsides, String shapename, String shapehint) { numSides = numsides; shapename = shapeName; shapehint = shapeHint; } //getter methods public int getSides() { return numSides; } public String getName(){ return shapeName; } public String getHint(){ return shapeHint; } } </code></pre> <p>It's now that I have reached the shapeGuesser class that I am starting to struggle just a little. I'm unsure how to incorporate a guard for my game and the JOptionPane side of it. I need shapeGuesser to run until the user guesses the correct shape.</p> <p>I have been instructed to present the user with this option at the start.</p> <p>What question shall I ask?</p> <p>Enter Number: 1.How many sides? 2.Are your sides the same length? 3. Hint</p> <p>Based on the number you enter 1, 2 or 3.That question will be asked of that shape. So your Shape must have an appropriate response ready.</p> <pre><code>import javax.swing.JOptionPane; import java.util.Random; public class shapeGuesser { public static void main(String[] args, Object Do) { // TODO Auto-generated method stub // the shape the program uses int random; shape shapeChoice; // create shapes square s = new square(4, "Square", true, "Geeks were called this in the 80s"); Rectangle r = new Rectangle(4, "Rectangle", false, "Not Pentangle"); Triangle t = new Triangle(3, "Triangle",false, "Toblerone"); Circle c = new Circle(0, "Circle",true, "Circle Circle Circle"); //declare shape array shape[] Shapes; //create shape array Shapes = new shape[4]; //put shape objects in shape array Shapes[0] = s; Shapes[1] = r; Shapes[2] = t; Shapes[3] = c; // generate random number random = (int) (1 + (Math.random() * 3)); //pick shape from shape array based on random number shapeChoice = Shapes[random]; } } </code></pre> <p>Anyone who read this far and might have the time to enlighten me in anyway. It would be much appreciated.</p> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload