Question: Constructor ( 3 Parameters ) : The constructor should accept the item's name, cost, and price as arguments and assign these values to the object's

Constructor (3 Parameters):
The constructor should accept the item's name, cost, and price as arguments and assign
these values to the object's corresponding instance variables.
The constructor should also initialize weight to 1.0 kg and taxable to true by default.
Note: Ensure that the constructor does not allow negative values for the price or cost. If
negative values are passed, set them to 0 and print an appropriate error message.
Add Accessor and Mutator Methods:
Provide getter and setter methods for all instance variables.
Ensure that the setter methods for price, cost, and weight do not allow negative values.
Add the increaseCost () Method:
This method should increase the cost price of the item by 5% each time it is called. This is a
void method as it modifies the current state of the object.
Add the profit() Method:
This method should accept no parameters and return the profit of the item, which is calculated
as the selling price minus the cost price. Note: Ignore taxes in this calculation.
Add the toString () Method:
This method should display the contents of the item's instance variables in a well-formatted
string. For example:
"Item: Desk Chair, Price: 30.0 AED, Cost: 55.0 AED, Weight: 3.0 kg , Taxable: true"
Constructor ( 3 Parameters ) : The constructor

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!