Please implement the pseudocode of the following Please use

Please implement the pseudocode of the following. Please use Java. Your program will first ask the user to input the number of activities, next it will ask the user to input a group of starting times, then a group of finishing times. The output will be a subset of maximum number of compatible activities. Deliverable: A complete program that can be compiled and run. Please, attach the screen shot of the running program. Greedy-Activity-Selector (s, f) n leftarrow length[s] A leftarrow {a_1} i leftarrow 1 for m leftarrow 2 to n do if S_m greaterthanorequalto f_i then A leftarrow A {a_m} i leftarrow m return A

Solution

//GreedyActivitySelector.java

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

class GreedyActivitySelector
{
   public static ArrayList<Integer> activitySelector(int s[], int f[])
   {
       int n = s.length;
       int i, j;

ArrayList<Integer> activity = new ArrayList<Integer>(n);
      
       // select first activity
       i = 0;
       activity.add(i);
      
       // remaining activities
       for (int m = 1; m < n; m++)
       {
           if (s[m] >= f[i])
           {
               activity.add(m);
               i = m;
           }
       }

       return activity;
   }
  
   // driver program to test above function
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);

System.out.print(\"Enter number of activities: \");
int n = sc.nextInt();

int[] s = new int[n];
int[] f = new int[n];

for (int i = 0; i < n ; i ++ )
{
   System.out.println(\"Enter starting time \" + i + \": \");  
   s[i] = sc.nextInt();
}
for (int i = 0; i < n ; i ++ )
{
   System.out.println(\"Enter finish time \" + i + \": \");  
   f[i] = sc.nextInt();
}

       ArrayList<Integer> activity = new ArrayList<Integer>(s.length);
      
       System.out.println(\"\ \ Activities selected : \ \");

       activity = activitySelector(s, f);

       System.out.println(Arrays.toString(activity.toArray()));

   }
  
}


/*
output:

Enter number of activities: 6
Enter starting time 0:
1
Enter starting time 1:
3
Enter starting time 2:
0
Enter starting time 3:
5
Enter starting time 4:
8
Enter starting time 5:
5
Enter finish time 0:
2
Enter finish time 1:
4
Enter finish time 2:
6
Enter finish time 3:
7
Enter finish time 4:
9
Enter finish time 5:
9


Activities selected :

[0, 1, 3, 4]

*/

 Please implement the pseudocode of the following. Please use Java. Your program will first ask the user to input the number of activities, next it will ask the
 Please implement the pseudocode of the following. Please use Java. Your program will first ask the user to input the number of activities, next it will ask the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site