Lab 8

Lab Description:

The goal of the lab is to create a data analyzer with four functions. The four functions are: asking user to input different numbers and then, order it in ascending, in they way they were entered, and finally displaying all the numbers once. So in another word create a menu that ask user for a numbers of amount of numbers that the user want to enter. Then enter the amount of the numbers. After you have enter the amount the problem will show ascending of numbers, how they was entered, and finally displaying all the numbers once.

 

Code:

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeSet;
import java.util.Collections; 

public class test1 {

private static Scanner input;


public static void main(String[] args) {
    input = new Scanner(System.in);
    Stack stack = new Stack();
    LinkedList list1 = new LinkedList();
    LinkedList list2 = new LinkedList();
    TreeSet treeset = new TreeSet();
    
    System.out.print("Pick the one you want (1 = String) (2 = Double) (3 = Integer)  ");
    int link = 0;
    link = input.nextInt();
    
    if (link == 1) {
        int x = 0;
        System.out.println("You have pick String. ");
        System.out.print("Enter Amount of Strings: ");
        int y = input.nextInt(); 
        
        while(x < y) {
            System.out.print("Strings: ");
            String c = input.next();
            list1.addFirst(c);
            stack.push(c);
            treeset.add(c);
            x++; 
        }

        list2.addAll(list1);
        Collections.sort(list2);
        
        System.out.println("Strings Entered in Order: " + stack);
        System.out.println("Strings Entered in Reversed Order: " + list1);
        System.out.println("Strings Entered in Ascending Order: " + list2);
    }
    
    if (link == 2) {
        int x = 0;
        System.out.println("You have pick Double. ");
        System.out.print("Enter Amount of Numbers: ");
        int y = input.nextInt(); 
            
        while(x < y) {
            System.out.print("Numbers: ");
            double c = input.nextDouble();
            list1.addFirst(c);
            stack.push(c);
            treeset.add(c);
            x++; 
        }

        list2.addAll(list1);
        Collections.sort(list2);
        
        System.out.println("Numbers Entered in Order: " + stack);
        System.out.println("Numbers Entered in Reversed Order: " + list1);
        System.out.println("Numbers Entered in Ascending Order: " + list2);
    }
    
    if (link == 3) {
        int x = 0;
        System.out.println("You have pick Integer. ");
        System.out.print("Enter the Amount of Numbers: ");
        int y = input.nextInt(); 
                
        while(x < y) {
            System.out.print("Numbers: ");
            Integer c = input.nextInt();
            list1.addFirst(c);
            stack.push(c);
            treeset.add(c);
            x++; 
        }

        list2.addAll(list1);
        Collections.sort(list2);
        
        System.out.println("Numbers Entered in Order: " + stack);
        System.out.println("Numbers Entered in Reversed Order: " + list1);
        System.out.println("Numbers Entered in Ascending Order: " + list2);
    }
}
}

Screenshots: