A Java application that calculates area and perimeter for multiple shape types, then visualizes the selected shape with JavaFX.
The program asks the user for a number of sides, builds the correct shape object, collects the required measurements, prints the result, and opens a visual representation when JavaFX is available.
- Supports circles, triangles, rectangles, pentagons, and generic polygons
- Uses a shared
Shapeabstraction for common behavior - Uses
Polygonas a base class for polygon-based shapes - Calculates area and perimeter for each supported shape
- Validates triangle side lengths and angle totals
- Uses JavaFX to draw the selected shape
- Java
- Object-oriented programming
- Abstract classes
- Inheritance
- Polymorphism
- Method overriding
- Switch expressions
- JavaFX graphics
Compile the Java files:
javac *.javaRun the main program:
java MainJavaFX must be configured in your IDE or runtime environment for the visualizer window to display correctly.
This project helped me understand how class hierarchies can model real-world categories. A circle, triangle, rectangle, and polygon all share shape behavior, but each one calculates its measurements differently.