Lab 5

Description:

For this java lab, I had to use the programming technique called Data Structure. The type of data structure I had to use is ArrayList which allows the program to change its size to have more elements. I only had used one class call DataStructLab5 which also have the main method. I had used double numbers as an element to do this program. I used TreeSet to stores the double numbers into a tree hierarchy format. I used stack.push as a command to push the numbers on the stack. to display the numbers I used the for loop statement. As this program is running I will display the same numbers I had entered in four different ways the professor want to show as the output all in double number element.

package cet3640.Fall13.Lab5;
/*
*
*@AntonScott
*
*/
import java.util.*;
public class DataStructLab5 {
private static Scanner scanner;
public static void main(String[] args) {
// TODO Auto-generated method stub
scanner = new Scanner(System.in);
Double Number;
ArrayList list = new ArrayList();
Stack stack = new Stack();
Queue queue = new PriorityQueue();
TreeSet setList = new TreeSet();

do {
System.out.println("Hello, please enter as many numbers as possible so that you can execute this program. \n To exit or stop the program to calculated the results, enter any letter into this program:");
Number = scanner.nextDouble();

list.add(Number);
stack.push(Number);
queue.offer(Number);
setList.add(Number);

} while (scanner.hasNextDouble());

if (!scanner.hasNextDouble()) {
System.out.println("\n The numbers displayed in the order as follows: ");
for (int i = 0; i 0) {
System.out.print(queue.peek() + " ");
queue.poll();
}

System.out.println("\n\n The numbers displayed with no repetitions as follows: ");
while (!setList.isEmpty()) {
System.out.print(setList.first() + " ");
setList.remove(setList.first());
}
}
}
}

Lab 5 pic

Leave a Reply

Your email address will not be published. Required fields are marked *