Exercise 5: Implement a class according to its UML class symbol: Product -name: String "price: double -scancode: int "numofobjecta: 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 acancode is a 4-digit integer value 1000+numofobjects that shall be calculated and initialised by the constructor. The variable numofobjects shall be incremented by the constructor every time a new objoct of type Product is instantiated.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question
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.
Transcribed Image 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.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage