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: An Introduction to Problem Solving and Programming (8th Edition)
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)
- In Java Write a RainFall class that stores the total rainfall for each of 12 months into anarray of doubles. The program should have methods that return the following: Total rainfall for the year, The average monthly rainfall The month with the most rain The month with the least rainThe program should not accept negative numbers for monthly rainfall figures.You may use the following main function to test the methods:public static void main(String[] args) { // Array with this year's rainfall data double[] thisYear = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7 }; int high; // To hold the month with the highest amount int low; // To hold the month with the lowest amount // Display the total rainfall. System.out.println("The total rainfall for this year is " + getTotalRainFall(thisYear)); // Display the average rainfall. System.out.println("The average rainfall for this year is " + getAverageRainFall(thisYear)); // Get and display the month with the highest rainfall.…arrow_forwardWrite the following methodarrow_forwardWrite a Java method that reverses a given array. the method that reverses the array passed in the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers, and displays the numbers.arrow_forward
- Write a method to read numbers from the keyboard into an array. Stop reading when the user enters the sentinel value -999. Return the number of values that were read. Do not put the sentinel in the array and do not include it in the number of values entered. Print an error message and stop reading if the user tries to enter more values than the array can hold.Write a method to print out the numbers in the array. Make sure the method only prints the array positions that were filled with the user's input. Print one number on each line.Write a method called zeros to return the number of entries in the array which contain zero.Write a method called replace which includes the parameters before and after, which are both integers. The method will change every array entry that contains the value before to contain the value after. For example, if the array contains {10,20,30,40,20,50}, before is 20 and after is 1, the array should be changed to {10,1,30,40,1,50}.Write a method called positive…arrow_forwardPlease help me with these array questions using javaarrow_forwardWrite a java application which initializes an array with ten random integers between 1 and 6. Write two methods: 1. arraySwap: this method should accept an integer array and swap the first and the last item. 2. findMinimum: this method should accept the array and return the minimum value of that array You should comment and follow javaDoc for both methods. Your main method should test each of these methods.arrow_forward
- Create a Golf Game. Allow for two players. Prompt for the player names. Each player plays 18 holes. Use an array or List for each player to hold their number of swings for each hole. Logical methods should be implemented for different tasks (broken out below). It is up to you to determine the parameters and return types of each method as appropriate. Method 1 - For each hole, the player has a number of swings. Determine the player's swings by generating a random number between 1 and 4. Store each players number of swings in the array/list. Method 2 - After completing the 18 holes, add up the number of swings for each hole for each player. The player with the fewest number of swings is the winner. Method 3 - Save the game data into a CSV file in the main project (root) directory. Name the file "Golf_Game_Player1_Player2.csv" using the player's names. The information in the file should look like this: playername, scoreforhole1, scoreforhole2, scoreforhole3, etc... Method 4 - In the…arrow_forwardJava: Write a complete method to create an array of random integers. Method Specification The method takes in three integer parameters: the array size, the lower bound, and the upper bound. The method also takes in a boolean parameter. The method creates and returns an integer array of the specified size that contains random numbers between the lower and upper bound., using these rules: The lower bound is always inclusive. If the boolean parameter is true, the upper bound is also inclusive. If the boolean parameter is false, the upper bound is not inclusive (meaning it is exclusive). If any of the parameters are invalid, null is returned. Driver/Tester Program I have provided you with a driver/tester program that you can use to test your code before submitting. Paste your code into the placeholder at the top of the file. Review the Homework FAQ page, which contains instructions and a video of how to use the provided file. If you aren't sure how to use the tester or have any…arrow_forwardJava: Write a complete method to create an array of random integers. Method Specification The method takes in three integer parameters: the array size, the lower bound, and the upper bound. The method also takes in a boolean parameter. The method creates and returns an integer array of the specified size that contains random numbers between the lower and upper bound., using these rules: The lower bound is always inclusive. If the boolean parameter is true, the upper bound is also inclusive. If the boolean parameter is false, the upper bound is not inclusive (meaning it is exclusive). If any of the parameters are invalid, null is returned. Driver/Tester Program I have provided you with a driver/tester program that you can use to test your code before submitting. Paste your code into the placeholder at the top of the file. I strongly recommend running this program before you submit your homework. The program is designed to help you catch common errors and fix them before submitting.…arrow_forward
- Write a method that receives an array to determine how many scores are above or equal to the average. Assume that the maximum number of scores is 100. The header of the method is as follows:arrow_forwardYou 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_forwardPLEASE HELP ME WITH MY JAVA HOMEWORK PLEASE PLEASE!Write a program that stores positive random integers in an array. Get the element number(length of the array) from the user. It cannot be less than 10. And fill this array andomly. The range is up to you. No duplicate values are allowed. Display the elements. Your job is to write a method that finds and returns the next biggest positive integer considering the biggest element in this array. Show me your main method too. DO NOT USE ANY PRE_DEFINED METHODS IN THE JAVA API.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage