Lab 5

we create a program and analyze the data that first will display a menu asking the user to enter the data type of the elements and how many elements to process. Then the user enters the data and after finishing the program will analyze it by displaying all the elements in the order they were entered, all the elements in the reverse order they were entered, all the elements in ascending order, the elements only once.

package lab5;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
public class lab5 {
@SuppressWarnings({ "unchecked", "resource" })
public static void main(String[] args) {

Scanner inputA = new Scanner( System.in );

System.out.println("Enter the amount of Elements you would like to process: \n");

String qstrings = inputA.next();

int inputcase = Integer.parseInt(qstrings);

int count = inputcase;

@SuppressWarnings("rawtypes")

Queue myStringsQ = new LinkedList();

@SuppressWarnings("rawtypes")

Stack myStringS = new Stack();

@SuppressWarnings("rawtypes")

TreeSet myStringTS = new TreeSet();

@SuppressWarnings("rawtypes")

Set myStringsSet = new HashSet();

for (int i = 0; i < inputcase; i++) {
Scanner input = new Scanner( System.in );

System.out.println("Enter the Elements: \n");

String position = input.next();

myStringsQ.offer(position);

myStringS.push(position);

myStringTS.add(position);

myStringsSet.add(position);
}
while (inputcase != 0){
System.out.println("Displaying Elements you entered in order using Queue Structuring: ");
for (int i = 0; i < count; i++) {
System.out.printf("%s: ", myStringsQ.peek());
myStringsQ.poll();
}
System.out.println("\n\nDisplaying Elements you entered in reverse order using Stack Structuring: ");
for (int i = 0; i < count; i++) {
System.out.printf(myStringS.pop()+": ");
}

System.out.print("\n\nElements you entered Ascending order using TreeSet Structuring: \n");

System.out.printf(myStringTS+"");

System.out.println("\n\nNon-Duplicate Elements you entered using HashSet Structuring: ");

System.out.printf(""+myStringsSet);
break;
}
}
@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
public void doubles(){

Scanner inputA = new Scanner( System.in );

System.out.println("Enter the amount of Elements you would like to process: \n");

String qstrings = inputA.next();

int inputcase = Integer.parseInt(qstrings);

int count = inputcase;

Queue myStringsQ = new LinkedList();

Stack myStringS = new Stack();

TreeSet myStringTS = new TreeSet();

Set myStringsSet = new HashSet();

for (int i = 0; i < inputcase; i++) {

Scanner input = new Scanner( System.in );

System.out.println("Enter the Elements: \n");

String position = input.next();

Double posA = Double.parseDouble(position);

myStringsQ.offer(posA);

myStringS.push(posA);

myStringTS.add(posA);

myStringsSet.add(posA);
}

while (inputcase != 0){

System.out.println("Displaying Elements you entered in order using Queue Structuring: ");

for (int i = 0; i < count; i++) {

System.out.printf("%s: ", myStringsQ.peek());

myStringsQ.poll();
}

System.out.println("\n\nDisplaying Elements you entered in reverse order using Stack Structuring: ");

for (int i = 0; i < count; i++) {

System.out.printf(myStringS.pop()+": ");
}

System.out.print("\n\nElements you entered Ascending order using TreeSet Structuring: \n");

System.out.printf(myStringTS+"");

System.out.println("\n\nNon-Duplicate Elements you entered using HashSet Structuring: ");

System.out.printf(""+myStringsSet);

break;
}
}

@SuppressWarnings("unchecked")

public void integers(){

@SuppressWarnings("resource")

Scanner inputA = new Scanner( System.in );

System.out.println("Enter the amount of Elements you would like to process: \n");

String qstrings = inputA.next();

int inputcase = Integer.parseInt(qstrings);

int count = inputcase;

@SuppressWarnings("rawtypes")

Queue myStringsQ = new LinkedList();

@SuppressWarnings("rawtypes")

Stack myStringS = new Stack();

@SuppressWarnings("rawtypes")

TreeSet myStringTS = new TreeSet();

@SuppressWarnings("rawtypes")

Set myStringsSet = new HashSet();

for (int i = 0; i < inputcase; i++) {

@SuppressWarnings("resource")

Scanner input = new Scanner( System.in );

System.out.println("Enter the Elements: \n");

String position = input.next();

int posB = Integer.parseInt(position);

myStringsQ.offer(posB);

myStringS.push(posB);

myStringTS.add(posB);

myStringsSet.add(posB);
}

while (inputcase != 0){
System.out.println("Displaying Elements you entered in order using Queue Structuring: ");
for (int i = 0; i < count; i++) {
System.out.printf("%d: ", myStringsQ.peek());
myStringsQ.poll();
}
System.out.println("\n\nDisplaying Elements you entered in reverse order using Stack Structuring: ");
for (int i = 0; i < count; i++) {
System.out.printf(myStringS.pop()+": ");
}
System.out.print("\n\nElements you entered Ascending order using TreeSet Structuring: \n");
System.out.printf(myStringTS+"");
System.out.println("\n\nNon-Duplicate Elements you entered using HashSet Structuring: ");
System.out.printf(""+myStringsSet);
break;
}
}

}

Queue, typically, but do not necessarily, order elements in a (First in First Out)

Stack, creates a new array of integers (Last in First Out)

Treeset,

Hashset

Capture Capture2

Leave a Reply

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