LAB 5PT2 – Data Structure Second Version

Lab Report 5 – Description

I created a program that analyzes data displays a menu asking to choose three different data types of the elements (string, double or integer) and how many elements the user would like to process. The user will then enter their data and the program will analyze it and display the data in the order they were entered, reverse order they were entered, in ascending order, and only once (i.e. no repetitions). I used the appropriate data structure as instructed.

Code:

package LAB_5_PT2;

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 dstructuring {

	public void strings(){
		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();
			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;

		}
	}

	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;

		}
	}

	public void integers(){
		
		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();
			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;

		}
	}
}


package LAB_5_PT2;

import java.util.Scanner;

public class dstructuringtest {

	String Introduction;
	public dstructuringtest (String Program)
	{
		Introduction = Program;
	}

	public String getWELCOME()
	{
		return Introduction;
	}

	public void MSGDISPLAY()
	{
		System.out.printf("Welcome to Washington Sarmiento's Fifth Program\n%s!\n\n", getWELCOME());
	}

	public static void main(String[] args) {

		dstructuringtest prgMessage = new dstructuringtest("CET3640f2013 LAB 5: Data Structures");
		prgMessage.MSGDISPLAY();
		Scanner input = new Scanner( System.in );
		System.out.println("Enter a Data Type: 1-String, 2-Double, 3-Integer: \n");
		String strings = input.next();
		int inputcase = Integer.parseInt(strings);

		switch (inputcase){
		case 1:
			dstructuring stringsA = new dstructuring();
			stringsA.strings();
			break;
		case 2:
			dstructuring doublesA = new dstructuring();
			doublesA.doubles();
			break;
		case 3:
			dstructuring integersA = new dstructuring();
			integersA.integers();
			break;
		default:
			System.out.println("\nChoose a number from the above menu.\nRun the program again.\nSEMPER FI");
			break;

		}
	}

}

Screenshots:

Screen Shot 2013-11-18 at 11.56.38 PM

 

Leave a Reply

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