Question: IN PHP 1. Create a class called Person that has the following attributes: name (a string) age (an integer) gender (a string) The class should
IN PHP
1. Create a class called Person that has the following attributes:
name (a string)
age (an integer)
gender (a string)
The class should have the following methods:
setName($name): This method should set the name of the person.
setAge($age): This method should set the age of the person.
setGender($gender): This method should set the gender of the person.
getName(): This method should return the name of the person.
getAge(): This method should return the age of the person.
getGender(): This method should return the gender of the person.
Create a PHP class called Employee that extends the Person class and has the following additional attributes:
id (an integer)
position (a string)
salary (a float)
The class should have the following methods:
setId($id): This method should set the id of the employee.
setPosition($position): This method should set the position of the employee.
setSalary($salary): This method should set the salary of the employee.
getId(): This method should return the id of the employee.
getPosition(): This method should return the position of the employee.
getSalary(): This method should return the salary of the employee.
Create a PHP class called Manager that extends the Employee class and has the following additional attribute:
bonus (a float)
The class should have the following methods:
setBonus($bonus): This method should set the bonus of the manager.
getBonus(): This method should return the bonus of the manager.
In the Main file, create two Employee objects and two Manager objects, set their attributes, and demonstrate the use of each of the methods.
Hint: You can use the parent keyword to call a method from the parent class.
2. Create a PHP class called Shape that has the following attribute:
name (a string)
The class should have the following methods:
setName($name): This method should set the name of the shape.
getName(): This method should return the name of the shape.
calculateArea(): This method should be an abstract method that returns the area of the shape.
Create two PHP classes called Circle and Rectangle that extend the Shape class. The Circle class should have the following attributes:
radius (a float)
The class should have the following methods:
setRadius($radius): This method should set the radius of the circle.
getRadius(): This method should return the radius of the circle.
calculateArea(): This method should calculate and return the area of the circle.
The Rectangle class should have the following attributes:
length (a float)
width (a float)
The class should have the following methods:
setLength($length): This method should set the length of the rectangle.
setWidth($width): This method should set the width of the rectangle.
getLength(): This method should return the length of the rectangle.
getWidth(): This method should return the width of the rectangle.
calculateArea(): This method should calculate and return the area of the rectangle.
In the Main file, create one Circle object and one Rectangle object, set their attributes, and call the calculateArea() method on each object.
3. Create an interface called ShapeInterface that has the following method:
calculateArea(): This method should be an abstract method that calculates and returns the area of the shape.
Create an abstract class called Shape that implements the ShapeInterface interface and has the following attributes:
name (a string)
The class should have the following methods:
setName($name): This method should set the name of the shape.
getName(): This method should return the name of the shape.
Create two classes called Circle and Rectangle that extend the Shape class. The Circle class should have the following attributes:
radius (a float)
The class should have the following methods:
setRadius($radius): This method should set the radius of the circle.
getRadius(): This method should return the radius of the circle.
calculateArea(): This method should calculate and return the area of the circle.
The Rectangle class should have the following attributes:
length (a float)
width (a float)
The class should have the following methods:
setLength($length): This method should set the length of the rectangle.
setWidth($width): This method should set the width of the rectangle.
getLength(): This method should return the length of the rectangle.
getWidth(): This method should return the width of the rectangle.
calculateArea(): This method should calculate and return the area of the rectangle.
In the Main file, create one Circle object and one Rectangle object, set their attributes, and call the calculateArea() method on each object.
4. Create a class called User that has the following attributes:
name (a string)
email (a string)
The class should have the following methods:
setName($name): This method should set the name of the user.
setEmail($email): This method should set the email of the user.
getName(): This method should return the name of the user.
getEmail(): This method should return the email of the user.
Create a class called Admin that extends the User class. The Admin class should have the following methods:
deleteUser($user): This method should delete a user object from an array of users.
createUser($name, $email): This method should create a new user object and add it to an array of users.
updateUser($user, $name, $email): This method should update the name and email attributes of a user object in an array of users.
In the Main file, create an array of User objects and one Admin object. Use the Admin object to add, delete, and update User objects in the array.
5. Create a class called Vehicle that has the following attributes:
make (a string)
model (a string)
year (an integer)
color (a string)
engine (an object of class Engine)
The class should have the following methods:
setMake($make): This method should set the make of the vehicle.
setModel($model): This method should set the model of the vehicle.
setYear($year): This method should set the year of the vehicle.
setColor($color): This method should set the color of the vehicle.
setEngine($engine): This method should set the engine of the vehicle.
getMake(): This method should return the make of the vehicle.
getModel(): This method should return the model of the vehicle.
getYear(): This method should return the year of the vehicle.
getColor(): This method should return the color of the vehicle.
getEngine(): This method should return the engine of the vehicle.
Create a class called Engine that has the following attributes:
type (a string)
displacement (an integer)
horsepower (an integer)
The class should have the following methods:
setType($type): This method should set the type of the engine.
setDisplacement($displacement): This method should set the displacement of the engine.
setHorsepower($horsepower): This method should set the horsepower of the engine.
getType(): This method should return the type of the engine.
getDisplacement(): This method should return the displacement of the engine.
getHorsepower(): This method should return the horsepower of the engine.
Create a new instance of the Vehicle class and set its attributes to some values. Then, create a new instance of the Engine class, set its attributes to some values, and set the engine attribute of the Vehicle instance to the new Engine instance. Finally, print out the make, model, year, color, type, displacement, and horsepower of the Vehicle instance.
6. Create a class called "Person" that has the following properties:
firstName (string)
lastName (string)
age (integer)
The class should have the following methods:
setFirstName($firstName): This method should set the person's first name.
setLastName($lastName): This method should set the person's last name.
setAge($age): This method should set the person's age.
getFirstName(): This method should return the person's first name.
getLastName(): This method should return the person's last name.
getAge(): This method should return the person's age.
Create a new instance of the "Person" class and set its properties to some values. Then, use the "getFirstName()", "getLastName()", and "getAge()" methods to print out the person's full name and age.
Next, create a new class called "Student" that extends the "Person" class. The "Student" class should have the following properties in addition to the "Person" properties:
gradeLevel (integer)
gpa (float)
The "Student" class should also have the following methods:
setGradeLevel($gradeLevel): This method should set the student's grade level.
setGpa($gpa): This method should set the student's GPA.
getGradeLevel(): This method should return the student's grade level.
getGpa(): This method should return the student's GPA.
Create a new instance of the "Student" class and set its properties to some values. Then, use the "getFirstName()", "getLastName()", "getAge()", "getGradeLevel()", and "getGpa()" methods to print out the student's full name, age, grade level, and GPA.
Finally, create a new class called "Teacher" that also extends the "Person" class. The "Teacher" class should have the following properties in addition to the "Person" properties:
subject (string)
yearsTeaching (integer)
The "Teacher" class should also have the following methods:
setSubject($subject): This method should set the teacher's subject.
setYearsTeaching($yearsTeaching): This method should set the number of years the teacher has been teaching.
getSubject(): This method should return the teacher's subject.
getYearsTeaching(): This method should return the number of years the teacher has been teaching.
Create a new instance of the "Teacher" class and set its properties to some values. Then, use the "getFirstName()", "getLastName()", "getAge()", "getSubject()", and "getYearsTeaching()" methods to print out the teacher's full name, age, subject, and years of teaching experience.
7. Create a PHP class called "BankAccount" that has the following properties:
accountNumber (string)
accountHolderName (string)
balance (float)
The class should have the following methods:
deposit($amount): This method should add the given amount to the account's balance.
withdraw($amount): This method should subtract the given amount from the account's balance, but only if the account has enough funds.
getBalance(): This method should return the account's current balance.
Create a new instance of the "BankAccount" class and set its properties to some values. Then, use the "deposit()", "withdraw()", and "getBalance()" methods to perform some transactions and print out the account's balance.
Next, create a PHP class called "SavingsAccount" that extends the "BankAccount" class. The "SavingsAccount" class should have an additional property called "interestRate" (float) and should have the following methods:
setInterestRate($interestRate): This method should set the interest rate of the savings account.
getInterestRate(): This method should return the interest rate of the savings account.
addInterest(): This method should calculate the interest earned on the account's balance based on the interest rate and add it to the balance.
Create a new instance of the "SavingsAccount" class and set its properties to some values. Then, use the "setInterestRate()", "addInterest()", and "getBalance()" methods to calculate and print out the account's balance after earning some interest.
Finally, create a PHP class called "CheckingAccount" that extends the "BankAccount" class. The "CheckingAccount" class should have an additional property called "transactionFee" (float) and should have the following methods:
setTransactionFee($transactionFee): This method should set the transaction fee for withdrawals.
getTransactionFee(): This method should return the transaction fee for withdrawals.
withdraw($amount): This method should override the "withdraw()" method of the "BankAccount" class to subtract the transaction fee from the account's balance for each withdrawal.
Create a new instance of the "CheckingAccount" class and set its properties to some values. Then, use the "withdraw()", "getTransactionFee()", and "getBalance()" methods to perform some transactions and print out the account's balance after deducting transaction fees.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
