Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
OBJECT
General object
Specific object
1. THEORETICAL FRAMEWORK
Introduction to java
Some of its history start in the early 90s, extending the power of network computing to
the activities of everyday life was a radical vision. In 1991, a small group of Sun engineers
called the "Green Team" believed that the next wave in computing was the union of digital
consumer devices and computers. Led by James Gosling, the team worked around the
clock and created the programming language that would revolutionize our world Java.
(Oracle, 2017)
One important part of java is its Java Virtual Machine (JVM) this executes java code, but
is written in platform specific languages such as C/C++/ASM, etc. so JVM is not written
in JAVA and hence cannot be platform independent and Java interpreter is a part of JVM.
(W3schools.in, 2016)
Introduction to eclipse
Eclipse, in the late 1990s, IBM began development of what we now know as Eclipse.
Today we see high adoption rates and evidence of successful application of this
technology across the software industry. The purpose of this article is to review the
inception of Eclipse, to illustrate the role it plays in today's development tools, and to
convey how we see the technology evolving over time. (Cernosek, 2005)
The Eclipse Project was originally created by IBM in November 2001 and supported by
a consortium of software vendors. The Eclipse Foundation was created in January 2004
as an independent not-for-profit corporation to act as the steward of the Eclipse
community. The independent not-for-profit corporation was created to allow a vendor
neutral and open, transparent community to be established around Eclipse. Today, the
Eclipse community consists of individuals and organizations from a cross section of the
software industry. (Cernosek, 2005)
Stack in Java
The stack is a sequence of elements of the same type in which access to it is done by a
single place called top:
We see how access to the elements of the stack is always done on a single end. The
operations that characterize the stack are to introduce a new element on the top (push)
and extract the element located at the top (pop). One way of looking at this data structure
is like a stack of books in which you can only pick up the book that is on top or stack
more books on it, but the books that hold the stack are not accessible because otherwise
everything would fall apart. (Roldan, s.f.)
Stack static
The elements that make up the stack are stored in arrays (arrays), in the vector container
or forming a linked list. The implementation with an array is static since the array is fixed
in size.
The PilaLineal class, with this representation, needs an array and a numeric variable, top,
that points to the last element placed on the stack. When using an array, it is necessary to
take into account that the size of the stack cannot exceed the number of elements in the
array, and the full stack condition will be significant for the design.
The usual method of introducing elements in a stack is to define the bottom of the stack
in position 0 of the array and without any element inside it, that is, define an empty stack;
then, elements are introduced in the stack (in the array), so that the first element added is
inserted in an empty stack and in position 0, the second element in position 1, the next in
position 2 and so on With these operations, the index pointing to the top of the stack is
incremented by 1 each time a new element is added. The algorithms enter, "insert" (push)
and "remove", remove, (pop). (Martnez, 2008)
Insert (push)
Check if the battery is not full.
Increase the pointer index of the stack by 1.
Store item in the pointer position of the stack.
Remove (pop)
Check if the battery is not empty.
Read the element of the pointer position of the stack.
Decrease the stack pointer by 1.
Class Pila_Lineal
The declaration of an abstract type includes the representation of the data and the
definition of the operations. In the TAD Stack the data can be of any type, and the
operations.
Stack data (Data type is any type of primitive data or class type).
createPile initializes a stack. It is like creating a stack without elements, therefore,
empty.
Check that the battery is not full before inserting or inserting ("push") an element
in the battery; verify that a stack is not empty before removing or removing
("pop") an item from the battery. If these preconditions are not met, an error
message should be displayed, and the program must finish.
pilaVacia returns true if the stack is empty and false otherwise.
Full stack returns true if the stack is full and false otherwise. These two Last
operations are used to verify the preconditions of inserting and removing.
CleanPile empties the stack, leaving it without elements and available for other
tasks.
cimaPila returns the value located at the top of the stack, but does not decrease its
pointer, since the battery remains intact. (Martnez, 2008)
1. DEVELOPMENT OF AUTO-PRACTICE
STATIC STACK
To create a stack in java we must define the size of the stack, 2 classes will be used,
in the first class called Method_pila the different methods that allow the creation of
the stack will be implemented. In the second class called Main_pila, will be where
the stack size will be defined, and a menu will be available to perform the different
operations with the stack.
Part 1: Determine the size of the stack
2. Full. This method allows to give the state of the stack. If the stack is full, a
Boolean value will return true.
This method also allows you to solve the overflow problem, this happens when
you want to add an element to a full stack.
3. Push. This method, if the stack is not full, allows you to add an element to the
stack.
5. Show Stack. This method, if the stack is not empty, allows to show all the
elements of the stack.
In the main_pila class, a menu is implemented, which is useful in a dynamic way with
the user to relate the operations that this requires.
The menu will be available until the user enters the number 0.
In this part, we can see the method push working. And overflow problem solved.
In this part, we can see the method pop working. And underflow problem solved.
For the creation of the dynamic stack we will need a java API class that is the Linked List
which can be seen as a kind of vector in which we can store an infinity of data until the
machine supports it since it has not defined a specific limit.
For that we call the methods that this class contains in the following way:
With the creation of the list object we are going to use the methods of this class and in
fact the list is already defined.
To interact with our program, we will create a menu of operations where we will enter,
delete, and values.
With the help of the switch cycle that is implemented to validate menus where the user
decides what they want to do.
For case 1 we are going to add values to the stack, it is worth mentioning that if we
type that option, it will ask for a value and we will return to the options menu.
With the help of the add-First method, it locates the value that we enter at the
beginning of the list.
For the case 2 in which the elimination of a value is done, we use the remove-First
method which eliminates the first value from the list.
For case 3 we are going to use the methods of the interator class which will help us to
print the data of the list for it, we use the while loop in which we condition through
the method hasNext () which returns if the object is not the last one of the list while
the cycle is true will send the data to the console.
For the last case (4) we are going to use the clear () method that is inside the
LinkedList class, which removes the data from the stack.
Stack Dynamic
In the same way we will manage an operations menu similar to the static stack program
in this case we will select option 1 to enter a data to the list, but it is worth mentioning
that once we enter the values we will return to the options menu and also as it is dynamic
the spaces are going to be created as we are loading values into said list.
In this case, enter two values to the list and effectively visualize the data that is loaded.
Now we are going to eliminate a data of the list for it we are going to execute the option
2 and then we are going to realize the impression of data.
Effectively the data was deleted and at the time of printing the data the number does not
appear which its position was taken by the number 34.
2. Class methods
peek() This method looks at the object at the top of this stack without
removing it from the stack.
push(E item) This method pushes an item onto the top of this stack.
pop() Removes the object at the top of this stack and returns that
object as the value of this function.
To use the Stack class, the first thing to do is import the util.Stack class
Finally the use of methods that can be used according to the needs of the practice. in
this practice the push and pop method has been used.
Finally we can conclude that Stack are structures that allow storing
information, this information is stored in a specific order, the only way to
retrieve the information is in the LIFO mode. That is, the last one to enter
will be the first one to leave.
Stacks like any other information container, can suffer from problems such
as overflow and underflow. For this, the empty and full methods must be
implemented correctly, which will allow solving these problems.
The batteries are used in real life, for when another program is called, the
program that is running does not lose the information. That is to say, they
allow to save the state of the variables at the time the call is made, to
continue occupying them when returning from the subprogram.
5. RECOMMENDATIONS
The teacher should implement the use of the stacks in an easy problem, so that
the student can understand in a better way the use of these.
Investigate the relationship between these types of data storage in the creation
of more complex programs and even adapt them to the knowledge that has
been acquiring.