Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java.....need the uml diagram and java source code including the interface, its implementation, exception classes, helper, driver and the testing data file please B. Project
java.....need the uml diagram and java source code including the interface, its implementation, exception classes, helper, driver and the testing data file
please
B. Project description Project 1 Abstract Data Type(ADT) Bag An ADT Bag is composed of a list of grocery items and a set of operations on the list. You may think of a grocery bag as an instance of the ADT Bag. A grocery bag contains a list of groceries. There is a set of operations that operate on the list. For example, we can add an item, remove an item, count the number of items, check for a specific item, etc. In this project, you will design an ADT bag by following software development cycle including specification, design, implementation, test/debug, and documentation. . Specification/Analysis: The ADT Bag must contain the following operations: create an empty bag that can hold up to 100 items add an item to the end of the list of this bag- insert(item) remove the item at the end of this bag - removeLast() remove an item at a random index from this bag - removeRandom() get the index of the first occurrence of an item from this bag - get(a reference to an item) get a reference to an item at position index of this bag(get(index)), check how many items are there in this bag - size() check to see if this bag is empty - isEmpty() empty this bag - makeEmpty() Design: Complete a UML diagram to include all classes that are needed to meet the specifications. An interface class needs to be defined to specify the design of each operation. In the interface, what each operation does is specified. A class implementing this interface needs to be defined to specify how each operation does and a data structure is selected to store a collection of data. Exceptions should to be considered when operations are designed. Java has two types of exceptions: checked exceptions and runtime exceptions. Checked exceptions are instances of classes that are sub classes of java.lang.Exception class. They must be handled locally or explicitly thrown from the method. They are typically used when the method encounters a serious problem. In some cases, the error may be considered serious enough that the program should be terminated. Runtime exceptions occur when the error is not considered as serious. These types of exceptions can often be prevented by fail-safe programming. For example, it is fairly easy to avoid allowing an array index to go out of range, a situation that causes the runtime exception ArrayIndexOutOfBoundsException to be thrown. Runtime exceptions are instances of classes that are subclasses of the java.lang.RuntimeException class. RuntimeException is a subclass of java.lang.Exception that relaxes the requirement forcing the exception to be either handled or explicitly thrown by the method. In general, some operations of an ADT list/ADT Bag can be provided with an index value. If the index value is out of range, an exception should be thrown. Therefore, a subclass of IndexOutOfBoundException needs to be defined. Also, an exception is needed when the list/bag storing the items becomes full. A subclass of java.lang.RuntimeException should be defined for this erroneous situation. A full ADT bag should throw an exception when a new item is inserted. Similarly, an empty ADT Bag should throw an exception when removing an item from it. Code/Implementation: A class implementing the interface needs to be written to specify how each operation does and a data structure is selected to store a collection of data. An array must be used to store all items in an ADT Bag. The element type of the array should be object type - the ultimate superclass of all other classes. When organizing items in the array, all items must be stored consecutively. This means shifting may be needed after some insertion or removal operations. Javadoc comments need be written during this activity. Class comments must be included right above the corresponding class header. Method comments must be included right above the corresponding method header. Comments are also needed in each method to document each block of statements. Debug/Testing: Note: It is required to store all testing data in a file. It is required to use decomposition design technique. To test the ADT bag design, all operations must be tested. In general, an empty ADT Bag is created, and then, fill the bag, display the list and test other operations. It is not efficient to write everything in main. Method main should be small and the only method in a driver program. A helper class should be created to assist the driver. In the Helper class, minimum three static methods should be included. Method start creates an empty bag and is decomposed/calls other methods such as create and display. Method create should add items into the bag. Method display should display the items in the bag. More methods can be added to test other operations. Method main should call start from the driver program to start the entire testing process. Test the entire design by creating a driver program and a helper class of the driver program. Create a helper class. In the helper class, minimum three static methods should be included. public class Helper //method 1 public static void start() { This void method is decomposed. It creates an empty bag. It calls create with a reference to the empty bag. create adds a list of items into the bag. It calls display with a reference to the bag. display displays the list of items in the bag. 8 //method 2 public static returnTypeOrvoid create (A reference to a bag) { Using data stored in text files to make items. Add the items into the bag. Note: In this case, you may add String objects to an ADT Bag that can store items of Object type. } //method 3 public static returnTypeOrvoid display (A reference to a bag) { Displays the list of items in the bag. . Create a driver program. In main of the driver program, call method start to start the entire testing process. public class Driver public static void main(String[] args) { Helper.start(); The sample testing file may contain items like this: Apple Pear Orange Milk Bread Documentation: Complete all other documents neededStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started