Criterion C Development
Criterion C Development
Classes
Complex techniques:
1. Array
2. Complex Selection
3. Graphic User Interface
4. Data Persistence
5. Exceptions
6. Loops
7. Searching Algorithms
Array:
I used this complex technique as the data structure in my program to allow the user to store
objects and manage them by performing essential actions such as adding and deleting,
complying with my first criterion for success. I made an array for Products and another for
Orders. Both can hold up to 1000 objects since around 900 products exist and per year she
sells around 240 orders allowing her to use it for reasonable amount of years.
As it is seen in the AdminProducts class, for the arrays I used a ‘top’ which is always located at
the first position empty, so that an object added is situated there.
When adding a Product, if there is space in the array, the Product is placed in the position where
the ‘top’ is. The ‘top’ moves one place to the right, so that the next Product is added in the first
position empty.
Complex Selection (Nested if):
I used an if statement inside another if statement in some methods, such as addOrder and
deleteProduct, to first check if an object exists and then, if the condition is true, check other
conditions as it can be seen below. They allow me to create methods that are necessary to
comply with my criterion of allowing the user to add, modify, delete orders and products, and
check if they exist.
In the deleteProduct method, the first if statement checks if the Product id exists. If it exists, the
statements inside it are executed, and it will get to the next if statement. It checks if the Product
‘id’ in position ‘i’ of the array is equal to the ‘id’ in the parameter. If this condition is true, the
statements inside it are executed.
It checks if the order exists to comply with my criteria for success of not allowing an existing
order to be entered.
● SaveFile
The SaveFile method is used when the “Exit Application” button is clicked.
● TextFile
● ReadFile
Exceptions (Try / Catch):
I used it to test for possible errors by catching exceptions, while the program is being run. This is
useful for dealing with errors and exceptions that might appear. For example, whenever a space
is not filled or wrongly completed, such as when deleting an Order a string is entered in the ‘id’
field, complying with a criterion for success, an error message appears transmitting the problem
and avoiding the program from crashing.
Loops:
I used this complex technique for creating methods that were necessary to comply with my
criterion of adding, modifying, deleting objects and checking if they exist. For example, in the
AddOrder method, I used a ‘for’, as it is seen in the image below, to check in each position of
the array of products selected by the user for this new order, if it was empty or if it had a
product. If the position of the array had a product, the quantities selected for that product would
be deleted from the stock. This ‘for’ is used to apply it for each of the selected products by the
user.
I also used loops in the FrontEnd. For example, in the addOrder window the user must be able
to select any product in stock, for that order. So a ‘for’ was used to display each of the products
that are in the products array.
Searching Algorithms:
Inside my program I used this complex technique creating a searching method for every
attribute of the objects. This complies with the criterion for success of allowing the user to
choose by which attribute to search products and orders. I used a linear search because my
data is not sorted, so it searches consecutively. The object found is returned to the FrontEnd. If
it does not exist the FrontEnd receives ‘null’ to then display a warning message.