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

2017/4/10

Setting Score

rockon411 rockon411

2017/4/10

#
I have a boolean method that is supposed to be able to tell if a score is greater than or equal to 2.5. Here is the code
public boolean isPostive()
    {
        if (getSentimentScore() >= 2.5)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
I am having troubles because whenever I test it my computer freaks out a little, so I obvious coded something incorrectly. I think it might have to do with the method it uses which is supposed to set the score and change the image accordingly.
public void setSentimentScore(double score)
    {
        this.review = score;
        if (getSentimentScore() <= .4)
        {
            setImage("0.png");
        }
        else if (getSentimentScore() <= 1.4)
        {
            setImage("1.png");
        }
        else if (getSentimentScore() <= 2.4)
        {
            setImage("2.png");
        }
        else if (getSentimentScore() <= 3.4)
        {
            setImage("3.png");
        }
        else
        {
            setImage("4.png");
        }
    }
This method uses this other method which is supposed to return the score.
private double review = 0;

    public Sentiment()
    {
        setImage("2.png");
    }
    
    public double getSentimentScore()
    {
        return review;
    }
These are all in my actor class, Sentiment. Any help would be appreciated.
Nosson1459 Nosson1459

2017/4/10

#
rockon411 wrote...
I am having troubles because whenever I test it my computer freaks out a little, so I obvious coded something incorrectly.
Could you say what happens? And post the full class code (Ctrl+A then Ctrl+C to copy everything, then paste it here). If the terminal window pops up then post that also.
danpost danpost

2017/4/10

#
Show what you tried to test it, also.
Nosson1459 Nosson1459

2017/4/10

#
rockon411 wrote...
I am having troubles because whenever I test it my computer freaks out a little,
danpost wrote...
Show what you tried to test it, also.
What are you doing to test it?
rockon411 rockon411

2017/4/11

#
Sorry guys. This is what my test looks like.
private Sentiment bob;
    
    public SentimentTest()
    {
    }
    public void setUp()
    {
        bob = new Sentiment();
    }
    public void testIsNeutral()
    {
        bob.setSentimentScore(2.0);
        
        assertEquals(true, bob.isNeutral());
    }
danpost danpost

2017/4/11

#
I thought you were testing the 'isPostive' method? Looks like you are test an 'isNeutral' method of which we have not seen the code for.
rockon411 rockon411

2017/4/11

#
Ya whoops. Ok I'm going to use the Ctrl-A thingy. Sorry about the confusion
import sofia.micro.*;

public class Sentiment extends Actor
{
    private double review = 0;
    public Sentiment()
    {
        setImage("2.png");
    }
    public double getSentimentScore()
    {
        return review;
    }
    public void setSentimentScore(double score)
    {
        review = score;
        if (getSentimentScore() <= .4)
        {
            setImage("0.png");
        }
        else if (getSentimentScore() <= 1.4)
        {
            setImage("1.png");
        }
        else if (getSentimentScore() <= 2.4)
        {
            setImage("2.png");
        }
        else if (getSentimentScore() <= 3.4)
        {
            setImage("3.png");
        }
        else
        {
            setImage("4.png");
        }
    }
    public boolean isPostive()
    {
        if (getSentimentScore() >= 2.5)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    public boolean isNegative()
    {
        if (getSentimentScore() < 1.5)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public boolean isNeutral()
    {
        if (getSentimentScore() >= 1.5 && getSentimentScore() < 2.5)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
danpost danpost

2017/4/11

#
I do not see anything obviously wrong with the codes given. What do you mean by "whenever I test it my computer freaks out a little"? What exactly does "freaks out" mean?
rockon411 rockon411

2017/4/11

#
Greenfoot freezes and does not say if the test passes or fail. I have to force quit to get anything to work after that. Thanks for looking over it. I'll continue working on the other programs and see if I can figure it out.
danpost danpost

2017/4/11

#
rockon411 wrote...
Greenfoot freezes and does not say if the test passes or fail. I have to force quit to get anything to work after that. Thanks for looking over it. I'll continue working on the other programs and see if I can figure it out.
Maybe we should look at the code where you are creating a SedimentTest object.
You need to login to post a reply.