Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
•
Four fields: id with type int, name of type string, nbStocks of type int and price
of type double.
•A static variable NbArticle that computes the number of Stock objects.
•A constructor that creates a Stock with the specified id, name, nbStocks and price.
•The getter and setter methods.
Object Oriented Design &
Programming
•Two methods named DecrementStock() and IncrementStock() that decrement
and increment respectively by one the number of a Stock.
•A method named changePrice(int percent) that change the price of a Stock
according to the corresponding percent given by its argument and returns the
new price.
•A method named ToString() that displays the information of a Stock.
•Draw the UML diagram for the class.
•Write a test program that creates a Stock with arguments given by the user.
•Display the number of created Stocks.
•Decrement by 2 the number of Stock and then display the number of Stocks.
•Increment by 1 the number Stock and then display the number of Stocks.
•Add the price of Stock by 20% and then display the new price.
•Display the final information of the Stock.


What I have tried:

Hello, Please How can I solve this question
Posted
Updated 10-Dec-21 2:10am

Java
class Stock {
    int id;
    string name;
    int nbStocks;
    double price;
    static NbArticle = 0; // increment this in the constructor to count the objects.
    public Stock(int id, string name, int nbStocks, double price) {
        // use the setters to initialise the object
    }
}
 
Share this answer
 
v2
Sorry - we don't do homework for you. It doesn't help anyone, especially you.
Try reading this article How to Write Code to Solve a Problem, A Beginner's Guide[^] , then write some code. By all means return here with that code if you hit any problems
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900