Giter VIP home page Giter VIP logo

long-term-project-aquarium-java's Introduction

Aquarium Project

Java Based application to demonstrate how to use OOP principles, for example interface, inheritance.

Implementation:

For example, class InsideContainer is represent the Fish Container for the Aquarium. At its constructor we initialize the baseBackground for the water image, and initialize fishCollection variable to hold the fishes.
InsideContainer, the paint method. In the paint method we override:

  • Create a buffer image for Double Buffering (Drawing Image in memory first)
  • Draw the background SeaScape
  • Loop all fishCollection and draw the fish current image ( each fish will have two type of image, left or right).

For example, Fish Abstract Class. Fish is an abstract class, this class cannot be instantiate. We will need to inherits from Fish and make a new class, for example RedFish.

The RedFish class, use static initializer to load images, for example, fish-red.png and fish-red-right.png You will see that RedFish will be forced to override two abstract methods from Fish class:
- getLeftImage()
- getRightImage()

But many methods its already inherited from Fish class:
- moveUp()
- moveDown()
- moveLeft()
- moveRight()
- getCurrentImage()
- run() - this is for Runnable thread

Some of them is either protected or private. private method in Fish class means the method is only visible inside the Fish class, and cannot be invoke from outside Fish class, for examples: - randomStartPosition
- randomMovementArea
- randomHorizontalDirection
- randomVerticalDirection
- randomMinLeft
- randomMaxRight
- randomMinTop
- randomMaxBottom
protected method in Fish class means the method is only visible inside the Fish class and it subclasses, so RedFish as a subclass still can invoke it directly:
- setCurrentImage(Image currentImage)
By providing private modifiers, we hide the complexity of the Fish class, so when we create a new class, extending from Fish, we can only see the public/protected and can override the required method.

Using FishFactory Class FishFactory is a class that can be used to instantiate various kinds of Fish, we are recommending to create a fish object using FishFactory. The FishFactory will read the index file and load it to program.

Easily adding new Fish
- Create a new class for example YellowFish.java in package.
- Implements the required method, make sure you use image, for example fish-yellow.png and fish-yellow-right.png
- Put those images in src/main/resources.
- Add some line the index file.

Example of UI:


Get help: TBD-supportReview the GitHub status page

© 2023 TBD-copyright-holder • Code of ConductMIT License

long-term-project-aquarium-java's People

Contributors

akakiev 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.