Java Programming Lab Lesson: Beauty Product Management System
Learning Outcome:
Write a Java application to teach the construction of an Object Oriented java program with 5 classes that uses Arrays to store and retrieve the OBJECTS.
Overview
In this lesson, we are going to construct an Object-Oriented Java program that incorporates arrays to store and retrieve objects.
An object is a BOX into which you can put business data and business processes.
We will be creating a simple beauty product management system.
The five classes we'll create include:
Product: This class will represent individual beauty products.
Category: This class will represent different categories of beauty products.
Inventory: This class will represent an inventory of beauty products.
Customer: This class will represent the customers.
Shop: This class will represent a beauty shop and serves as the main application class.
Class 1: Product
First, we define the Product class. Each product will have a name, price, and category.
publicclassProduct {
private String name;
private double price;
private Category category;
// constructor is a method that creates an object reference to a Class
// Initialize categories, products, inventory, customers and the shop
// Also, print out the details of the customers and the inventory
}
}
You can fill the main method with the appropriate initializations for the categories, products, inventory, customers, and the shop. You can also use this method to print out the details of the customers and the inventory.
This basic system can be extended further according to your needs.
The key takeaway from this lesson is the utilization of Object-Oriented concepts in Java and the use of arrays to manage and store objects.
To create a customer with a favorite product, you would need to instantiate the required objects and set up the relationships between them. Here's an example of how you can implement the main method to create a customer with their favorite product:
// Create the customer with their favorite category
Customer shakira = newCustomer("Shakira", makeup);
// Print the customer's details
System.out.println(shakira);
}
}
In this updated code, we first create the makeup category with null as the initial products array. Then, we create the lipstick and mascara products, passing the makeup category as the category for both.
After creating the products, we assign them to the makeup category using the setProducts method. Finally, we create the inventory object, and the shakira customer with the makeup category as their favorite category.
Please make sure you have the appropriate import statements and separate the classes into their respective files.
In this example, we first create the required products (lipstick and mascara) and assign them to the makeup category. Then, we create the inventory object with the makeup category.
Finally, we create the shakira customer and pass the makeup category as their favorite category. The customer's details are printed using the toString() method.
Please note that the code provided assumes you have defined the classes Product, Customer, Category, and Inventory in separate files and imported them correctly.
Final Working Code:
public class Shop {
private Inventory inventory;
private Customer[] customers;
public static void main(String[] args) {
// Create the categories
Category makeup = new Category("Makeup", null);
// Create the products
Product lipstick = new Product("Lipstick", 9.99, makeup);
Product mascara = new Product("Mascara", 12.99, makeup);
// Assign the products to the makeup category
makeup.setProducts(new Product[]{lipstick, mascara});
// Create the inventory
Inventory inventory = new Inventory(new Category[]{makeup});
// Create the customer with their favorite category
Customer shakira = new Customer("Shakira", makeup);
Customer Lilly = new Customer("Lilly", makeup);
// Print the customer's details
System.out.println(Lilly);
}
}
class Category {
private String name;
private Product[] products;