Commit 104f008
committed
feat: Add Cylindertest1 with basic geometry methods for cylinders
WHAT the code does:
Defines Cylindertest1 with public fields radius and height.
Implements geometry methods:
- lidArea(): returns area of the circular lid (πr²).
- circumference(): returns circumference of the base circle (2πr).
- totalSurfaceArea(): computes total surface area (2πr² + 2πrh).
- volume(): currently returns only lidArea() instead of πr²h.
Defines CylinderTest with main():
- Creates a cylinder object with radius = 7 and height = 10.
- Prints lid area, total surface area, and volume.
WHY this matters:
Demonstrates how to model a cylinder with fields and methods in Java.
Highlights the bundling of state (radius, height) and behavior (area, surface, volume).
Shows how mathematical formulas can be encapsulated in methods for reusability.
Provides an accessible educational example of class and object usage.
HOW it works:
lidArea() computes πr² = 153.938...
circumference() computes 2πr = 43.982...
totalSurfaceArea() adds two lid areas + lateral surface = 2πr² + 2πrh.
main() sets radius and height, then prints computed results.
Tips and gotchas:
The volume() method is incorrect; it should be πr²h, not just lidArea().
radius and height are public, which breaks encapsulation. Prefer private fields with getters and setters.
Method naming consistency matters: totalSurfaceArea is clear, but lidArea could be renamed baseArea for symmetry.
Using double precision is fine for small examples, but rounding/formatting may be needed for real-world output.
Use-cases:
Educational demo of geometry modeling in Java.
Foundation for math/physics simulation applications.
Can evolve into an encapsulated, validated design with constructors and private fields.
Short key: class-cylindertest1 cylinder-geometry area-surface-volume.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent dec4f0e commit 104f008
1 file changed
+8
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | | - | |
7 | | - | |
| 5 | + | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
11 | | - | |
| 8 | + | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
| 12 | + | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | | - | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
| |||
0 commit comments