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

2016/8/7

Rookie dilemma - setRotation randomly constructor

chalkwharf chalkwharf

2016/8/7

#
Hi there, I'm taking a Java Programming Fundamentals course, learning the very basics of programming and one of the programs we are using for this course is Greenfoot! I've run into a rookie situation that I can't seem to find the answer to in my course notes and could use a bit of assistance! I'm trying to make an instance in my game have a random rotation by adding a constructor to the object class. The practice activity I'm working on states: In the Rocket Constructor use the setRotation() method to set the angle of the rocket randomly between 45 and134 degrees. I know this is a very simple issue, I just am not all that savvy yet when it comes to Greenfoot source coding and, well, really just programming in general. Thanks in advance for any help!
erdelf erdelf

2016/8/7

#
The setRotation method is simple and just requires an integer. Well you need a random rotation, so we could use the Random method java provides, but Greenfoot already does that, so you can just call getRandomNumber(int). Check out the links to the api and if you need further assistance, just answer here. Edit: forgot something. The constructor is basically a normal method that get's called to create the Object. It has no return type and is called the same as the class. so the class "Rocket" has the constructor:
public Rocket()
{

}
You need to login to post a reply.