Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7.2, Problem 11STQ
Give the definition of a static method called getArrayOfHalves that has an array of base type double as a single parameter and that returns another array whose base type and length are the same as those of the parameter, but whose elements have each been divided by 2.0.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
write a java method with followin instraction :
Write a method called prioritizeQueue to give priority for vaccination for elderly persons. The method is to be in a class called VaccinationQueue and has two parameters q1 and q2 type ArrayQueue. The q1 and q2 data are of type Integer. Assume that initially q1 is not empty and q2 is empty. The method will insert from q1 those elements towards the beginning of the queue (front) q2 whose data is greater than or equal to 45 and will insert those elements whose data is less than 45 and greater than or equal to 18 towards the end (rear) of q2. Any data item less than 18 of q1 will not be inserted in q2. It returns the number of elements added to q2.
Class ArrayQueue and all its methods including iterator are available for use. You can also create temporary queues. You are not allowed to use arrays or any other data structure.
Example:
Before method call:
front rear
q1: 14 25 50…
Please help me solve this with java
1-method called printArray that takes an array of double values and prints the arrayelements on the same line with one space between each two elements, then prints a new line.2. A method called getRandomElement that takes an array of double numbers and returns a random element from the array.3. A method called shiftArray that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place.For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become:3.3, 6.5, 2.1, 5.8, 1.54. A method called occurrences that takes a double value and an array of doubles as parameters, and returns the number of occurrences of the double value in the array.For example, if the double number 4.1 and the array {1.5,…
I need to have a main method in a Tester class that will:
Fill an array of type Vehicle[] of size NUM_VEHICLES with Vehicle objects. You need to generate a random number between 0 and 2. If the number is 0, add a Vehicle to the array. 1, add a Car, 2, add a Boat. The Vehicle/Car/Boat that you add must be initialized with a random efficiency between 0 and 100.0. Do this until you have added NUM_VEHICLES objects to the array
How do I write it so that the array generates random numbers 0 through 2 (inclusive) and how would I then correlate those numbers to a different class object?
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write code for a function with the following prototype: / Addition that saturates to TMin or TMax / int saturat...
Computer Systems: A Programmer's Perspective (3rd Edition)
Suppose you are using a multiuser operating system that allows you to view the names of the files belonging to ...
Computer Science: An Overview (12th Edition)
Suppose a multiprogramming operating system allocated time slices of 10 milliseconds and the machine executed a...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
In Exercises 71 and 72, write a statement to carry out the task. Pop up a message dialog box with "Taking Risks...
Introduction to Programming Using Visual Basic (10th Edition)
Find the error in each of the following program segments. If the error can be corrected, explain how.
C How to Program (8th Edition)
String Reverser Write a recursive method that accepts a string as its argument and prints the string in reverse...
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- This question involves reasoning about one-dimensional and two-dimensional arrays of integers. You will write three static methods, all of which are in a single enclosing class, named DiverseArray (not shown). The first method returns the sum of the values of a one-dimensional array; the second method returns an array that represents the sums of the rows of a two-dimensional array; and the third method analyzes row sums. (a) Write a static method arraySum that calculates and returns the sum of the entries in a specified one-dimensional array. The following example shows an array arr1 and the value returned by a call to arraySum. Value returned by arraySum (arr1) arrl Submit 1 3 4 3 7 16 Complete method arraySum below. / ** Returns the sum of the entries in the one-dimensional array arr. * / public static int arraySum (int [] arr) (b) Write a static method rowSums that calculates the sums of each of the rows in a given two-dimensional array and returns these sums in a one-dimensional…arrow_forwardI need quickly answerarrow_forwardWrite a method that accepts an array of integers as a parameter and returns a reference to an array that contains the even numbers in the original array. The returned array should have a size equal to the number of even numbers in the original array. Use Java language.arrow_forward
- Write a Java method that takes an array of type int and returns a boolean value. The method returns true if the number of positive elements in the parameter array is larger than the number of negative elements. The method returns false if any of the following conditions is satisfied: • The parameter array is of length of 0 or 1 • The number of positive elements of the parameter array is less than or equal to the number of negative elements • The number of positive elements or negative elements is equal to zero The method's header is as follows. public static boolean verify (int[] x) Sample run Result int[] x = (1, 2, 3}; verify(x); {5}; verify(x); int[] x = {1, 2, 3, -5, -1}; boolean b = verify(x); int[] x = new int[0]; verify(x); false boolean b = int[] x = boolean b = false true false boolean b = BIU A Paragraph +varrow_forwardWrite a program that includes in its MainClass the following methods: 1. A method called printArray that takes an array of integer values and a boolean value. The method prints the array elements on the same line with one space between each two elements. If the boolean value is true, the elements must be printed in their original order, if it is false they must be printed in reverse order. The method should print a new line after printing the array elements.arrow_forwardWhat is the answer?arrow_forward
- Write a method that takes two arrays as parameters. It should return a new array where each position has the sum of the two corresponding positions in the two incoming arrays. The returned array should be as long as the longer of the two passed in arrays.arrow_forward5. Write a static method largestColumnFirst() that receives as parameter a 2D array numAr,finds the column with the largest sum, and switches it with the first column. For example:6 7 9 4 8 9 7 6 4 83 2 7 4 1 → 7 2 3 4 19 4 5 8 3 5 4 9 8 3arrow_forwardIs it true that a method that takes an array as a parameter has access to the original array or just a replica of it?arrow_forward
- Write a RainFall class that stores the total rainfall for each of 12 months into an array of double s. The program should have methods that return the following: • the total rainfall for the year • the average monthly rainfall • the month with the most rain • the month with the least rain • Test the RainFall class by writing a tester class, RainFallDemo , to produce the outputs similar to the sample execution below. For the rainfall values, you must get them from the user’s input as double values in the tester class. For the class RainFall you must write standard Java Documentation for the whole class on the top, and for every method. Input Validation: Do not accept negative numbers for monthly rainfall figures. If a value is negative, ask the user to re-enter the input.arrow_forwardWrite a static method that takes an array of a generic type as its only argument. The method should display the array and return the number of elements in the array. Test the method in main with at least three arrays of objects. SAMPLE OUTPUT Here is an Integer array 12 21 7 16 8 13 That array held 6 elements Here is a String array one two three four That array held 4 elements Here is a Double array 1.1 2.2 3.3 4.4 5.5 That array held 5 elements My code: package radosavljevic19part1; import java.util.ArrayList;import java.util.Arrays; public class CreatorOfArray {public static void main(String[]args) {//creating array in three different typesInteger[]arr1= {12, 21, 7, 16, 8, 13};String []arr2={"one", "two", "three", "four"};Double[]arr3={1.1, 2.2, 3.3, 4.4, 5.5};//display arrays System.out.println("Here is an integer array: ");printList(arr1);System.out.println("\nHere is a String array: ");printList(arr2); System.out.println("\nHere is a Double array: ");printList(arr3);}//generic…arrow_forwardFOR JAVA Write a method that takes an integer array, prints the elements that are divisible by 3 and returns the sum of these elements. Write a method that takes an integer array and returns the difference between the sum of even indexed elements and the sum of odd indexed elements in that array. Write a method that takes a String array and an integer as parameters and prints the Strings in the array whose length is greater than the second parameter. Write a method that takes two integer arrays, and returns a new array by taking the intersection of the two arrays.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License