|
1 | | -# Java OOP Task 2 |
2 | | - |
3 | | -This repository contains Java programs demonstrating fundamental Object-Oriented Programming (OOP) concepts such as encapsulation, inheritance, and class design. The project includes solutions to four tasks (1.1 to 1.4) that involve creating classes like `Person`, `Product`, `Account`, and an inheritance example with `Employee`. |
4 | | - |
5 | | -## Project Structure |
6 | | - |
7 | | -- **Person.java**: Implements a `Person` class with name and age properties (Task 1.1). |
8 | | -- **Person2.java**: Likely an updated or alternative version of the `Person` class. |
9 | | -- **Product.java**: Defines a `Product` class with a main class to handle product data (Task 1.2). |
10 | | -- **Account.java**: Implements an `Account` class with balance management (Task 1.3). |
11 | | -- **XYZ.java**: Contains inheritance example with `Person` and `Employee` classes (Task 1.4). |
12 | | -- **1.1.png, 1.2_a.png, 1.2_b.png, 1.3.png, 1.4.png**: Screenshots of the code implementations for each task. |
13 | | - |
14 | | -## Tasks Overview |
15 | | - |
16 | | -### Task 1.1: Person Class |
17 | | -- Creates a `Person` class with properties `name` and `age`. |
18 | | -- Default age is set to 18. |
19 | | -- Includes a constructor to initialize name and age, and a method to display them. |
20 | | - |
21 | | -### Task 1.2: Product Class |
22 | | -- Defines a `Product` class with properties `pid`, `price`, and `quantity`. |
23 | | -- Includes a main class (`ProductMain`) that: |
24 | | - - Accepts information for 5 products and stores them in an array. |
25 | | - - Finds the product with the highest price. |
26 | | - - Calculates the total amount spent on all products (price * quantity). |
27 | | - |
28 | | -### Task 1.3: Account Class |
29 | | -- Implements an `Account` class with a `balance` property. |
30 | | -- Provides two constructors (default and parameterized). |
31 | | -- Includes methods to deposit, withdraw, and display the balance. |
32 | | - |
33 | | -### Task 1.4: Inheritance with Person and Employee |
34 | | -- Defines a base class `Person` with `name` and `age`. |
35 | | -- Creates a subclass `Employee` that inherits from `Person` and adds `employeeID` and `salary`. |
36 | | -- Uses the `super` keyword to initialize `Person` attributes in the `Employee` constructor. |
37 | | - |
38 | | -## How to Run |
39 | | - |
40 | | -1. **Clone the Repository**: |
41 | | - ```bash |
42 | | - git clone https://github.com/thesoulseizure/task-2.git |
43 | | - ``` |
44 | | -2. **Navigate to the Project Directory**: |
45 | | - ```bash |
46 | | - cd task-2 |
47 | | - ``` |
48 | | -3. **Compile the Java Files**: |
49 | | - ```bash |
50 | | - javac *.java |
51 | | - ``` |
52 | | -4. **Run the Desired Program**: |
53 | | - - For Task 1.1: `java Person` |
54 | | - - For Task 1.2: `java Product` |
55 | | - - For Task 1.3: `java Account` |
56 | | - - For Task 1.4: `java XYZ` |
57 | | - |
58 | | -## Requirements |
59 | | - |
60 | | -- Java Development Kit (JDK) 8 or higher. |
61 | | -- A terminal or IDE to compile and run Java programs. |
62 | | - |
63 | | -## Screenshots |
64 | | - |
65 | | -The repository includes screenshots (1.1.png to 1.4.png) that show the code implementations for each task. Refer to these images to view the solutions visually. |
| 1 | +# Java OOP Foundations |
| 2 | + |
| 3 | +This repository contains Java programs demonstrating fundamental Object-Oriented Programming (OOP) concepts such as encapsulation, constructors, inheritance, and class design. It includes four foundational tasks (1.1 to 1.4), each focusing on a specific OOP principle. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 📌 Project Structure |
| 8 | + |
| 9 | +``` |
| 10 | +java-oop-foundations/ |
| 11 | +├── Account.java # Task 1.3 – Account class with deposit/withdraw operations |
| 12 | +├── Person.java # Task 1.1 – Basic Person class |
| 13 | +├── Person_2.java # Updated/alternate Person version |
| 14 | +├── Product.java # Task 1.2 – Product class & product management logic |
| 15 | +├── XYZ.java # Task 1.4 – Inheritance example (Person → Employee) |
| 16 | +├── screenshots/ # Output/code screenshots for all tasks |
| 17 | +│ ├── 1.1.png |
| 18 | +│ ├── 1.2.a.png |
| 19 | +│ ├── 1.2.b.png |
| 20 | +│ ├── 1.3.png |
| 21 | +│ ├── 1.4.png |
| 22 | +└── README.md |
| 23 | +``` |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 📘 Task Overview |
| 28 | + |
| 29 | +### **🧩 Task 1.1 — Person Class** |
| 30 | +- Defines a `Person` with `name` and `age`. |
| 31 | +- Default age is set to **18**. |
| 32 | +- Features: |
| 33 | + - Constructor initialization |
| 34 | + - Display method |
| 35 | +- 📸 Screenshot: `screenshots/1.1.png` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +### **🛒 Task 1.2 — Product Class** |
| 40 | +- Contains product fields: `pid`, `price`, `quantity`. |
| 41 | +- Includes a main program that: |
| 42 | + - Accepts **5 products** |
| 43 | + - Finds the **highest-priced product** |
| 44 | + - Calculates **total spending = price × quantity** |
| 45 | +- 📸 Screenshots: |
| 46 | + - `screenshots/1.2.a.png` |
| 47 | + - `screenshots/1.2.b.png` |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### **🏦 Task 1.3 — Account Class** |
| 52 | +- Demonstrates encapsulation with: |
| 53 | + - `balance` field |
| 54 | + - Default & parameterized constructors |
| 55 | + - `deposit()`, `withdraw()`, `displayBalance()` |
| 56 | +- 📸 Screenshot: `screenshots/1.3.png` |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +### **🧑💼 Task 1.4 — Inheritance (Person → Employee)** |
| 61 | +- `Employee` extends `Person` |
| 62 | +- Adds: |
| 63 | + - `employeeID` |
| 64 | + - `salary` |
| 65 | +- Uses `super()` to initialize parent class data. |
| 66 | +- 📸 Screenshot: `screenshots/1.4.png` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## ▶️ Running the Programs |
| 71 | + |
| 72 | +### **Clone Repository** |
| 73 | +```bash |
| 74 | +git clone https://github.com/TheComputationalCore/java-oop-foundations.git |
| 75 | +cd java-oop-foundations |
| 76 | +``` |
| 77 | + |
| 78 | +### **Compile** |
| 79 | +```bash |
| 80 | +javac *.java |
| 81 | +``` |
| 82 | + |
| 83 | +### **Run** |
| 84 | +```bash |
| 85 | +java Person # Task 1.1 |
| 86 | +java Product # Task 1.2 |
| 87 | +java Account # Task 1.3 |
| 88 | +java XYZ # Task 1.4 |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## 🛠 Requirements |
| 94 | +- **JDK 8 or higher** |
| 95 | +- Any Java IDE or terminal with javac |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## 🖼 Screenshots |
| 100 | +Stored inside: `/screenshots` |
| 101 | + |
| 102 | +``` |
| 103 | +1.1.png – Person class |
| 104 | +1.2.a.png – Product class part A |
| 105 | +1.2.b.png – Product class part B |
| 106 | +1.3.png – Account class |
| 107 | +1.4.png – Inheritance example |
| 108 | +``` |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## ✔️ Notes |
| 113 | +This repository focuses on essential OOP concepts and serves as a solid foundation for more advanced Java development. |
| 114 | + |
0 commit comments