Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>isEqual() needs an implementation in the base class, shape, as with <strong>all methods</strong> you want to call on all your shapes. Have the base shape return false. (Ideally shape should be abstract so you can't have a basic shape object, only squares, rectangles, etc. but its okay, you're new, and nobody else will use this. So you yourself can just never create a base shape. But for the future, that's what abstract is for ^^) Then, have all your other shapes override that base isEqual() the way your square already does.</p> <p>You're doing good! You've selected a random shape, and created many shapes.</p> <p>Now create a loop that prints the options,</p> <pre><code>system.out.println("Enter Number: 1.How many sides? 2.Are your sides the same length? 3. Hint"); </code></pre> <p>Then take the user input, and parse it to an integer. Have an if/else/else or a switch/case using that integer. (alternatively, use if/else/else with the string as it is, but make sure to use .equals() not ==)</p> <p>So now you've asked a question, and selected one. Now you print out</p> <pre><code>if(userInput.equals("1")){ system.outprintln("How many sides? " + shapeChoice.getSides()); } </code></pre> <p>Do the same thing for 2 and 3. You'll be dealing with a shapeChoice, so you have to call the base methods of shape. However, at runtime, if the object is a square or a rectangle, when you call shapeChoice.getSides() it will invoke the square or rectangle implementation, giving you the answer you want! :)</p> <p>Then all you have to do is loop back, ask the question over and over again, and if the user wants to, let him guess, and check his answer! (compare .equals(shapeChoice.getName()))</p> <p>so have a big while(true) forever loop, inside of which you can ask a question, and then check if they want to answer. If they answer right, you break out. Otherwise, you loop back around, and keep asking them which hint they'd like.</p> <p>EDIT: Actually, now that I look at it, since you're practicing polymorphism, you should probably use it a little more. Right now, You have your separate classes, but you're passing in all your information when you construct them. Instead of:</p> <pre><code>square s = new square(4, "Square", true, "Geeks were called this in the 80s"); Rectangle r = new Rectangle(4, "Rectangle", false, "Not Pentangle"); </code></pre> <p>Have it be more like</p> <pre><code>square s = new square(); </code></pre> <p>and have part of square's definition inherently define </p> <pre><code>public class square extends shape { //square member variables boolean equalSides = true; int numSides = 4; //and so on //OR even better, don't define them, since the base class already does! //merely set the values in the constructor public square(){ numSides = 4; equalSides = true; shapeHint = "Geeks were called this in the 80s"; } } </code></pre> <p>EVERY square object is going to be this way, so there's no reason it should be a parameter. That is part of the definition of a square. </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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