Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in a class named ExtraCreditLab, implement all of the following methods as compl

ID: 3771787 • Letter: I

Question

in a class named ExtraCreditLab, implement all of the following methods as completely and correctly as you can.

1. Write a method named capitalizeFirstLetters that prints a capitalized version of a passed in string to the screen, that is, it changes the rst letter of each word in the string to upper case (if it is not already up-per case). So "I really enjoy attending lab!" becomes "I Really Enjoy Attending Lab!". The string to be printed should be a parameter to the method, and the method should have a void return. You should test your method in main by getting a line of input from the user and applying the method to it. (Hint: you may want to browse the Java String docs for useful methods on strings).
2. Write a method named transpose that calculates the transpose of an n-by-n matrix when called, that is, it exchanges the rows and columns of a matrix without using extra space. The n-by-n matrix should be passed in as a parameter and nothing needs to be returned. You should test your method in main by creating a matrix of random values and passing that in to your method. Print the original matrix rst, before calling transpose, then print it again after calling transpose.
3. Write a method named isRagged that determines if a passed in two dimensional array is ragged. It should take a 2d array as a parameter, and return true if it is ragged and false if it is not ragged. You should test your method in main by coding some dierent 2d array inputs (ragged and non-ragged).
4. Write a method named findMin that takes in an array of strings and a starting index, and calculates the minimum string (i.e. the earliest word alphabetically) in the array starting from the passed in index. The method should return the index where the minimum string is located. As before, make sure to test you method in main (you can hard code the array or use Scanner on keyboard input to populate the array).
5. Answer this question as a comment in your java le: how would you use the method findMin above to sort an array of Strings?

Explanation / Answer

1)

private String capitalizeFirstLetters(String word){

        String[] words = word.split(" ");
        StringBuilder sb = new StringBuilder();
        if (words[0].length() > 0) {
            sb.append(Character.toUpperCase(words[0].charAt(0)) + words[0].subSequence(1, words[0].length()).toString().toLowerCase());
            for (int i = 1; i < words.length; i++) {
                sb.append(" ");
                sb.append(Character.toUpperCase(words[i].charAt(0)) + words[i].subSequence(1, words[i].length()).toString().toLowerCase());
            }
        }
        return sb.toString();

    }

2)

import java.util.Scanner;

class TransposeAMatrix
{
   public static void main(String args[])
   {
      int m, n, c, d;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter the number of rows and columns of matrix");
      m = in.nextInt();
      n = in.nextInt();

      int matrix[][] = new int[m][n];

      System.out.println("Enter the elements of matrix");

      for ( c = 0 ; c < m ; c++ )
         for ( d = 0 ; d < n ; d++ )
            matrix[c][d] = in.nextInt();

      int transpose[][] = new int[n][m];

      for ( c = 0 ; c < m ; c++ )
      {
         for ( d = 0 ; d < n ; d++ )             
            transpose[d][c] = matrix[c][d];
      }

      System.out.println("Transpose of entered matrix:-");

      for ( c = 0 ; c < n ; c++ )
      {
         for ( d = 0 ; d < m ; d++ )
               System.out.print(transpose[c][d]+" ");

         System.out.print(" ");
      }
   }
}

3)

boolean isRagged( int [][] X)
{
for (int i =1; i < X.length ; i ++)
{
if ( X[i].length != X[0].length)
{
return true ;
}
}
return false ;
}


4)

import java.util.Random;
import java.util.Scanner;
public class FindMin
{
    public static void main(String[] args){
        System.out.println("Main Method Started");
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the size of the arr");
        int size = in.nextInt();
        System.out.println("Enter the maximum value of the arr");
        int max = in.nextInt();
        int [] arr = initializeArr(max, size);
        print(arr);
        findMin(arr);
        System.out.println("Main Method Ended");
    }
    public static void print(int[] arr){
        for(int val:arr){
            System.out.print(val + " ");
        }
        System.out.println();
    }
    public static int[] initializeArr(int max,int size){
        Random random = new Random();
        int [] arr = new int[size];
        for(int ii=0;ii<arr.length;ii++){
            arr[ii]=random.nextInt(max);
        }
        return arr;
    }
    public static void findMin(int[] arr){
        int min=arr[0];
        int max=arr[0];
        for(int ii=0;ii<arr.length;ii++){
            if(arr[ii]<min)
            {
                min=arr[ii];
            }
          
        }
        System.out.println("The minimum in the arr::"+min);
    }
}