Skip to content

rin-star/abstractingRealObjects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bird Simulation Project

Welcome to the Bird Simulation Project. This program models a real-world object, a Bird, using Java classes. The project demonstrates object-oriented programming principles such as encapsulation, composition, constructors, method overloading, and behaviors.

This Java program simulates the behavior of birds in a virtual environment. Users can create birds, feed them, make them fly, and monitor their health and energy levels. The project highlights key object-oriented programming principles, including encapsulation, composition, constructors, and method overloading.

Folder Structure

The workspace contains the following folders:

  • src: contains the Java source files (Bird.java, Wing.java, BirdTester.java)
  • lib: contains any dependencies if added
  • bin: the folder where compiled .class files are generated by default

If you want to customize the folder structure, open .vscode/settings.json and update the related settings there.

Classes Overview

Bird.java

Represents the main class for the bird object. Includes:

  • Six instance variables (color, size, weight, energyLevel, health, and wing)
  • Two constructors (default and parameterized)
  • Accessor and mutator methods for all variables
  • Four behavior methods (fly(), eat(double), heal(), displayStatus())
  • A toString() method for displaying information about the bird

Wing.java

Represents the secondary class used within the Bird class. Includes:

  • One instance variable (wingStrength)
  • Accessor and mutator methods
  • A toString() method for descriptive output

BirdTester.java

Contains the main() method used to test the Bird and Wing classes. Demonstrates:

  • Object creation using both constructors
  • Calling behavior methods with and without parameters
  • Printing the object’s state using toString()

How to Run

  1. Open the project folder in Visual Studio Code.

  2. Compile the Java files:

    javac -d bin src/*.java
  3. Run the tester class:

    java -cp bin BirdTester

Example Output

Bird [color = unknown, size = 0.0, weight = 0.0, energyLevel = 100.0, health = 100.0, wingStrength = 50.0]
Bird [color = Blue, size = 1.5, weight = 2.3, energyLevel = 80.0, health = 90.0, wingStrength = 70.0]
The bird has eaten and gained energy.
The bird has eaten and gained energy.
The bird is flying!
The bird is flying!
Bird Status: Bird [color = unknown, size = 0.0, weight = 0.0, energyLevel = 110.0, health = 95.0, wingStrength = 50.0]
Bird Status: Bird [color = Blue, size = 1.5, weight = 2.3, energyLevel = 85.0, health = 85.0, wingStrength = 70.0]

Learning Objectives

  • Write and call constructors, including overloaded constructors.
  • Write methods with parameters and return values.
  • Write and use custom classes in Java.

Dependency Management

The JAVA PROJECTS view in Visual Studio Code allows you to manage dependencies. More details can be found in the VS Code Java Dependency Guide.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages