Skip to content

Mahalakshmi-IT/OJP-Practical2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

OJP-Practical2

Constructors and the this Keyword Task 1: Creating the Product Class ● Create a Java class named Product to represent a product with attributes: productId (int), productName (String), and price (double). ● Implement a parameterized constructor that initializes these attributes. ● Use the this keyword to distinguish between instance variables and constructor parameters. ● Implement a method called displayProductInfo to display the product information (ID, name, and price). Task 2: Using the Product Class ● In the main method, create three instances of the Product class with the following data: ○ Product 1: ID = 101, Name = "Laptop", Price = 999.99 ○ Product 2: ID = 202, Name = "Smartphone", Price = 499.95 ○ Product 3: ID = 303, Name = "Tablet", Price = 299.50 ● Display the information of all three products using the displayProductInfo method. Task 3: Additional Operations ● Implement a method in the Product class to calculate and return the discountedprice of a product. Allow specifying a discount percentage. ● Create a new Product object and calculate and display the discounted price witha 10% discount. ● Modify the Product class to include a static variable for tracking the total number of products created. Implement a static method to retrieve this count. ● Display the total number of products created in the main method.

About

Constructors and the this Keyword

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors