Given main(), define the Product class that will manage product inventory. Product class has three private member fields: a product code (String), the product's price (double), and the number count of product in inventory (int). Implement the following Constructor and member methods as listed below: • public void setCount(int num) - set the number of items in inventory to parameter num public int getCount() - return the count • public void addInventory(int amt) - increase inventory by parameter amt • public void sellinventory(int amt) - decrease inventory by parameter amt Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10 apples are added to the Product object's inventory, but then 5 are sold, the output is: Name: Apple Price: 0.40 Count: 8 Ex. If the Product object's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is: Name: Golden Delicious Price: 0.55 Count: 4 13 14 • public Product(String code, double price, int count) - set the member fields using the three parameters public void setCode(String code) - set the product code (i.e. SKU234) to parameter code • public String getCode() - return the product code public void setPrice(double p) - set the price to parameter p • public double getPrice() - return the price 1 import java.util.Scanner; 2 3 public class Product { 4 // TODO: Build Product class with private fields and methods Listed above 5 6 /* Type your code here. */ 7 8 // main 9 public static void main(String args[]) { 10 string name = "Apple"; 11 double price = 0.40; 12 15 16 17 . 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 } } int num = 3; Product prod = new Product (name, price, num); // Test 1 - Are instance variables set/returned properly? System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count:" + prod.getCount()); System.out.println(); // Test 2 - Are instance variables set/returned properly after adding and selling? num = 10; prod.addInventory (num); num = 5; prod.sellInventory (num); System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count:" + prod.getCount()); system.out.println(); // Test 3 - Do setters work properly? name = "Golden Delicious"; prod.setCode (name); price = 0.55; prod.setPrice(price); num = 4; prod.setCount (num); System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count: " + prod.getCount());
Given main(), define the Product class that will manage product inventory. Product class has three private member fields: a product code (String), the product's price (double), and the number count of product in inventory (int). Implement the following Constructor and member methods as listed below: • public void setCount(int num) - set the number of items in inventory to parameter num public int getCount() - return the count • public void addInventory(int amt) - increase inventory by parameter amt • public void sellinventory(int amt) - decrease inventory by parameter amt Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10 apples are added to the Product object's inventory, but then 5 are sold, the output is: Name: Apple Price: 0.40 Count: 8 Ex. If the Product object's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is: Name: Golden Delicious Price: 0.55 Count: 4 13 14 • public Product(String code, double price, int count) - set the member fields using the three parameters public void setCode(String code) - set the product code (i.e. SKU234) to parameter code • public String getCode() - return the product code public void setPrice(double p) - set the price to parameter p • public double getPrice() - return the price 1 import java.util.Scanner; 2 3 public class Product { 4 // TODO: Build Product class with private fields and methods Listed above 5 6 /* Type your code here. */ 7 8 // main 9 public static void main(String args[]) { 10 string name = "Apple"; 11 double price = 0.40; 12 15 16 17 . 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 } } int num = 3; Product prod = new Product (name, price, num); // Test 1 - Are instance variables set/returned properly? System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count:" + prod.getCount()); System.out.println(); // Test 2 - Are instance variables set/returned properly after adding and selling? num = 10; prod.addInventory (num); num = 5; prod.sellInventory (num); System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count:" + prod.getCount()); system.out.println(); // Test 3 - Do setters work properly? name = "Golden Delicious"; prod.setCode (name); price = 0.55; prod.setPrice(price); num = 4; prod.setCount (num); System.out.println("Name:" + prod.getCode()); System.out.printf("Price: %.2f\n", prod.getPrice()); System.out.println("Count: " + prod.getCount());
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Concept explainers
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Question
Java - Product Class
![Given main(), define the Product class that will manage product inventory. Product class has three private member fields: a product code
(String), the product's price (double), and the number count of product in inventory (int).
Implement the following Constructor and member methods as listed below:
• public void addInventory(int amt) - increase inventory by parameter amt
• public void sellInventory(int amt) - decrease inventory by parameter amt
Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is:
Name: Apple
Price: 0.40
Count: 3
Ex. If 10 apples are added to the Product object's inventory, but then 5 are sold, the output is:
Name: Apple
Price: 0.40
Count: 8
Ex. If the Product object's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is:
Name: Golden Delicious
Price: 0.55
Count: 4
5
6
1 import java.util.Scanner;
2
3 public class Product {
4
// TODO: Build Product class with private fields and methods Listed above
/* Type your code here. */
// main
public static void main(String args[]) {
string name = "Apple";
double price = 0.40;
7
8
9
• public Product(String code, double price, int count) - set the member fields using the three parameters
• public void setCode(String code) - set the product code (i.e. SKU234) to parameter code
• public String getCode() - return the product code
• public void set Price(double p) - set the price to parameter p
• public double getPrice() - return the price
10
11
• public void setCount(int num) - set the number of items in inventory to parameter num
• public int getCount() - return the count
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 }
}
int num= 3;
Product prod = new Product (name, price, num);
// Test 1 - Are instance variables set/returned properly?
System.out.println("Name: " + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());
System.out.println();
// Test 2 - Are instance variables set/returned properly after adding and selling?
num= 10;
prod.addInventory (num);
num = 5;
prod.sellInventory (num);
System.out.println("Name:" + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());
System.out.println();
// Test 3 - Do setters work properly?
name "Golden Delicious";
prod.setCode (name);
price = 0.55;
prod.setPrice (price);
num= 4;
prod.setCount (num);
System.out.println("Name: " + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F73901183-513c-4b44-b5b0-c95e8b35aeb4%2F958f13d6-5e00-4639-83ae-ccf9a6a94ac1%2Fjf3n86w_processed.png&w=3840&q=75)
Transcribed Image Text:Given main(), define the Product class that will manage product inventory. Product class has three private member fields: a product code
(String), the product's price (double), and the number count of product in inventory (int).
Implement the following Constructor and member methods as listed below:
• public void addInventory(int amt) - increase inventory by parameter amt
• public void sellInventory(int amt) - decrease inventory by parameter amt
Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is:
Name: Apple
Price: 0.40
Count: 3
Ex. If 10 apples are added to the Product object's inventory, but then 5 are sold, the output is:
Name: Apple
Price: 0.40
Count: 8
Ex. If the Product object's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is:
Name: Golden Delicious
Price: 0.55
Count: 4
5
6
1 import java.util.Scanner;
2
3 public class Product {
4
// TODO: Build Product class with private fields and methods Listed above
/* Type your code here. */
// main
public static void main(String args[]) {
string name = "Apple";
double price = 0.40;
7
8
9
• public Product(String code, double price, int count) - set the member fields using the three parameters
• public void setCode(String code) - set the product code (i.e. SKU234) to parameter code
• public String getCode() - return the product code
• public void set Price(double p) - set the price to parameter p
• public double getPrice() - return the price
10
11
• public void setCount(int num) - set the number of items in inventory to parameter num
• public int getCount() - return the count
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 }
}
int num= 3;
Product prod = new Product (name, price, num);
// Test 1 - Are instance variables set/returned properly?
System.out.println("Name: " + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());
System.out.println();
// Test 2 - Are instance variables set/returned properly after adding and selling?
num= 10;
prod.addInventory (num);
num = 5;
prod.sellInventory (num);
System.out.println("Name:" + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());
System.out.println();
// Test 3 - Do setters work properly?
name "Golden Delicious";
prod.setCode (name);
price = 0.55;
prod.setPrice (price);
num= 4;
prod.setCount (num);
System.out.println("Name: " + prod.getCode());
System.out.printf("Price: %.2f\n", prod.getPrice());
System.out.println("Count: " + prod.getCount());
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps

Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education