Question

In: Computer Science

write the “largerComponents” method that takes in two integer arrays and returns true or false if...

write the “largerComponents” method that takes in two integer arrays and returns true or false if the first array’s components are strictly greater than the second array’s components. The arrays must be the same size or else return false. Clarification Note: Components meaning each value at a specific index. For instance, if we had the arrays {5,2,7} and {1,3,1} then this method would return false as the value “2” is not greater than “3”.

here is a provided code

//Do not alter-----------------------------------------------------------------------
public class Question01 {

        public static boolean largerComponents(int[] a, int[] b)
        {
//-----------------------------------------------------------------------------------   
                //Write your solution here

                
                
                
                
                
                        
                
        }//Do not alter this
        //Write any additional helper properties or methods here
        
        //--------------------------------------------------------------------------------
        //Test your code here. You may alter this as needed.
        public static void main(String[] args)
        {

                int[] test01 = {5,4,3};
                int[] test02 = {2,1,0};

                System.out.println(largerComponents(test01,test02));
        }
        //--------------------------------------------------------------------------------
}//Do not alter this

Solution Tests:

  • Does the solution compile?
  • Does the solution have your name in the comments?
  • Does the solution have a high-level solution description (150-300 words) in the comments?
  • If the first array has the values {5,4,3} and the second array has the value {2,1,0} does the method return true?
  • If the first array has the values {1,2,3} and the second array has the value {1,2,3} does the method return false?
  • If the first array has the values {10,9,8} and the second array has the value {1,2,3,4,5,6} does the method return false?

Solutions

Expert Solution

COMPLETE CODE FOR THE FOLLOWING PROGRAM:-


// FILE:          Question.java
   // TITLE:         Course Enrollments
   // SUBMITTED BY:  Your Name Goes Here

   // PURPOSE:
   // This program takes two arrays of integers and  
   //returns true or false if the first array’s components are strictly
   //greater than the second array’s components. T
   //he arrays must be the same size or else return false.
   //Components meaning each value at a specific index. 
   
   // OVERALL METHOD:
   // The list of general tasks is:
   // 1. declare two integres array 
   // 2. pass them to largerComponents function 
   // 3. larger Components willl return false if two arrays 
   // are not equal in size if not
   // it will compare every elments of array one to elements of array 2 
   // if array one elements are greater than array 2 elements 
   //print true else print false.
   
   // FUNCTIONS:
   //
   // largerComponents
   // It takes two arrays and return true if elements
   // of array one is strictly greater than array two 

   
public class Question01  {
    
        // largerComponents function to check arrray one is strictly greater than two or not
        public static boolean largerComponents(int[] a, int[] b)
        {
                //-------------------------------  
                int count=0;
                //Write your solution here
                //If both arrays are equal in length
                if(a.length==b.length){
                    for(int i=0;i<a.length;i++)
                    {
                        if(a[i]>b[i]){
                            count++;
                        }
                    }
                    if(count==a.length){
                        return true;
                    }else{
                        return false;
                    }
                }else{
                    //if both arrays are not equal in length
                    return false;
                }
        }//Do not alter this
        //Test your code here. You may alter this as needed.
        public static void main(String[] args)
        {

                //declaration of two arrays
                int[] test01 = {5,4,3};
                int[] test02 = {2,1,0};

               //Calling largerComponents function
                System.out.println(largerComponents(test01,test02));
        }
        //--------------------------------------------------------------------------------
}//

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

SAMPLE OUTPUT:-

  • If the first array has the values {5,4,3} and the second array has the value {2,1,0} does the method return true?

  • If the first array has the values {1,2,3} and the second array has the value {1,2,3} does the method return false?

  • If the first array has the values {10,9,8} and the second array has the value {1,2,3,4,5,6} does the method return false?

HAPPY LEARNING


Related Solutions

Write a method weave that takes two arrays of ints, a and b, and that returns...
Write a method weave that takes two arrays of ints, a and b, and that returns an array that contains the elements of a and b in the order a[0], b[0], a[1], b[1], etc. If one of the arrays a or b is longer than the other, just add the extra elements at the end of the array. In your solution, you can use only 3 arrays, namely the two arrays a, and b passed to the method and the...
Write a Junit test method that takes 2 Arrays of type Integer[], and tests whether these...
Write a Junit test method that takes 2 Arrays of type Integer[], and tests whether these 2 Arrays are equal or not, and also if the elements are all even numbers. Describe under what conditions these 2 Arrays would be considered equal.
Write a program that takes two integer arrays a and b of size n from the...
Write a program that takes two integer arrays a and b of size n from the user, the use a method product to find the product of a and b and return the results after storing them in an array c, then prints the returned results to the screen. (Note: c[i] = a[i] * b[i], for i = 0, ..., n-1) Sample Output: Enter the size of your arrays: 5 Enter the integer values of the first array a: 1...
JAVA Arrays 4 Write a method called isPalindrome that takes a String as input and returns...
JAVA Arrays 4 Write a method called isPalindrome that takes a String as input and returns true if the String is a palindrome.
Write a function convert_date that takes an integer as a parameter and returns three integer values...
Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring). Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py A sample run for t03.py: Enter a date in the format MMDDYYYY: 05272017 The output will...
Write a method that takes two Sorted Arrays of different sizes and merges them into one...
Write a method that takes two Sorted Arrays of different sizes and merges them into one sorted array, and use the method to write a full recursive Merge Sort Algorithm.
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT