Question: Write a program that accepts product information ( name , SKU, and price ) for different products and performs validation using regular expressions. You will

Write a program that accepts product information (name, SKU, and price) for different products and
performs validation using regular expressions. You will also implement a class that extends the main
product class and adds additional functionality for specific product types.
Create a doc file for the program (all classes)
This Java program, is designed to capture and validate information about Product using regular
expressions.
1- Create a parent class name LastNameFirstNameProductHw3.java
Create a class name LastNameFirstNameProductHw2.java class with the
following:
A public field for productName.
A private field for price.
A protected field for sku.
Implement a constructor that takes three parameters: productName, price,
and sku.
Write getter methods for price and sku
Add a method to display product information.
2- OtherProducts Class (Inheritance):
Create a subclass for OtherProducts name
(LastNameFirstNameOtherProductHw2.java) that extends the Parent class.
Add a field called type to indicate the type of product. The type should be one
of the following categories: women, men, children etc ....
Override the toString() method to include additional product information like
the type (e.g., "Product is for women")
3- Main Class (Input and Validation):
Create a main class name (LastNameFirstNameProductInformationHW3.java)
that:
Accepts user input for product details (name, SKU, and price), use Scanner
Declare variable
The program prompts the user to enter the product name for the "Boots"
product, and store it in a variable
Use a Pattern.compile(has regular expression) with regular expressions
Uses regular expressions to validate the SKU for Boots and Sandals.
Boots SKU format: "Boots 1234", That is start with B should be uppercase
followed by oo[2 os] followed by ts followed by space followed by 4 digits.
The program enters a loop (you can use while loop) where it repeatedly asks
the user to enter an SKU for the Boots product in the format "Boots 1234".
Use a matcher
The input is checked against the pattern regular expression.
If the input matches, the message "Boots name matches!" is displayed, and
the loop ends. By making the Boolean variable =false
If the input doesnt match, the user is informed that the SKU is invalid, and
they are prompted to enter it again.
End of while loop
To obtain price of the Boots will be by calling a method that need to be
created in the main class(LastNameFirstNameProductInformationHW2.java)
Use group(int) to get the word Boots, assign it to a variable
For Sandals will be same process as for Boots
The user is prompted to enter the product name for Sandals, and store it in a
variable.
Use a Pattern.compile(has regular expression) with regular expressions
Sandals SKU format: "Sandals" or "sandals" (case-insensitive). "Sandals-1234"
or "sandals-1234", that is start with S uppercase or s small case followed by
hyphen followed by 4 digits.
A loop similar to the Boots input loop, but this time it checks the SKU for
Sandals.
The user is asked to enter the SKU, and it is validated against the pattern
If the input matches, the loop exits, By making the Boolean variable equals to
false
If the input doesnt match, the user is asked to try again.
End of while loop
To obtain price of the Sandals will be by calling a method that need to be
created in the main class(LastNameFirstNameProductInformationHW2.java)
Use group(int) to get the word Sandals, assign it to a variable
Create boots and sandal objects by calling the Parent Constructor
Call the display method. You might need to use try and catch, If invalid inputs
were provided, an IllegalArgumentException is thrown, and the error message
is printed.
Handling Third Product
The program allows the user to input the details for a third product, which
should either be "Boots" or "Sandals".
Use while loop
Enter product name
Depending on the product name, the SKU pattern and type are set
accordingly.
If the name doesn't contain "Boots" or "Sandals"[use if statement to check the
product name with variable that we assign from group(in)]
Depending on the product name, the SKU pattern and type are set accordingly.
If the name doesn't contain "Boots" or "Sandals", the user is prompted to
enter the correct product name.
End loop
To obtain price of the Sandals will be by calling a method that need to be
created in the main class(LastNameFirstNameProductInformationHW2.java)
Create an object using the subclass constructor.
displayed using the overridden toString() from the subclass.
You might need to use try and catch, If an invalid input is encountered (e.g., an
invalid SKU or price), an IllegalArgumentException is thrown, and an error
message is printed.
Outside main method creating a price match method that will return a String
and it has 2 parameters, String for price and second parameter variable for
Pattern
This method is used to ensure that the price ente

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!