lab 5 Data Structures

Description:
In this lab we analyze data that display a menu asking the user to the data type of element (string, double or integer) , the program also ask them how many elements to process. Then the user enters how many elements he wants to process. The program then analyze it by displaying all the elements in the order they were entered, display all the elements in the reverse order they were entered, display all the elements in ascending order, and display the elements only once which means no repetition is allowed.

Code:

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;

}
}

}

lab 5 pic 2
lab 5 pic 1

Leave a Reply

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