https://github.com/rezoanulhasan/php-oop-basic
https://github.com/rezoanulhasan/php-oop-basic
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rezoanulhasan/php-oop-basic
- Owner: RezoanulHasan
- Created: 2023-10-04T00:14:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-04T00:17:52.000Z (almost 2 years ago)
- Last Synced: 2025-01-08T06:30:28.319Z (6 months ago)
- Language: PHP
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phpoopbasic
working on a project to create an online shopping cart system. As part of the project, you need to implement a Product class that represents a product in the system. The Product class should have the following properties:
- id (integer type): the unique identifier of the product
- name (string type): the name of the product
- price (float type): the price of the productIn addition to the properties, the Product class should also have the following methods:
1. __construct: a constructor method that takes the id, name, and price as parameters and initializes the corresponding properties of the object.
2. getFormattedPrice: a method that returns the price of the product formatted as a string with two decimal places.
3. showDetails: a method that prints the details of the product (id, name, and formatted price) to the console.
Your task is to write the implementation of the Product class in PHP. Use the provided template code below and fill in the missing parts:
php
class Product {
// TODO: Add properties
public function __construct($id, $name, $price) {
// TODO: Initialize properties
}// TODO: Add getFormattedPrice method
// TODO: Add showDetails method
}// Test the Product class
$product = new Product(1, 'T-shirt', 19.99);
$product->showDetails();Expected Output:
Product Details:
- ID: 1
- Name: T-shirt
- Price: $19.99