Question: Implement a class according to its UML class symbol: Product -name: String -price: double -scanCode: int -numObjects: int = 0 +Product (String, double) +getName(): String

Implement a class according to its UML class symbol: Product -name: String -price: double -scanCode: int -numObjects: int = 0 +Product (String, double) +getName(): String +getScanCode: int +getPrice(): double +changePrice (double): void +getNumObjects(): int +getNumberInstock(): int The constructor shall take two parameters to initialise the name and price fields. The variable numObjects shall be incremented by the constructor every time a new object is instattiated. The scanCode is a 4-digit integer value 1000 +numObjects initialised by the constructor. Test the defined class with the following program: class TestProduct {public static void main (String[] args) {System.out.println ("There are " + Product.getNumberInStock() + "items"); Product pr1 = new Product ("Computer", 1500.0); System.out.println ("There are" + Product.getNumberInstock() + "items"); Product pr2 = new Product ("Printer", 600.0); Product pr3 = new Product ("Monitor", 240.0); System.out.println ("There are" + Product.getNumberInstock() + "items")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
