Java Assignment: Implementing a Bag for a Clothing Boutique

Verified

Added on  2023/04/04

|5
|630
|248
Practical Assignment
AI Summary
This assignment solution focuses on implementing a 'bag' data structure in Java for a clothing boutique application. The core objective is to create a class capable of storing item values and prices, where the order of insertion is irrelevant, and elements can be stored and removed randomly. The solution utilizes the Scanner class for user input and incorporates getter and setter methods to manage data encapsulation. The assignment details the pre-planning phase, outlining operations like insertion, removal, element checking, and counting elements within the bag. The implementation leverages private variables to control access and modify data, enhancing flexibility and data security. The provided code demonstrates how to get user input and store data using the Scanner class, assigning values to variables using getter and setter methods. The document also includes references to relevant literature on data structures and Java programming.
Document Page
CLOTHING BOUTIQUE BAG IMPLEMENTATION IN JAVA
1
Assignment
Student
Course
Instructor
Date
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
CLOTHING BOUTIQUE BAG IMPLEMENTATION IN JAVA
2
Introduction
Main objective is to implement a class that will be used as bag which will be capable of storing
the values for different items and the prices in a specific class. For the Bag data type order of
insertion of the objects/elements is not irrelevant. The stored objects/elements can be stored as
well as removed in a random manner (Lafore, 2017). Through the use of the Bag abstract data
type, the most important intent is to use it and suggest collection of the objects which are familiar
to developers or users in their day to day experience.
Program 1 Pre-Planning (Clothing Boutique)
The available operations for the proposed application of bag includes insertion of new values,
removal of the elements, checking for an element in order to see if that value is stored in the
collection of elements or bag. Furthermore it is also possible to find out the number of
elements/objects in bag. In addition to that as there are problems which requires capability of
looping over all the elements in the bag/container. This can be achieved in Bag data structure
without exposing details of the implementation or knowing the way collection is organized in the
memory.
Furthermore bag is also helpful in constructing a set in java. Most of the functionalities are same
in set with the only change in the addition of the element where it checks if the new element /
value is already present in the collection or not. Operations like intersection of sets, set union as
well as difference among them can be implemented through the use of the simple loop
mechanisms available in java.
Document Page
CLOTHING BOUTIQUE BAG IMPLEMENTATION IN JAVA
3
In order to implement the bag for the program the inbuilt getter and setter function is used.
Along with that the scanner class is also used in order to get the user input for storing values of
different variables (Joyce & Weems, 2016). The variables in the class are declared as private
members in order to hide the data and methods to hide the complex logic of the programs and
unintended changes to the values stored in the variables. In this way, it is possible to have
increased and better control over the class attributes as well as methods. Through this the
declared class variables are made as read-only or write-only through the selection of the only get
() or set () method. The program becomes flexible. The program can be meant to develop in such
a way that the user input can change one part of the application code while having no impact on
other parts by enhancing the security of data.
Conclusion
In the complete implementation of the program the Scanner class is also utilized in order to get
the user input and store the value in the variables. This class is available inside the java.util
package (Joyce & Weems, 2016). In order to use Scanner class, an object is created and the
previously declare getter setter methods are utilized for assigning values to the variables. In the
developed program the next () for the item_name and the nextInt() method for the price of the
items.
Screenshot of the program
Document Page
CLOTHING BOUTIQUE BAG IMPLEMENTATION IN JAVA
4
References
Horstmann, C. S. (2016). Big Java, Binder Ready Version: Early Objects. John Wiley & Sons.
Joyce, D. T., & Weems, C. (2016). Object-oriented data structures using Java. Jones & Bartlett
Publishers.
Lafore, R. (2017). Data structures and algorithms in Java. Sams publishing.
Savitch, W. (2017). Java: An Introduction to Problem Solving and Programming, Student Value
Edition Plus MyProgrammingLab with Pearson eText-Access Card Package. Pearson.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
CLOTHING BOUTIQUE BAG IMPLEMENTATION IN JAVA
5
References
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]