|
1 | | -# Java OOP Fundamentals |
| 1 | +# Java Basics: Control Flow |
2 | 2 |
|
3 | | - |
| 3 | + |
| 4 | +[](./LICENSE) |
4 | 5 |
|
5 | | -This repository contains Java programs demonstrating fundamental Object-Oriented Programming (OOP) concepts such as encapsulation, inheritance, and basic class design. It includes four tasks (1.1 to 1.4), each illustrating a different OOP principle. |
| 6 | +This repository contains a set of beginner-friendly Java programs demonstrating **control flow**, including looping, branching, number processing, pattern printing, and basic input/output logic. |
| 7 | + |
| 8 | +It includes **7 standalone programs**, each focusing on a fundamental Java concept. |
| 9 | + |
| 10 | +--- |
6 | 11 |
|
7 | 12 | ## 📁 Project Structure |
| 13 | + |
8 | 14 | ``` |
9 | | -src/ |
10 | | -├── Account.java |
11 | | -├── Person.java |
12 | | -├── Person_2.java |
13 | | -├── Product.java |
14 | | -├── XYZ.java |
15 | | -└── screenshots/ |
16 | | - ├── 1.1.png |
17 | | - ├── 1.2.a.png |
18 | | - ├── 1.2.b.png |
19 | | - ├── 1.3.png |
20 | | - └── 1.4.png |
| 15 | +java-basics-control-flow/ |
| 16 | +├── src/ |
| 17 | +│ ├── PrintNumberRange.java |
| 18 | +│ ├── CheckNumberSign.java |
| 19 | +│ ├── ReverseNumber.java |
| 20 | +│ ├── FindSmallestOfThree.java |
| 21 | +│ ├── DiscountCalculator.java |
| 22 | +│ ├── NumberPatternGenerator.java |
| 23 | +│ ├── NumberPatternGeneratorAlt.java |
| 24 | +├── screenshots/ |
| 25 | +│ ├── printnumrange.png |
| 26 | +│ ├── numcheck.png |
| 27 | +│ ├── reversenum.png |
| 28 | +│ ├── smallnum.png |
| 29 | +│ ├── discountcal.png |
| 30 | +│ ├── pattern.png |
| 31 | +├── LICENSE |
| 32 | +└── README.md |
21 | 33 | ``` |
22 | 34 |
|
23 | | -## 📝 Task Overviews |
| 35 | +--- |
| 36 | + |
| 37 | +## 📝 Program Overviews |
24 | 38 |
|
25 | | -### **Task 1.1 — Person Class** |
26 | | -- Implements a `Person` class with `name` and `age`. |
27 | | -- Default age is **18**. |
28 | | -- Includes constructor + method to display info. |
| 39 | +### **1️⃣ PrintNumberRange.java** |
| 40 | +Prints numbers from **10 to 50** using a loop. |
29 | 41 |
|
30 | | -▶️ **Screenshot:** |
31 | | - |
| 42 | +📸 Screenshot: |
| 43 | + |
32 | 44 |
|
33 | 45 | --- |
34 | 46 |
|
35 | | -### **Task 1.2 — Product Class** |
36 | | -- Represents products with `pid`, `price`, and `quantity`. |
37 | | -- `ProductMain`: |
38 | | - - Accepts **5 products**. |
39 | | - - Finds **highest price product**. |
40 | | - - Calculates **total expenditure**. |
| 47 | +### **2️⃣ CheckNumberSign.java** |
| 48 | +Checks whether a number is **positive** or **negative**. |
41 | 49 |
|
42 | | -▶️ **Screenshots:** |
43 | | - |
44 | | - |
| 50 | +📸 Screenshot: |
| 51 | + |
45 | 52 |
|
46 | 53 | --- |
47 | 54 |
|
48 | | -### **Task 1.3 — Account Class** |
49 | | -- Implements `deposit`, `withdraw`, and `display` methods. |
50 | | -- Includes default + parameterized constructors. |
| 55 | +### **3️⃣ ReverseNumber.java** |
| 56 | +Reverses digits in a number |
| 57 | +Example: `876 → 678` |
51 | 58 |
|
52 | | -▶️ **Screenshot:** |
53 | | - |
| 59 | +📸 Screenshot: |
| 60 | + |
54 | 61 |
|
55 | 62 | --- |
56 | 63 |
|
57 | | -### **Task 1.4 — Inheritance (Person → Employee)** |
58 | | -- `Employee` extends `Person`. |
59 | | -- Adds `employeeID` and `salary`. |
60 | | -- Uses `super()` for parent initialization. |
| 64 | +### **4️⃣ FindSmallestOfThree.java** |
| 65 | +Inputs three numbers and prints the **smallest**. |
61 | 66 |
|
62 | | -▶️ **Screenshot:** |
63 | | - |
| 67 | +📸 Screenshot: |
| 68 | + |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### **5️⃣ DiscountCalculator.java** |
| 73 | +Applies a discount based on purchase amount: |
| 74 | + |
| 75 | +| Amount Range | Discount | |
| 76 | +|--------------|----------| |
| 77 | +| < 500 | 0% | |
| 78 | +| 500–1000 | 10% | |
| 79 | +| > 1000 | 20% | |
| 80 | + |
| 81 | +📸 Screenshot: |
| 82 | + |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +### **6️⃣ NumberPatternGenerator.java** |
| 87 | +Prints a number-based pattern using loops. |
| 88 | + |
| 89 | +📸 Screenshot: |
| 90 | + |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +### **7️⃣ NumberPatternGeneratorAlt.java** |
| 95 | +Alternative implementation of the number pattern. |
64 | 96 |
|
65 | 97 | --- |
66 | 98 |
|
67 | 99 | ## ▶️ Running the Programs |
68 | 100 |
|
69 | | -### **1. Clone the Repository** |
| 101 | +### Clone Repository |
70 | 102 | ```bash |
71 | | -git clone https://github.com/TheComputationalCore/java-oop-fundamentals.git |
72 | | -cd java-oop-fundamentals/src |
| 103 | +git clone https://github.com/TheComputationalCore/java-basics-control-flow.git |
| 104 | +cd java-basics-control-flow/src |
73 | 105 | ``` |
74 | 106 |
|
75 | | -### **2. Compile** |
| 107 | +### Compile All Programs |
76 | 108 | ```bash |
77 | 109 | javac *.java |
78 | 110 | ``` |
79 | 111 |
|
80 | | -### **3. Run (examples)** |
| 112 | +### Run a Specific Program |
81 | 113 | ```bash |
82 | | -java Person |
83 | | -java Product |
84 | | -java Account |
85 | | -java XYZ |
| 114 | +java PrintNumberRange |
| 115 | +java CheckNumberSign |
| 116 | +java ReverseNumber |
| 117 | +java FindSmallestOfThree |
| 118 | +java DiscountCalculator |
| 119 | +java NumberPatternGenerator |
86 | 120 | ``` |
87 | 121 |
|
88 | 122 | --- |
89 | 123 |
|
90 | | -## 📦 Requirements |
91 | | -- Java JDK **8 or higher** |
92 | | -- Any terminal or Java IDE |
| 124 | +## 🛠 Requirements |
| 125 | +- Java **JDK 8 or higher** |
| 126 | +- Any Java IDE or terminal |
93 | 127 |
|
94 | 128 | --- |
95 | 129 |
|
96 | | -## 📄 License |
97 | | -This project is licensed under the MIT License. |
| 130 | +## 📄 License |
| 131 | +This project is licensed under the **MIT License**. |
| 132 | + |
0 commit comments