This site requires JavaScript, please enable it in your browser!
Greenfoot back
CROCKETTROCKETT4
CROCKETTROCKETT4 wrote ...

2019/4/19

Help with Image and Displaying Text

CROCKETTROCKETT4 CROCKETTROCKETT4

2019/4/19

#
Hi, having some difficulty figuring out why the attempt to have a random adverb, verb, and noun isn't working. I'm aware of some repeated and unnecessary code as I've just been grasping at straws. So any input is appreciated. Also, would we need anything in the world class? (as of now I just want the code to show the text on the screen.
WORDS CLASS
public class Words extends Actor
{
    String text;
     
    public void act(){
        word();
        GreenfootImage();
    }

      public static String[] getAdv(){
        String[] adv =
        {"eerily", "spookily", "weirdly", "frighteningly", "uncannily", 
        "creepily", "ghostily", "mysteriously", "chillingly", "scarily", 
        "sinisterly", "eerily", "hauntingly", "terrifyingly", "supernaturally",
        "disturbingly", "ominously", "dreadfully", "putridly", "repulsively", 
        "distressingly", "menacingly", "deliberately" };
        return adv;
    }
        
         public static String[] getNoun(){
        String[] noun = {"Mr. Eaton", "Spencer", "Daniel", "Other Spencer",
        "ghost", "dinosaur", "frederick", "Colonel Sanders", "zombie",
        "wight", "skeleton", "bones", "flesh", "witch", "Obama", "Yoda",
        "cartilidge", "Julius Ceasar", "Ben Shapiro", "ZUckerberg", "dr Phil" };
        return noun;
    }
        
        public static String[] getVerb(){
        String[] verb = { "bite", "petrify", "howl", "horrify", "murder",
        "murder", "panic", "carve", "collect", "creep", "curse",
        "curdle", "scare", "possess", "spook", "startle", "frighten",
        "terrorize", "vex", "haunt", "destroy", "consume", "devour", 
        "degrade", "dissect", "decompose" };
        return verb;
    }
    
    public String GreenfootImage(java.lang.String string, int size, Color foreground, Color background, Color outline){
           string = text; size = 100; foreground = Color.WHITE; background = Color.BLACK; outline = Color.BLACK;              
    }
    
                      
    public Image(String text){
        setImage(new GreenfootImage(text, 50, Color.RED, Color.YELLOW, null));
        
    } 
    
    public String word(){  
         text = getAdv()[Greenfoot.getRandomNumber(getAdv().length)] + getVerb()[Greenfoot.getRandomNumber(getVerb().length)] + getNoun()[Greenfoot.getRandomNumber(getNoun().length)];
         
    }
}    
Super_Hippo Super_Hippo

2019/4/19

#
The "Image" method lacks a return type. If it should be the constructor, its name has to be equal to the class' name. Your "GreenfootImage" method has a return type String, but it does not return anything. In fact, the method doesn't do anything. I think it would be clever to let the word methods return one word and not the whole array of words. Then you also don't need to call the methods twice. The "word" method also has a return type String, but doesn't return anything. Keep in mind that the text on an image is not updated when you change the text variable. You need to create a new image with the updated text.
You need to login to post a reply.