Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rezoanulhasan/php-oop-basic
https://github.com/rezoanulhasan/php-oop-basic
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rezoanulhasan/php-oop-basic
- Owner: RezoanulHasan
- Created: 2023-10-04T00:14:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-04T00:17:52.000Z (about 1 year ago)
- Last Synced: 2024-11-10T19:31:03.583Z (6 days 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