Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement Pseudocode of the java code below: import java.util.Scanner; public class SortNamesNumbers { /***************************************************************************/ private static void printArray ( int [] nums ) { for

Implement Pseudocode of the java code below:

 import java.util.Scanner; public class SortNamesNumbers {   /***************************************************************************/  private static void printArray(int[] nums) {   for(int i=0;i)  {    System.out.println(nums[i]); }   }  /*************************************************************************/  private static void printArray(String[] str) {   for(int i=0;i)  {    System.out.println(str[i]); }   }  /*********************************************************************************/  private static void sortnumsDec(int[] array) {   // Sorts elements in Decending order int temp1; for (int i = 0; i < array.length; i++)  {    for (int j = i + 1; j < array.length; j++)  {     if (array[i] < array[j])  {      temp1 = array[i]; array[i] = array[j]; array[j] = temp1; }    }   }  }  /*********************************************************************************/  private static void sortnumsAsc(int[] array) {   // Sorts elements in Ascending order int temp1; for (int i = 0; i < array.length; i++)  {    for (int j = i + 1; j < array.length; j++)  {     if (array[i] > array[j])  {      temp1 = array[i]; array[i] = array[j]; array[j] = temp1; }    }   }   }  /*********************************************************************************/  private static void sortStringsDesc(String[] arr) {   /* Bubble Sort Method: Sorts elements in Descending order */ for(int i = 0; i < arr.length-1; ++i) {    for (int j = i + 1; j < arr.length; ++j) {     if (arr[i].compareTo(arr[j]) < 0) {       //Swapping String temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }    }   }   }  /*********************************************************************************/  private static void sortStringsAscd(String[] arr) {   //Bubble Sort Method: Sorting Strings alphabetical order for(int i = 0; i < arr.length-1; ++i) {    for (int j = i + 1; j < arr.length; ++j) {     if (arr[i].compareTo(arr[j]) > 0) {       //Swapping String temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }    }   }   }   // Driver Code /*********************************************************************************/  public static class MainDriver{    public static void main(String[] args) {     int capacity, optChoice; Scanner sc = new Scanner(System.in);// keyboard // input user condition while (true) {     System.out.print("Choose either Option 1 = [Strings] OR Option 2 = [Numbers]: "); optChoice = sc.nextInt(); if (optChoice != 1 && optChoice != 2) {      System.out.println("Invalid optChoice. Must enter either number 1 or 2 for String or Numbers Respectively."); } else break; }     /*********************************************************************************/    // Option 1: Display String "names" if(optChoice == 1)    {     System.out.print("How many names do you want to enter: "); capacity = sc.nextInt(); String str[] = new String[capacity]; for(int i=0;i)     {      System.out.printf("Enter String number %d: ", i + 1); str[i]=sc.next(); }      do {      System.out.print("Choose your Sorting Option: (Option 1 = Ascending Order/ Option 2= Decending order): "); optChoice = sc.nextInt(); if (optChoice != 1 && optChoice != 2) {       System.out.println("Invalid Choice. MUST be be 1 or 2 "); } else break; } while (true); System.out.println("Array Before Sorting Option: "); printArray(str); if(optChoice == 1) {      sortStringsAscd(str); } else if(optChoice == 2) {      sortStringsDesc(str); }      System.out.println("Array After Sorting Option :"); printArray(str); }    /*********************************************************************************/    // Option 2: Number (Integers) else if(optChoice == 2)    {     System.out.print("How many numbers do you want to enter :"); capacity = sc.nextInt(); int nums[] = new int[capacity]; for(int i=0;i)     {      System.out.printf("Enter Numbers%d: ", i + 1); nums[i] = sc.nextInt(); }      do {      System.out.print("How do you want to sort (Option 1 = Ascending Order/ Option 2= Decending order) :"); optChoice = sc.nextInt(); if (optChoice != 1 && optChoice != 2) {       System.out.println("** Invalid.Must be either 1 or 2 **"); } else break; } while (true); System.out.println("Array Before Sorting :"); /*********************************************************************************/     // Display printArray(nums); if(optChoice==1)     {      sortnumsAsc(nums); }     else if(optChoice==2)     {      sortnumsDec(nums); }     System.out.println("Array After Sorting :"); printArray(nums); }   }// end SortNamesNumberDriver }//end SortNamesNumber class } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+What is the nature of the unions in the particular country?

Answered: 1 week ago