Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im on chapter 10 problem 45E in introduction to programming with greenfoot 2nd e

ID: 3710541 • Letter: I

Question

Im on chapter 10 problem 45E in introduction to programming with greenfoot 2nd edition. Iin myWorld class, it says it cant find method. my code thus far.

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Start here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Start extends Actor
{
public GreenfootSound sound = new GreenfootSound("SleepAWAY.mp3");
private boolean off = true;
/**
* Act - do whatever the Start wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Greenfoot.mouseClicked(this) && off)
{
sound.playLoop();
off = false;
}
else if(Greenfoot.mouseClicked(this) && !off)
{
sound.pause();
off = true;
}
}

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{

/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{   
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
addObject(newStart(),400, 250);
}
}

Explanation / Answer

There is a syntax error in MyWorld class, method public MyWorldClass().

I think instead of

addObject(newStart(),400, 250);

you meant

addObject(new Start(), 400, 250);

You were missing a space in between keyword new and Start().

I hope that solves the problem in case of any doubts just comment down.