Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: (a) Develop a Java class that represents a product as follows: The product should have a description and a price and an ID

image text in transcribed

Question 1: (a) Develop a Java class that represents a product as follows: The product should have a description and a price and an ID Apply the principle of encapsulation by making the description and price private, and provide appropriate setter and getter methods for them. Make the ID public Define a default constructor, which generates a random number for the ID, and set the price to 10, and the description to "Unknown Define the toString method for the class to return an appropriate description of the product. (b) Based on the Product class in part (a), complete the following main program: Public class Test Product Public static void main(String[] args) { //1. Create two objects, item1 and item2, with the following values. Object name item1 item2 Description Book Pencil Price 54.50 I 20 1/2. Increment the price of item1 by 10. //3. Print the total prices of item1 and item2. //4. Change the description of item 1 to "Java Book" //6. Use toString method to print item2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

gpt 2 9 .

Answered: 1 week ago

Question

Define Management or What is Management?

Answered: 1 week ago

Question

What do you understand by MBO?

Answered: 1 week ago