Giter Club home page Giter Club logo

nour-sadek / guess-the-animal Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 46 KB

In this project, the computer will try to guess the animal that the user has in mind, extending its knowledge base by learning new facts about animals and using this information in the next game.

Home Page: https://hyperskill.org/projects/132

Java 100.00%
binarytree-java deserialization interactive java java-oop recursion resource-bundles serialization static-initializer

guess-the-animal's Introduction

Guess-the-Animal

Learning Outcomes

  • tree data structure: how to search it, and traverse all its nodes.
  • how to use serialization to store knowledge from a tree data structure.
  • how to use resource bundles for program internalization and adding support for different languages

About

In this project, a simple interactive game was created where the computer will try to guess the animal that the user has in mind with the help of yes or no questions. During the game, the computer will extend its knowledge base by learning new facts about animals and using this information in the next game.

The program starts (if it was being launched for the first time) by asking the user what their favorite animal is. This animal name will be the root node in our knowledge tree for now.
After that, the user will be greeted with a menu that has these 6 items:

  • Play the guessing game
  • List of all animals: lists all the animals that the user has provided to the program so far
  • Search for an animal: The user provides an animal name (with no article) and, if it exists in the knowledge tree, prints facts about it
  • Calculate statistics: gives information about what the current root node is, the total number of nodes, animals, and statements, the height of the tree, and the minimum and average animal's depth
  • Print the knowledge tree: prints the knowledge tree where the right node represents answering yes to the question and the left node represents answering no.
  • Exit: exits the program and saves the information from the knowledge tree through serialization in a file "animals.db"

This program also includes support for both the English and Esperanto languages through the use of resource bundles. The default language is English, but the user can specify the language to be Esperanto instead by using the "user.language" key of the JVM. For example, to specify the Esperanto language, one can run the following command:

java -Duser.language=eo Main

In the IntelliJ development environment (if IntelliJ was used as the IDE to run this program), the user can specify this key in the "Run / Debug Configurations" in the "VM Options" field.

Objectives of the guessing game

The program prompts the user to think of an animal and then tries to guess what it is. If the computer fails, the program should ask the user what this animal is and what statement can help distinguish it from another one. This knowledge is supposed to be stored in a form of a binary tree and saved through serialization for another run of the program.

When the computer starts the game, it will ask questions starting from the top, that is, the root node. If the computer makes a wrong guess, it should ask the user two questions: first, what animal the user had in mind, and second, what statement can help the computer distinguish the animal it guessed (old) from the animal that the person actually thought of (new). The program should clarify whether that fact is correct for the new animal. After that, the name of the "old" animal in the tree is replaced with the new statement, and two new leaves are added to this node: one with the "old" animal and another with the "new" animal.

At the end of each session, the program should ask the user if they want to keep playing or quit the game.

General Info

To learn more about this project, please visit HyperSkill Website - Guess the Animal (Java).

This project's difficulty has been labelled as Hard where this is how HyperSkill describes each of its four available difficulty levels:

  • Easy Projects - if you're just starting
  • Medium Projects - to build upon the basics
  • Hard Projects - to practice all the basic concepts and learn new ones
  • Challenging Projects - to perfect your knowledge with challenging tasks

This repository contains

animals package
    - Contains the animals.Main java class that contains the main method to run the project
    - Contains the animals.TestInput java class that is used to check for proper user input
    - Contains the animals.SerializationUtils java class that allows for serialization of tree information
    - Contains the animals.Node java class that includes the implementation of the Node class of BinaryTree
    - Contains the animals.BinaryTree java class that includes the implementation of the BinaryTree class that stores Node object as its root
    - Contains the BinaryTreePrinter java class that includes the implementation to print the BinaryTree on to the console window

main.resources Resource Bundles
    - Contains the messages.properties (for English) and messages_eo.properties (for Esperanto) 'messages' resource bundles
    - Contains the patterns.properties (for English) and patterns_eo.properties (for Esperanto) 'patterns' resource bundles

Project was built using java 21

How to Run

Download the animals and main.resources repositories to your machine. Create a new project in IntelliJ IDEA, then move the downloaded repositories to the src folder and run the animals.Main java class. After a single run of the program, a file "animals.db" will be saved to the same working directory. If a new fresh start of the program is needed, then "animals.db" needs to be deleted.

guess-the-animal's People

Contributors

nour-sadek 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.