Concept explainers
Suppose that we create an array A of GameEntry objects, which has an integer scores field, and we clone A and store the result in an array B. If we then immediately set A[4].score equal to 550, what is the score value of the GameEntry object referenced by B[4]?
Trending nowThis is a popular solution!
Learn your wayIncludes step-by-step video
Chapter 1 Solutions
Data Structures and Algorithms in Java
Additional Engineering Textbook Solutions
Vector Mechanics For Engineers
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
HEAT+MASS TRANSFER:FUND.+APPL.
- Write a program that creates a 2-D array initialized with test data . Use any primitive type of data EXCEPT int (Integer). The program should have all methods in the problem. getTotal - This method should accept a two-dimensional array as its argument and return the total of all the values in the array. getAverage - This method should accept a two-dimensional array as its argument and return the average of all the values in the array. getRowTotal. - This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. getColumnTotal - This method should accept a two-dimensional array as its First argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column.…arrow_forwardGiven an array temps of double, containing temperature data, and an int variable n that contains the number of elements in temps: Compute the average temperature and store it in a variable called avgTemp. Besides temps, n, and avgTemp, you may use only two other variables -- an int variable k and a double variable total, which have been declared.arrow_forwardyou created a Card class that represents a standard playing card. Use this to design and implement a class called DeckOfCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck.Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck. This is my Card class: mport java.util.Random; /*Card.java Richard Mino * This is a program demonstrating the use of random and predetermined objects and values in the form * of a playing card using getter/setter methods and two constructors and printing them out as a string * using the toString method */public class Card { //Set up variables for card rank and…arrow_forward
- Write code that will accept as input the characteristics of an undefined number of different softdrinks. Each softdrink should have a colour (of the can), name and volume. • Create SoftDrink objects and store them in an ArrayList (see the Appendix) as each softdrink is entered. • Alternatively, you can use an array. Take a number of items first, create an array of that size and read in the elements. • Prompt the user to add a softdrink until they choose to quit. • Once the user quits, print out a list of the softdrinks that the user has entered, sorted first by alphabetical order of name, then by colour, then by volume (ascending order). Name your driver class Question2.java. NOTE: • You can use the built-in static sort() method in the java.util.Collections class to sort your ArrayList of SoftDrink objects. Sample I/O Enter option: (1) add soft drink (2) quit: 1 Enter name, colour and volume in ml separated by space Fanta Orange 500 Enter option: (1) add soft drink (2)…arrow_forwardIn this lab assignment you need to implement the method named middleValue, in a program named ArrayOps.java. The method accepts an array of integer values as a parameter, and returns the value in the middle of the array. For instance, if an array contains five elements, then the third element would be the middle element to be returned. However, if the array contains six elements, both the third and fourth values could be considered to be the middle elements. In this case, only return the first middle value, namely, the third element of the array. Complete the method middleValue, and test the correctness of your method in main(). Particularly, you should create two arrays (arbitrary values), one array with odd length, and the other with even length, and print out the middle values of these two arrays.arrow_forwardSuppose we have a 1-D array of Strings such that: • Each string records individual scores for different quizzes for one student. • Each string has the form "d1;d2;d3;.;dn;" where d1 to dn are all double values and they are separated using the character . Note that there is one ; after the last double value. • Each string contains the same number of double values. Write the method convert that takes a 1-D array of such Strings and an integer n as inputs, where n means the number of double values in each String in the array and returns a 2-D array containing doubie values. In the two 2-D array, each row records scores of one student and each column contains scores of one exam for all students. For example, if the parameters are ("1:2;3:4;", "5:6:7;8;", "9;10;11;12;") and 4, then the output would be a 3'4 2-D array which has the value ((1.0, 2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0), (9.0, 10.0, 11.0, 12.0). You are supposed to use the provided String library methods to operate these string…arrow_forward
- There is an array of n integers. There are also 2 disjoint sets, A and B, each containing m integers. You like all the integers in set A and dislike all the integers in set B. Your initial happiness is 0. For each i integer in the array, if i E A, you add 1 to your happiness. If i E B, you add -1 to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end. Note: Since A and B are sets, they have no repeated elements. However, the array might contain duplicate elements. Constraints 1≤n ≤ 105 1≤m≤ 105 1 Any integer in the input ≤ 10⁹ Input Format The first line contains integers n and m separated by a space. The second line contains n integers, the elements of the array. The third and fourth lines contain m integers, A and B, respectively.arrow_forwardThere is an array of n integers. There are also 2 disjoint sets, A and B, each containing m integers. You like all the integers in set A and dislike all the integers in set B. Your initial happiness is 0. For each i integer in the array, if i E A, you add 1 to your happiness. If i E B, you add -1 to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end. Note: Since A and B are sets, they have no repeated elements. However, the array might contain duplicate elements. Constraints 1≤ n ≤ 105 1≤m≤ 105 1 Any integer in the input ≤ 10⁹ Input Format The first line contains integers n and m separated by a space. The second line contains n integers, the elements of the array. The third and fourth lines contain m integers, A and B, respectively.arrow_forward1. Declare an array to save 4 Dog objects. The Dog class is provided below. Look into the Dog class and find what attributes are needed for a dog object. Then initialize five dogs with the following information: Lily, 5 years old Jacob, 2 years old Sugar, 8 years old Bush, 3 years old 2. Print out every dog using a for loop (use either regular for loop or for-each loop, your choice). But you may find when you print out, the name and age are not displayed. Why? 3. Fix this problem by implementing the toString method in the Dog class. Dog Class: public class Dog { private String name; private int age; public Dog(String name, int age) { this.name = name; this.age = age; } public void setName(String name) { this.name = name; } }arrow_forward
- Please use java. In this assignment, you will implement a class calledArrayAndArrayList. This class includes some interesting methods for working with Arrays and ArrayLists. For example, the ArrayAndArrayList class has a “findMax” method which finds and returns the max number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, calling findMax(array) will return 9. There are 4 methods that need to be implemented in the A rrayAndArrayList class: ● howMany(int[] array, int element) - Counts the number of occurrences of the given element in the given array. ● findMax(int[] array) - Finds the max number in the given array. ● maxArray(int[] array) - Keeps track of every occurrence of the max number in the given array. ● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the given array. Each method has been defined for you, but without the code. See the javadoc for each method for instructions on what the method is supposed to do and how…arrow_forwardYou will be given a collection of five cards (representing a player's hand in poker). If your hand contains at least one pair, return an array of two elements: true and the card number of the highest pair (trivial if there only exists a single pair). Else, return false. Examples highestPair(["A", "A", "Q", "Q", "6"]) [true, "A"] highest Pair(["]", "6", "3", "10", "8"]) → false highest Pair(["K", highest Pair(["K", "9", "10", "J", "Q"]) false highest Pair(["3", "5", "5", "5", "5"]) [true, "5"] "7", "3", "9", "3"]) → [true, "3"] ➡ - Notes Hands with three or more of the same card still count as containing a pair (see the last example).arrow_forwardWrite a hangman game that randomly generates a word andprompts the user to guess one letter at a time, as presented in the sample run.Each letter in the word is displayed as an asterisk. When the user makes a correctguess, the actual letter is then displayed. When the user finishes a word, displaythe number of misses and ask the user whether to continue to play with anotherword. Declare an array to store words, as follows:// Add any words you wish in this arrayString[] words = {"write", "that",...}; (Guess) Enter a letter in word ******* > p↵Enter(Guess) Enter a letter in word p****** > r↵Enter(Guess) Enter a letter in word pr**r** > p↵Enterp is already in the word(Guess) Enter a letter in word pr**r** > o↵Enter(Guess) Enter a letter in word pro*r** > g↵Enter(Guess) Enter a letter in word progr** > n↵Entern is not in the word(Guess) Enter a letter in word progr** > m↵Enter(Guess) Enter a letter in word progr*m > a↵EnterThe word is program. You missed 1 timeDo…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