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

Hello guys, I need help for the study guide, and please could you answer, and gi

ID: 3818152 • Letter: H

Question

Hello guys, I need help for the study guide, and please could you answer, and give someexamples with explaining to let me understand it:

Two-dimensional arrays:

Standard and enhanced traversal

Constructing

Passing as a parameter and returning as a value

Some sort of manipulation (swapping rows/columns, etc.)

Comparable Interface

‘implements’ clause

‘compareTo’ method

Code:

Method signatures

Method calls

Method returns

Method overloading

Method overriding

Comparing data:

For primitives (==, <=, !=, etc.)

For objects (equals, compareTo, compare)

Sorting algorithms:

Selection sort coding

Sorting passes practice:

Use selection sort to show what the values of this array of integers will be after the 1st, 3rd and 5th pass:

Original 68 -11      21    42    42      71    5       21

1st pass      

3rd pass       

5th pass        

Objects:

Complete a custom class with

o DVC,

o EVC,

o sets,

o gets,

o toString

Thank you.

Explanation / Answer

########## Two Dimensional Array ################

public class TwoDimensionalArray {
  
   //this function adds corresponding elements of first rows and store result in thisrd rows
   public static int[][] addFirstTwoRows(int[][] arr){
       //Note:
       // arr.length : number of rows
       // arr[i].length : number of columns in row i
       for(int i=0; i<arr[0].length; i++){
          
           arr[2][i] = arr[0][i] + arr[1][i];
       }
      
       return arr;
   }
  
   public static void main(String[] args) {
      
       //construction, 2D array : 3 rows and 4 columns
       int[][] arr = new int[3][4];
      
       //initializing first two rows with some numbers
       int count = 0;
       for(int i=0; i<2; i++)
           for(int j=0; j<4; j++)
               arr[i][j] = count++;
      
       // traversing using enhanced for loop
       for(int a[]: arr){
           for(int x: a)
               System.out.print(x+" ");
           System.out.println();
       }
      
       System.out.println();
      
       //calling function
       int[][] result = addFirstTwoRows(arr);
       System.out.println("Array content after function call");
       for(int temp[]: result){
           for(int x: temp)
               System.out.print(x+" ");
           System.out.println();
       }
   }

}

############## Comparable Intrface ######################


// 1, using implements clause
public class TestComparable implements Comparable<TestComparable>{

   String name;
   int age;
  
   public TestComparable(String name, int age) {
       this.name = name;
       this.age = age;
   }
  
   // overriding comapreTo method
   @Override
   public int compareTo(TestComparable obj) {
       return name.compareTo(obj.name); // calling compare too of string Object
   }
  
   //Overloading compareTo method
   public int compareTo(int obj) { // using ==, <=, >= for primitives
       if(age > obj)
           return 1;
       else if(age == obj)
           return 0;
       else
           return -1;
   }

}

############ Selection Sort #####################
Original 68 -11 21 42 42 71 5 21   
1st pass -11 68   21   42   42   71   5   21
3rd pass -11   5   21    42   42   71   68   21
4th pass -11    5   21    42   42   71   68   21
5th pass -11   5   21   21   42   71   68   42     
6th pass -11   5   21   21   42   71   68   42  
7th pass -11   5   21   21   42   42   68   71  
7th pass -11   5   21   21   42   42   68   71

############ Custom Class ##################


public class CustomClass {
  
   // instant variables
   private String DVC;
   private String EVC;
  
   // setters and getters
   /**
   * @return the dVC
   */
   public String getDVC() {
       return DVC;
   }
   /**
   * @return the eVC
   */
   public String getEVC() {
       return EVC;
   }
   /**
   * @param dVC the dVC to set
   */
   public void setDVC(String dVC) {
       DVC = dVC;
   }
   /**
   * @param eVC the eVC to set
   */
   public void setEVC(String eVC) {
       EVC = eVC;
   }
  
   // toString
   @Override
   public String toString() {
       return "DVC: "+DVC+", EVC: "+EVC;
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote