Lab 5

Description:

The object of this lab was to create a program to analyze data that first will display a menu asking the user to enter: (1) the data type of the elements (string, double or integer) and (2) how many elements to process. Then the user enters the data and after finishing the program will analyze it by displaying the following:

  • Display 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.
  • Display the elements only once (i.e. no repetitions).

Code:

package Lab5;

import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class DataStructures {

	public static void main(String[] args) {
		//Arrays
		int[] integer;
		double[] bigNum;
		String[] words;

		Scanner input = new Scanner(System.in);
		Scanner i2 = new Scanner(System.in);
		int choice,numElements,num;
		double bNum;
		String word;
		//Arraylists
		ArrayList intArray = new ArrayList();
		ArrayList strArray = new ArrayList();
		ArrayList dblArray = new ArrayList();
		//Menu
		System.out.println("1.Integer\n2.Double\n3.String");
		System.out.print("What type of data would you like to enter?: ");
		choice = input.nextInt();
		System.out.print("How many elements would you like to enter?: ");
		numElements = input.nextInt();
		switch(choice){
		case 1:

			integer = new int[numElements];
			for(int x = 0; x set = new TreeSet();
			set.addAll(intArray);
			set.iterator();
			System.out.println("Elements with no Repition using Sets: "+set);

			break;
		case 2:
			bigNum = new double[numElements];

			for(int x = 0; x dblSet = new TreeSet();
			dblSet.addAll(dblArray);
			dblSet.iterator();
			System.out.println("Elements with no Repition using Sets: "+dblSet);

			break;
		case 3:
			words = new String[numElements];
			System.out.println("Enter words in lower case.");
			for(int x = 0; x strSet = new TreeSet();
			strSet.addAll(dblArray);
			strSet.iterator();
			System.out.println("Elements with no Repition using Sets: "+strSet);

			break;
		}
	}

}

 Screenshot:

lab5

Leave a Reply

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