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
Electric Circuits. (11th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Degarmo's Materials And Processes In Manufacturing
Starting Out With Visual Basic (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- We have the following method used in a chess game: boolean canMoveTo(int x, int y). This method is part of the Piece class and returns whether or not the piece can move to position (x, y). Explain how you would test this method.arrow_forwardUSING JAVA Write a method intToWeekDay(integer) that returns a week day if integer is belongs to {0,1,...,6} by using enumeration type. For example, calling intToWeekDay(0) returns "Sunday".arrow_forwardcomputer programmingarrow_forward
- In C# using an array Implement the inventory manager class. This class must have methods that do the following: Add a new item to the inventory manager. Remove an item from the inventory manager. Re-stock an item in the inventory manager. Display the items in the inventory manager. Search for an item in the inventory manager by at least two criteria (name, price, quantity, etc.). Test the inventory manager class with a driver program or unit tests. This may be a console application.arrow_forwardAdd a method called multiplesOfFive to the Exercise class. The method must have a void return type and take a single int parameter called limit. In the body of the method, write a while loop that prints out all multiples of 5 between 10 and limit (inclusive) on a single line. For instance, if the value of limit were 15 then the method will print: 10 15 You can use the printEvenNumbers method that is already in the Exercise class as an example to help you work out how to complete this method. In the main method of the Main class, add a call on the Exercise object to your multiplesOfFive method that prints the multiples of 5 between 10 and 25. Add a method called sum to the Exercise class. The method must have a void return type and take no parameters. In the body of the method, write a while loop to sum the values 1 to 10 and print the sum once the loop has finished. In the main method of the Main class, add a call on the Exercise object to your sum method. Check that it prints: 55 Add…arrow_forwardImage one is my file or you can create ur own file as long as it's similar to mine. image 2 is my program I want to write a 4th method(method 4) and the spec is: A method to count the occurrences of each value in an array takes one parameter, an array of integers returns an array containing the number of times each value occurs in the parameter array. Also should call method 3 from method 4Hint: The general idea of this method is using an array with length maxVal+1(maxVal should get from method 3 already) to save the occurrences of each number. For example, if number 44 occurs 3 times in the file, your array should have a value 3 stored at index 44.arrow_forward
- Assumptions You will pick exactly two songs. You cannot pick the same song twice. If you have multiple pairs with the same total time, select the pair with the longest song. There are at least two songs availablearrow_forwardAll coding is done in Java, using IntelliJ Idea. 3. Charge Account Validation Create a class with a method that accepts a charge account number as its argument. The method should determine whether the number is valid by comparing it to the following list of valid charge account numbers: 5658845 4520125 7895122 8777541 8451277 1302850 8080152 4562555 5552012 5050552 7825877 1250255 1005231 6545231 3852085 7576651 7881200 4581002 These numbers snould be stored in an array or an ArrayList Object. Prompt the user to choose search methodology between sequential/linear search, and binary search before the search is performed. Have the search locate the number passed as an argument. If the number is in the array, the method should return true, indicating the number is valid. If the number is not…arrow_forwardA teacher has three exam grades for all the members of her class, and she worries that the grades are too low. You need to complete the method, named testAverage, in the class named Grades.java. There are two parameters to this method: the first is an integer representing the number of students in the class and, the second is a two-dimensional array of integers. In other words, each row represents the three grades for one student, while the columns represent the three sets of test grades. The return value should be the number of students with an average exam grade below seventy. The grades should be treated as double variables. For example, consider the grades for the four students in the following 2-D array, [ [88, 84, 89] [76, 64, 67] [85, 76, 79] [95, 90, 91] ] The first student has an exam average of 87.0 (= (88+84+89)/3 = 261/3), the second student has an exam average of 69.0 (= (77+64+67)/3 = 207/3), the third student has an exam average of 80.0 (= (85+76+79)/3 = 240/3), while…arrow_forward
- A teacher has three exam grades for all the members of her class, and she worries that the grades are too low. You need to complete the method, named testAverage, in the class named Grades.java. There are two parameters to this method: the first is an integer representing the number of students in the class and, the second is a two-dimensional array of integers. In other words, each row represents the three grades for one student, while the columns represent the three sets of test grades. The return value should be the number of students with an average exam grade below seventy. The grades should be treated as double variables. For example, consider the grades for the four students in the following 2-D array, [88, 84, 89] [76, 64, 67] [85, 76, 79] [95, 90, 91] The first student has an exam average of 87.0 (= (88+84+89)/3 = 261/3), the second student has an exam average of 69.0 (= (77+64+67)/3 = 207/3), the third student has an exam average of 80.0 (= (85+76+79)/3 = 240/3), while the…arrow_forwardCreate a java class called ArrayOperations. Add the static methods described below. Then write a test class to verify that all of your methods work. Static Methods for ArrayOperations The lcass name is ArrayOperations It has one static method called findSum. This method returns the sum of the elements in an array To invoke this method from another class, we use the class name (ArrayOperations.findSum(MyArray)); toString : This method signature should be: public static String toString(int[] anArray). It should return a String that consists of all elements in the array. For example if the input array consists of {1, 5, 9, 2}, then toString should return the string 1 5 9 2 findMaxMin : The signature for this method should be public static int[] findMaxMin(int[] anArray) Notice that the method returns an array of int – not a single value. In this method Write code to declare an array of int with two elements – say limits Find the largest element in the array and store it in limits[0]…arrow_forwardCreate the Median class that has the method calculateMedian that calculates the median of the integers passed to the method. Use method overloading so that this method can accept anywhere from two to five parameters. CODE: import java.util.Arrays; //add class definitions below this line //add class definitions above this line public class Exercise4 { public static void main(String[] args) { //add code below this line //add code above this line }}arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage