Code Monkey home page Code Monkey logo

bugworld's Introduction

Andy's Bug World

Tasks

  • Task 1: Create two objects of class Bug using each constructor.

  • Task 2: Create a new method that asks the user to manually input values for the attributes (using a Scanner and System.in).

  • Task 3: Using an ArrayList, store 3 different bugs.

  • Task 4: Create a "move" method in Bug that can move the bug in one of the the four directions on a compass (N, S, E, W). At this point there is no concept of the size of the world, so it is ok to be in position x=-1 and y=-1.

  • Task 5: Create a test where one bug moves 100 times in random directions (using Math.random()).

Bug World 2

  • Create a class World that stores an unspecified number of bugs in a 2D world. The bugs must be stored in an ArrayList. The world must have attributes height and width that denote the size of the world.

  • Create appropriate constructors for the world that all iniialise a world with bugs in positions that are inside the world's height and width.

  • Create a drawWorld method. Use the symbol of each bug to show where the bug is in the world. Print the world as text in the format below:

|-----------------------------|
|       h      c    h         |
|                c            |
|          f    c             |
|                             |
|               hc      f     |
|  f                          |
|-----------------------------| 
  • Create an updateWorld method that randomly moves (or doesn’t move) each bug in the world. Bugs should not be allowed to move outside the world. Remember to use the move method of bug and not to manipulate x and y directly. Create a class Plant. Plants can grow, so each plant has a numeric value 0-9 of their size. Store a number of plants in another ArrayList within World. Change the drawWorld method so it includes plants.
|-----------------------------|
|       h      c    h         |
|            9    c           |
|   4      f    c             |
|                  2          |
|      0        hc      f     |
|  f                          |
|-----------------------------|  

Figure 2: Example text-only visualisation of the 2D map with plants

  • Create a class Obstacle. Obstacles are in the way of the bugs, i.e. they cannot walk over them or eat them.

Later (we haven't covered this yet!)

  • Using inheritance create 3 different types of bugs that inherit their behaviours from Bug. At this point the only difference between the different types should be their default species and symbol.

As part of this exercise make sure you understand:

  • the difference between objects and classes
  • inheritance
  • different levels of access modifiers (private and public that we've seen, and "protected" that is visible through the inheritance hierarchy)

bugworld's People

Contributors

andyfoster avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.