FOR JAVA
Create a class named Product that has ID, price and stock as fields. This class must have two constructors; one constructor must take all its fields as parameters, second constructor must take ID and price as parameters and set stock to 0. Also implement the following methods:
• String toString(): Returns a brief summary about the object.
• void sell(int): Takes a parameter that represents the amount to sell. Checks if stocks are sufficient. If so, it updates the stock and prints the total price. Else it prints a warning to user.
Create 3 instances of Product class and test your methods.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here