Skip to content

Foundational Java exercises covering console I/O, conditionals, loops, arrays, exceptions, and introductory OOP with a geometric object hierarchy; small programs practice calculations, validation, and classification.

r-siddiq/Java-Foundations

Repository files navigation

Java Foundations

A collection of small Java programs demonstrating core programming concepts: variables and arithmetic, conditionals and loops, arrays, objects/classes, recursion, I/O, and simple geometry. Each file is self‑contained and runnable from the command line.

Tooling: Plain Java (no third‑party libs). Build with javac, run with java.


📁 Project Layout

Java-Foundations/
├─ CoinFlipGrid.java                # Random coin flips in a grid; nested loops & counts
├─ CramerRuleEqSolver.java          # Solve linear systems via Cramer’s Rule (determinants)
├─ LetterClassifier.java            # Classify characters; vowels/consonants/digits
├─ LoanCompare.java                 # Compare loan terms; monthly payment & totals
├─ MinutesToYear.java               # Convert minutes to years/days (integer math)
├─ PopulationProjection.java        # Population growth projection with given rates
├─ ReadWriteIO.java                 # File read/write demo; basic text I/O
├─ RecursiveSum.java                # Sum using recursion (intro to recursive thinking)
├─ SafeArrayLookup.java             # Bounds-checked array indexing; exceptions
├─ MyInterger/
│  ├─ MyIntegerClass.java           # Integer wrapper (isEven/isOdd/isPrime, etc.)
│  └─ MyIntegerApp.java             # Driver/tests for MyIntegerClass
├─ RegularPolygon/
│  ├─ RegularPolygonClass.java      # Area & perimeter for regular polygons
│  └─ RegularPolygonApp.java        # CLI to create polygons & compute metrics
└─ SimpleGeometricObject/
   ├─ GeometricObjectClass.java     # Base class: color, filled, dateCreated
   ├─ TriangleGeometricObjectClass.java  # Triangle specialization; area/perimeter
   └─ GeometricObjectApp.java       # Demo app for the geometric classes

🛠️ Prerequisites

  • JDK 17+ (works with any modern LTS JDK)

    • Windows: Microsoft Build of OpenJDK or Oracle JDK
    • macOS: Homebrew openjdk or Oracle JDK
    • Linux: distro packages or Adoptium Temurin
  • A terminal (PowerShell, bash, zsh)

  • (Optional) VS Code or IntelliJ IDEA for IDE builds

No external libraries are required.


🚀 Build & Run (CLI)

From the repository root:

# 1) Compile everything (creates .class files next to sources)
javac $(find . -name "*.java")  # macOS/Linux
# Windows PowerShell equivalent:
# Get-ChildItem -Recurse -Filter *.java | ForEach-Object { $_.FullName } | javac -encoding UTF-8 -d . -

# 2) Run a program (examples)
java CoinFlipGrid
java CramerRuleEqSolver
java RegularPolygon/RegularPolygonApp

On Windows cmd, you can compile folder‑by‑folder: javac *.java inside each subfolder, then java ClassName.


📚 Program Index

Program / Class What it demonstrates Typical interaction
CoinFlipGrid Math.random(), nested loops, counters, formatting Prompt for grid size; prints heads/tails grid & counts
CramerRuleEqSolver Arithmetic, 2×2 linear systems, determinants Enter a,b,c,d,e,f; solves ax + by = e, cx + dy = f
LetterClassifier Conditionals, character methods, input validation Enter a character; prints letter/digit/vowel/consonant
LoanCompare Numeric types, Math.pow, financial formulas Enter principal, APR(s), years; compares monthly/total
MinutesToYear Integer division/modulo, constants Enter minutes; shows years & days equivalence
PopulationProjection Simple growth model, arithmetic, console I/O Enter current pop/rates; projects N years
ReadWriteIO java.io basics: read & write text files Reads input file; writes processed output
RecursiveSum Recursion vs. iteration, base/recursive cases Enter n; outputs 1+…+n
SafeArrayLookup Arrays, bounds checks, exceptions Enter index; safely prints element or error
MyIntegerClass + MyIntegerApp Encapsulation, static vs instance, utility methods Tests isEven/isOdd/isPrime, comparisons
RegularPolygonClass + App Classes/objects, methods, geometry formulas Enter side length/count; area & perimeter
GeometricObject* + Triangle* + App Inheritance/composition, method overrides, geometry Create colored/filled shapes; compute area/perimeter

The App files are simple drivers that exercise their corresponding classes and print results to the console.


🔧 Tips

  • If a program seems to “hang,” it’s usually waiting for input—check the prompt.
  • Use -encoding UTF-8 with javac on Windows to avoid character issues.
  • To run from subfolders (e.g., RegularPolygon), run java RegularPolygonApp from that folder or set a proper package if you reorganize.

✅ License / Usage

Feel free to use, modify, and extend for learning and portfolio purposes.

About

Foundational Java exercises covering console I/O, conditionals, loops, arrays, exceptions, and introductory OOP with a geometric object hierarchy; small programs practice calculations, validation, and classification.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages