In each case you will need to create a project, a public class with a main method, and a class that models the situation or object mentioned. Look at the DiceGame code. Die is the class that models the object, and DiceGame is the public class used to instantiate Die objects and test them out.
Easy
Create an Angle class. This should be pretty easy. Ideas for methods could be:
- boolean isAcute()
- boolean isObtuse()
- boolean isReflex()
- double toRadians()
Create a Point class, which models a point in 2 or 3 dimensional space. Ideas for methods could be:
- void print(), which just writes the point out to the console
- double distanceFrom(Point p), which takes another point as an argument and returns the distance between the two points
Learning to model space will help you when it comes to programming games in Greenfoot
Medium
Create a Fraction class. It will probably need variables like a numerator and a denominator. Ideas for methods could be:
- void print(), which just writes out the fraction to the console
- double convertToDecimal(), which returns the fraction as a decimal number (double is the data type for decimal numbers)
- Fraction add(Fraction), which takes another fraction as an argument and returns the sum of both fractions.
Create a Roulette game, which let’s you play a simple game.
Create a Birthday class, which does some interesting stuff with dates like:
- int getDay(), which returns the day on which the birthday falls, e.g. 0 for Monday, 1 for Tuesday, etc
- String getSign(), which tells you what star sign the birthday is
Create an Code class, which encrypts and decrypts text using a simple algorithm (e.g. rotation cipher)
Hard
Create a DeckOfCards class. This one is more challenging. You might need a Card class too. Your deck could be an array of Card objects. Ideas for methods could be:
- Card[] deal(int n), which returns an array of n cards from the pack
- void shuffle(), which randomises the pack
Can you use your deck to play a game?
Create a FootbalLeague class which simulates a football season by pairing teams and assigning a random number of goals to each to create a result. You may also need a FootballTeam class. Run a whole season and print the results. Does it look realistic?