-
Notifications
You must be signed in to change notification settings - Fork 9
Restructure examples and add basic tests #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ipavlopoulos
wants to merge
1
commit into
main
Choose a base branch
from
restructure-examples-and-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,87 +1,131 @@ | ||
| # Java Examples Collection | ||
|
|
||
| > Designed for the AUEB CS BSc Java Course | ||
| >> https://eclass.aueb.gr/courses/INF176/ | ||
| Designed for the AUEB CS BSc Java Course: | ||
| https://eclass.aueb.gr/courses/INF176/ | ||
|
|
||
| This repository contains a collection of Java programming examples used for teaching core object-oriented programming (OOP) concepts in an engaging and applied way. Each example is organized as a separate package/module, and includes working code, documentation, and console interaction. | ||
| This repository contains small, runnable Java examples and course projects used | ||
| to teach core programming and object-oriented programming concepts. Topic-based | ||
| examples live under `gr/aueb/cs/examples`, while larger mini-projects live under | ||
| `gr/aueb/cs/projects`. | ||
|
|
||
| ## 📁 Project Structure | ||
| ## Project Structure | ||
|
|
||
| Each top-level package contains a complete, runnable Java example: | ||
| ### `gr/aueb/cs/examples/introduction` | ||
|
|
||
| --- | ||
| Introductory Java examples covering variables, control flow, simple classes, and | ||
| basic simulation. | ||
|
|
||
| ### 🎲 `montyhall/` | ||
| ### `gr/aueb/cs/examples/strings` | ||
|
|
||
| A full implementation of the Monty Hall game: | ||
| Examples for working with Java strings and common string operations. | ||
|
|
||
| - OOP structure (`Door`, `MontyHallGame`, `Strategy`) | ||
| - Interactive version (console-based) | ||
| - Simulator to run thousands of trials | ||
| - Visual comparison of strategies (switch vs stay) | ||
| ### `gr/aueb/cs/examples/inheritance` | ||
|
|
||
| ➡️ Teaches: classes, interfaces, composition, simulations, user interaction | ||
| Examples for inheritance, `final`, dynamic binding, and polymorphism. | ||
|
|
||
| --- | ||
| ### `gr/aueb/cs/examples/abstraction` | ||
|
|
||
| ### 🚶 `walkroutes/` | ||
| Examples for abstract classes and salary-based employee models. | ||
|
|
||
| A pedestrian routing system on a city grid: | ||
| ### `gr/aueb/cs/examples/interfaces` | ||
|
|
||
| - Location graph representation | ||
| - Obstacle-aware pathfinding | ||
| - Modular packages: `model`, `routing`, `map`, `simulation` | ||
| Small demonstrations of interfaces and interface-based design. | ||
|
|
||
| ➡️ Teaches: graphs, modular design, file input, BFS-style logic | ||
| ### `gr/aueb/cs/examples/collections` | ||
|
|
||
| --- | ||
| Examples using Java collections such as lists, queues, iterators, and traversal | ||
| patterns. | ||
|
|
||
| ### 🎯 `demo/` | ||
| ### `gr/aueb/cs/examples/generics` | ||
|
|
||
| Demonstrates the difference between: | ||
| Examples for generic classes, generic methods, bounded type parameters, | ||
| comparators, sorting, and type erasure. | ||
|
|
||
| - `Math.random()` (static, simple, no seed) | ||
| - `Random` class (object-based, supports seeding) | ||
| - Repeatable pseudo-randomness | ||
| ### `gr/aueb/cs/examples/exceptions` | ||
|
|
||
| ➡️ Teaches: randomness, testing, debugging with seeded values | ||
| Examples for exception handling, throwing exceptions, and safer error handling. | ||
|
|
||
| --- | ||
| ### `gr/aueb/cs/examples/files` | ||
|
|
||
| ### 🏨 `hotelbooking/` *(optional extension)* | ||
| Examples for reading and writing files, UTF-8 text, URLs, and CSV-style input. | ||
|
|
||
| Simulates a basic hotel booking system with multiple room types. | ||
| ### `gr/aueb/cs/examples/unit` | ||
|
|
||
| ➡️ Teaches: inheritance, encapsulation, polymorphism | ||
| A small calculator example with a matching unit test. | ||
|
|
||
| --- | ||
| ### `gr/aueb/cs/examples/profiling` | ||
|
|
||
| ### 🎬 `movies/` *(optional extension)* | ||
| Simple performance and profiling examples comparing data structures, primitive | ||
| types, wrapper types, and buffer capacity choices. | ||
|
|
||
| Loads movie reviews from a file and filters recommendations by genre, rating, or sentiment. | ||
| ### `gr/aueb/cs/examples/graphics` | ||
|
|
||
| ➡️ Teaches: file I/O, `ArrayList`, filtering, basic NLP | ||
| Graphical Java examples, including a tag cloud visualization. | ||
|
|
||
| --- | ||
| ### `gr/aueb/cs/examples/sound` | ||
|
|
||
| ## 🧪 How to Run | ||
| Audio-related examples, including a simple alarm demo. | ||
|
|
||
| Use the terminal or your favorite IDE (e.g., IntelliJ, Eclipse): | ||
| ### `gr/aueb/cs/examples/review` | ||
|
|
||
| Review examples for dynamic dispatch, constructors, exceptions, anonymous | ||
| classes, and randomness. | ||
|
|
||
| ### `gr/aueb/cs/projects` | ||
|
|
||
| Larger examples and student-friendly mini-projects: | ||
|
|
||
| - `montyhall`: Monty Hall game logic, strategies, console UI, and simulation. | ||
| - `walkroute`: Walking route demos using linked structures, search, and agents. | ||
| - `captcha`: A simple CAPTCHA generator and checker. | ||
| - `javagotchi`: A virtual pet project. | ||
| - `javagotchiWeb`: A Spring Boot web version of the Javagotchi project. | ||
|
|
||
| ## How to Run | ||
|
|
||
| From the repository root, compile and run a single class by using its package | ||
| path. For example: | ||
|
|
||
| ```bash | ||
| # Compile from src root | ||
| javac montyhall/app/Main.java | ||
| java montyhall.app.Main | ||
| javac gr/aueb/cs/examples/introduction/Variables.java | ||
| java gr.aueb.cs.examples.introduction.Variables | ||
| ``` | ||
|
|
||
| Another example: | ||
|
|
||
| ```bash | ||
| javac gr/aueb/cs/examples/inheritance/Polymorphism.java | ||
| java gr.aueb.cs.examples.inheritance.Polymorphism | ||
| ``` | ||
|
|
||
| # Or run another example | ||
| javac demo/RandomComparison.java | ||
| java demo.RandomComparison | ||
| For examples that define multiple classes in the same package, compile the | ||
| source file and then run the public class: | ||
|
|
||
| ```bash | ||
| javac gr/aueb/cs/examples/interfaces/Demo.java | ||
| java gr.aueb.cs.examples.interfaces.Demo | ||
| ``` | ||
|
|
||
| The Spring Boot project has its own README: | ||
|
|
||
| ```text | ||
| gr/aueb/cs/projects/javagotchiWeb/README.md | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| The `gr/aueb/cs/examples/unit` package contains small JUnit 5 tests for the | ||
| calculator example. Run them from the repository root with: | ||
|
|
||
| ```bash | ||
| mvn test | ||
| ``` | ||
|
|
||
| ## ✏️ Contribution | ||
| ## Contributing | ||
|
|
||
| To contribute to this repo, [this cheatsheet](/git_cheatsheet.md) may help with the first steps. | ||
| To contribute to this repository, the [Git cheatsheet](git_cheatsheet.md) may | ||
| help with the first steps. | ||
|
|
||
| ## 📄 License | ||
| ## License | ||
|
|
||
| This project is licensed under the [MIT License](LICENSE). |
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/abstraction/Employee.java → ...ueb/cs/examples/abstraction/Employee.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/abstraction/JuniorSalariedEmployee.java → ...s/abstraction/JuniorSalariedEmployee.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/abstraction/SalariedEmployee.java → ...xamples/abstraction/SalariedEmployee.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/collections/CollectionTest.java → .../examples/collections/CollectionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...b/cs/collections/IndexTraversalError.java → ...ples/collections/IndexTraversalError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.collections; | ||
| package gr.aueb.cs.examples.collections; | ||
|
|
||
| import java.util.*; | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
...cs/collections/IteratorTraversalSafe.java → ...es/collections/IteratorTraversalSafe.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/collections/ListTest.java → ...ueb/cs/examples/collections/ListTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ueb/cs/collections/PriorityQueueTest.java → ...amples/collections/PriorityQueueTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ueb/cs/exceptions/DivideByZeroSafely.java → ...amples/exceptions/DivideByZeroSafely.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.exceptions; | ||
| package gr.aueb.cs.examples.exceptions; | ||
|
|
||
| import java.util.InputMismatchException; | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
...DivideByZeroWithoutExceptionHandling.java → ...DivideByZeroWithoutExceptionHandling.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.exceptions; | ||
| package gr.aueb.cs.examples.exceptions; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package gr.aueb.cs.examples.exceptions; | ||
|
|
||
| public class ThrowTest { | ||
| public static void main(String[] args) { | ||
| try { | ||
| throw new RuntimeException("Σφάλμα!"); | ||
| } catch (RuntimeException e) { | ||
| System.out.println("Πιάστηκε εξαίρεση: " + e.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/files/RepresentationsTest.java → ...s/examples/files/RepresentationsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.files; | ||
| package gr.aueb.cs.examples.files; | ||
|
|
||
| public class RepresentationsTest { | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/files/URLReader.java → gr/aueb/cs/examples/files/URLReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Καλημέρα | ||
| Πώς είσαι; | ||
| Αυτό είναι δοκιμαστικό αρχείο σε UTF-8. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <library> | ||
| <section name="Programming"> | ||
| <book title="Effective Java" author="Joshua Bloch" year="2018" /> | ||
| <book title="Clean Code" author="Robert C. Martin" year="2008" /> | ||
| </section> | ||
| <section name="Computer Science"> | ||
| <book title="Introduction to Algorithms" author="Cormen, Leiserson, Rivest, Stein" year="2022" /> | ||
| </section> | ||
| </library> |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...eb/cs/generics/BoundedTypeParamsTest.java → ...mples/generics/BoundedTypeParamsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/generics/GenericMethodTest.java → .../examples/generics/GenericMethodTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/generics/GenericsTest.java → ...eb/cs/examples/generics/GenericsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.generics; | ||
| package gr.aueb.cs.examples.generics; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
...enerics/StudentSortingComparatorDemo.java → ...enerics/StudentSortingComparatorDemo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.generics; | ||
| package gr.aueb.cs.examples.generics; | ||
|
|
||
| import java.util.*; | ||
|
|
||
|
|
||
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/generics/TypeErasureTest.java → ...cs/examples/generics/TypeErasureTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/graphics/JavaTagCloud.java → ...eb/cs/examples/graphics/JavaTagCloud.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/inheritance/DynamicBinding.java → .../examples/inheritance/DynamicBinding.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/inheritance/Final.java → gr/aueb/cs/examples/inheritance/Final.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gr/aueb/cs/inheritance/Polymorphism.java → ...cs/examples/inheritance/Polymorphism.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package gr.aueb.cs.inheritance; | ||
| package gr.aueb.cs.examples.inheritance; | ||
|
|
||
| class X { | ||
| int a; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed some classes have default visibility while other stay public. Is there a reason for that? Just afraid it might confuse some students.