Exercise 5: Implement a class according to its UML class symbol: Product -name: String "price: double -scancode: int -numofobjects: int - 0 +Product (String, double) : +getName (): String...


Exercise 5: Implement a class according to its UML class symbol:<br>Product<br>-name: String<br>

Extracted text: Exercise 5: Implement a class according to its UML class symbol: Product -name: String "price: double -scancode: int -numofobjects: int - 0 +Product (String, double) : +getName (): String +getScanCode: int +getPrice (): double +change Price (double): void +getNumofobjects(): int The constructor shall take two parameters to initialise the name and price data fields. The scancode is a 4-digit integer value 1000+numofObjects that shall be calculated and initialised by the constructor. The variable numo fObjects shall be ineremented by the constructor every time a new object of type Product is instantiated. Test the defined class with the following Java program: class TestProduct ( public static void main (Stringl) args) { System.out.printin ("There are + Product.getNumofobjects () +* items."): Product pri - new Product ("Computer", 1500.0): System.out.printin ("There are + Product.getNumofobjects () +" items."): Product pr2 - new Product ("Printer", 600.0) ; Product pr3 - new Product ("Monitor", 240.0) ; System.out.println ("There are + Product.getNumofobjects () + items."); pr2.changePrice( 549.99 ): System.out.printin(" -- Product info -- "); System.out.printin( "Name:" + pr2.getName () ); System.out.printin( "Scan code: " + pr2.getScanCode () ); Systen.out.printin( "Price: " + pr2.getPrice () ): Download the TestProduct java from Moodle (in the same folder as the Lab execriese); Make sure save TestProduct.java and Product.java in the same folder; 3. 1. 2. Compile the two java programs, "javac TestProduct.java Product.java"; Execute the TestProduct program, "java TestProduct" (why the program can't be executed by using "java Product"). 4.
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here