Suppose that we are selling boxes of candy for a fund-raiser. We have five kinds of candy to sell: Mints, Chocolates with Nuts, Chewy Chocolates, Dark Chocolate Creams, and Sugar-Free Suckers. We will record a customer’s order as an array of five integers, representing the number of boxes of each Kind of candy. Write a static method combineorder that takes two orders as its arguments and returns an array that represents the combined orders. For example, if order1 contains 0, 0, 3, 4, and 7, and order2 contains 0, 4, 0, 1, and 2, the method should return an array containing 0, 4, 3, 5, and 9.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java : Introduction To Prob...-MyProgrammingLab
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Database Concepts (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Programming in C
Concepts of Programming Languages (11th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- Needs to be written in java: Write a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values.1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below).2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. (print result from main())3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). (print result from main())Sample output:Enter a number:22Enter a number:34Enter a number:21Enter a number:35Enter a…arrow_forwardJAVA PROGRAM Write a program that asks the user to input two integers a and b. Then create an array that has all integer from a to b. Print out the array. (Don’t forget to consider the situation of a=b, a<b, and a>b.) Example 1: Input two numbers: 6 2 Array is [6, 5, 4, 3, 2] Example 2: Input two numbers: 4 8 Array is [4, 5, 6, 7, 8] Pass the above array as a parameter to a method called average and return the average and print it out in the main method. (Do not use Math library to get the average.)arrow_forwardIn java, Write a method checks if a given matrix is a unit matrix. An N x N unit matrix is a matrix of N rows and N columns where all the diagonal elements are ‘1’s and all the remaining elements are ‘0’s. The method should take a 2D array of integers as argument and return a Boolean which is true/false depending on whether the matrix corresponding to the 2D array is a unit matrix or not. Test the method in the ‘main’ method. For problems asking for 'methods', you need to write the method, and the 'main' method which is used as a 'driver' to test the given method.arrow_forward
- Write a static method: public static double intersectionSum(double[] a, double[] b) that takes two double arrays as arguments and returns the sum of the elements the two arrays have in common. In other words, the result should be the sum of every element in the two arrays where a[i] is equal to b[i] for some index i. Note that the two arrays may not be the same length. In these cases, you should only consider the indices that the arrays have in common (the indices of the shorter array). If either (or both) arrays are empty or null, the result should be 0.0. Example 1: intersectionSum({3.0, -4.0, 5.8, 6.75}, {3.0, 2.5, 5.8, 4.95}) è 8.8, since a[0] == b[0] and a[2] == b[2] and 3.0 + 5.8 = 8.8 Example 2: intersectionSum({8.5, 9.75, 1.25}, {3.5, 9.75, 1.25, 8.5, -2.34}) è11.0, since a[1] == b[1] and a[2] == b[2] and 9.75 + 1.25 = 11.0arrow_forwardWrite (define) a public static method named countGreaterThan, that takes an array of int, and an int as arguments and returns (as an int) a count of the number of values in the argument array that are greater than the second argument value. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; countGreaterThan(myArray, 200) should return 3 countGreaterThan(myArray, 9999) should return 0 You may wish to write some additional code to test your method. ------------------------------------------- public class Main { public static void main(String[] args) { // you may wish to write some code in this main method // to test your method. } // define your method(s) here below }arrow_forwardFOR JAVA // Question is the first one, try to solve it by using the second question. Repeat the second question, but if there are multiple occurrences of the number, your program must return the largest index instead of the small- est. Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index.arrow_forward
- You are given an array of n integers. Write a java method that splits the numbers of the array into two equal groups so that the GCD of all numbers in the first group is equal to one and the GCD of all numbers in the second group is not one. After splitting the numbers display the resulting groups as shown in the sample run below. Note: 1. The array has even size. 2. All elements of the array are less than 100. 3. You can define at most only one one-dimensional array. Sample run of the method: Input array: {6,7,9,4,3,2} Output Group one : {7,9,3} //Ignore Order of numbers. Order is not important Group two: {2,4,6} //Ignore Order of numbers. Order is not importantarrow_forwardIn java Implement a public static double[] ageMetrics(Patient[] patients) method that returns an array of length 3 with the following three values (starting at index 0): The age of the youngest patient The age of the oldest patient The mean age of all patientsarrow_forwardWrite a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. USING A JAVA…arrow_forward
- Write a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. THE OUTPUT…arrow_forwardWrite a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. THE OUTPUT…arrow_forwardWrite (define) a public static method named getIndexOfMax, that takes an Array of int as an argument and returns the intindex of the greatest value in the array. All values in the argument array will be different. For example, given the following Array declaration and instantiation: int[] myArray = {333, 22, 1, 400, 5005, 9}; getIndexOfMax(myArray) will return 4 ------------------------------------------------ public class Main { public static void main(String[] args) { // you may wish to write some code in this main method // to test your method. } <your method definition here> }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education