OOP Lab02 ProblemModelingEncapsulation
OOP Lab02 ProblemModelingEncapsulation
Object-Oriented Programming
Lecturer: NGUYEN Thi Thu Trang, trangntt@soict.hust.edu.vn
Teaching Assistant: TRINH Thu Hai, hai.tt184255@sis.hust.edu.vn
0. Assignment Submission
For this lab class, you will have to turn in your work twice, specifically:
ÿ Right after the class: for this deadline, you should include any work you have done within the lab
class.
ÿ 10PM two days after the class: for this deadline, you should include the final use case diagram, the
final class diagram, the source code of all sections of this lab, and the reading assignment in a directory
named “Lab02”. Note that for the use case diagram, submit both source file (.astah) and its exported
image (.png) in the folder named “Requirement”; for the class diagram, also submit both source file
(.astah) and its exported image file (.png) in the folder named “Design”; for the reading assignment,
submit an image file of the reading assignment in the folder named “ReadingAssignment”, put all into
a directory named “Lab02” and push it to your master branch of the valid repository.
Note that all sample codes or diagrams in the lab are only the examples/suggestions. You may need to change
them to satisfy the requirements. Each student is expected to turn in his or her own work and not give or receive
unpermitted aid. Otherwise, we would apply extreme methods for measurement to prevent cheating. Please
write down answers for all questions into a text file named “answers.txt” and submit it within your repository.
Astah is a design tool which supports UML. To get Astah UML, go to http://astah.net/student-license- request,
fill the form, and send the request. Then follow the 3 steps in the redirected page http://astah.net/student/thank-
you. See use case diagram with Astah at http://astah.net/manual/422-usecase-diagram.
Try to draw some several UML diagrams in the Astah UML, such as class diagram, activity diagram, sequence
diagram.
Page 1 of 12
Machine Translated by Google
There might be a future that Tiki and Sendo be in talks over a potential merger to contend other e-commerce platforms and
especially those who have foreign backers. The merger of these two firms will create a Ti-do company, where “Ti” is from Tiki, and
“do” is from Sendo, which means a billion-dollar company in Vietnamese. That company, Ti-do company, would like you to help
them create a brand-new system for AIMS project (AIMS stands for An Internet Media Store). Currently, there is only one type of
media: Digital Video Disc (DVD).
Customers can browse the list of DVDs available in the store, the display order is based on their added date, from latest to
oldest. When a customer wants to search for DVDs to add to cart, he or she can choose one of three searching options. The
software will display a list of all matches (latest DVDs first) with all their information. He or she can also choose to play a specific
DVD. The software will play a DVD (a demo part). If a DVD has the length 0 or less, the system must notify the customer that the
DVD cannot be played.
o When a customer searches for DVDs by title, he or she provides a string of keywords. If any DVD has the title containing
any word in the string of keywords, it is counted as a match. Note that the comparison of words here is case-
insensitive.
o When a customer searches for DVDs by category, he or she provides the category name. If any
DVD has the matching category (case-insensitive), it is counted as a match.
o When a customer searches for DVDs by price, he or she provides either the minimum and maximum cost, or just the
maximum cost.
Customers can view the detailed information of a DVD from the list of DVDs. He/she can add a big DVD
a cart from a list of DVDs or the detailed screen.
When a customer wants to see the current cart, the system displays all the information of the DVDs, along with the total cost.
Customers may listen to a DVD (a demo part) in the cart before confirming to place an order. Customers can sort all DVDs in the
cart by title or by cost:
o Sort by title: the system displays all the DVDs in the alphabet sequence by title. In case they
have the same title, the DVDs having the higher cost will be displayed first.
o Sort by cost: the system the system displays all the DVDs in decreasing cost order. In case they
have the same cost, the DVDs will be ordered by increasing title.
Customers can update the quantity of a DVD in a cart or remove a DVD from a cart. To increase consumer demand for the
product and grow sales, customers are allowed to have an item for free which is randomly picked out in the cart by the system.
Customers can filter DVDs in the cart by providing either its ID or title. If the item is found, display information of the found item in
the cart. Or else, notify the customer the item is not found in the current cart.
The customer can request to place order when they are seeing the current cart. For simplification, he/she does not need to
log in to place an order. The application will prompt the customer to enter the delivery information and delivery instructions. The
software will then calculate the delivery fee based on the total mass of the order & the delivery location. Then, it will display to the
customer the invoice including the DVD list, total cost before VAT, total cost after VAT, and the delivery fee. The customer can
then proceed to pay for the order. Currently, only one payment method – ie credit card – is allowed by connecting to a card
association system for checking the validation of the card or performing the pay transaction. After the transaction, the AIMS
software will display all the detailed information such as transaction ID, card owner, transaction amount, transaction message,
balance, transaction date to the customer. The order will be in pending state and the information of the order & the transaction will
be sent to the customer's email.
Page 2 of 12
Machine Translated by Google
The store manager needs to log in to the system to navigate to the management mode. He/she can see the list of pending
orders, then can pick any order to see its details to approve or reject the order. The store
manager can add new DVDs to the store. He or she must provide all information of the new DVD, including its ID, title, category,
director, length, and the cost. Additionally, the manager can also remove DVDs from the store.
Based on the problem statement in the section 2, please draw the use case diagram using Astah UML for the AIMS project.
A use case diagram is one of the UML diagrams to capture dynamic behaviors, ie, the pattern of state change over time (https://
www.cs.uct.ac.za/mit_notes/software/htmls/ch05s08.html). The use case diagram illustrates the relations among use cases. A use-
case model describes a software's functional requirements in terms of use cases. The use-case diagram is a model of the
software's intended functions and its environment and serves as a contract between the customer and the developers. Because it
is a very powerful planning instrument, the use-case diagram is generally used in all phases of the development cycle. For better
understanding, see https://www.uml-diagrams.org/use-case-diagrams.html.
To draw the use case diagram, you must identify the actors and use cases. A sample use case diagram is illustrated in Figure 1
with one use case: place an order. You have to identify more use cases to update the use case diagram for the final submission.
based on the information that the user provides. This information can be displayed whenever the user decides to see it. The
DVD with its information and functions is modeled with the DVD class. Finally, the application needs an entry point for
displaying to and taking input from the user (via a command-line interface), which will be the Aims class. A sample class
diagram is illustrated in Figure 2, which includes 3 classes: • The Aims class which provides a main() method which interacts
with the rest of the
system
• The DigitalVideoDisc class which stores the title, category, cost, director and length • The Cart class to
maintain an array of these DigitalVideoDisc objects
You have to update this class diagram following the below exercises for the final submission.
Figure 2. Sample class diagram for use cases related to cart management.
Page 4 of 12
Machine Translated by Google
+ You may need to check the option "public static void main(String[] args)"
This will automatically generate the main function in the class Aims.java as the following result.
+ Because you did not choose any package for the Aims class, Eclipse then displays the icon
package and mentions (default package) for your class.
Page 5 of 12
Machine Translated by Google
+ You can create a package and move the class to this package if you want. In the scr folder, a sub-folder will be
created (with the name of the package) to store the class. Do it yourself and open the src folder to see the result.
Page 6 of 12
Machine Translated by Google
Page 7 of 12
Machine Translated by Google
In this part, you will create yourself constructor method for DigitalVideoDisc for different purposes:
- Create a DVD object by title
- Create a DVD object by category, title and cost
- Create a DVD object by director, category, title and cost
- Create a DVD object by all attributes: title, category, director, length and cost
Page 8 of 12
Machine Translated by Google
Each purpose will be corresponding to a constructor method. By doing that, you have practiced with
overloading method.
Question:
- If you create a constructor method to build a DVD by title then create a constructor method to build
a DVD by category. Does JAVA allow you to do this?
Eclipse also allows you to automatically generate constructor methods by field. Just do the same generating getters and
setters. Right click anywhere in the source file, Choose Source, Choose Generate constructors by fields (Figure 10) then
select the fields (Figure 11) to generate constructor methods.
Page 9 of 12
Machine Translated by Google
This is how you create the first constructor method. Similarly, you will create by yourself the others.
Page 10 of 12
Machine Translated by Google
Now you have all the classes for the application. Just practice with them in the next section.
Do the following code in your main method and run the program to test.
Page 11 of 12
Machine Translated by Google
12. References
James Rumbaugh, Ivar Jacobson, and Grady Booch (2004). Unified Modeling Language Reference Manual, The (2nd Edition).
Pearson Higher Education
Page 12 of 12