Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Expert Solution & Answer
Book Icon
Chapter 3, Problem 19C

Explanation of Solution

Methods add() and remove() for Scoreboard class without any loops:

Code for add() method:

//Define the add() method to add a new score to collection

public void add(GameEntry e)

{

/*Check whether the "numEntries" is less than length of board. */

  if (numEntries < board.length)

  {

  //Assign the new entry to score board

  board[numEntries] = e;

  //Increment "numEntries" by "1"

  numEntries++;

  }

}

Explanation:

In the above code,

  • This method accepts the input parameter of “e” to add a new score entry to collection of score board.
  • Check whether the “numEntries” is less than length of board. If yes,
    • Assign the new entry to score board.
    • Increment “numEntries” by “1”.

Code for remove() method:

/*Define the remove() method to remove and return a high score from collection. */

public GameEntry remove(int i) throws IndexOutOfBoundsException

{

/*Check whether the "i" is less than "0" and "i" is greater than "numEntries"...

Blurred answer
Students have asked these similar questions
write a java program (method) to store all arrangments(permuations) of a given string in an array. note: Here it has to be mentioned that the permutations can also be of shorter length than the list of letters and that no letter is to be repeated. For example, if the initial list of letters is "STOP", then "TOP" and "TOPS" are both valid permutations, but "STOPS" isn't.
Use Java programming. Write the removeEvens() method, which receives an array of integers as a parameter and returns a new array of integers containing only the odd numbers from the original array. The main program outputs values of the returned array. Hint: If the original array has even numbers, then the new array will be smaller in length than the original array and should have no blank elements. Ex: If the array passed to the removeEvens() method is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the method returns and the program output is: [1, 3, 5, 7, 9] Ex: If the array passed to the removeEvens() method is [1, 9, 3], then the method returns and the program output is: [1, 9, 3]   import java.util.Arrays; public class LabProgram { public static int[] removeEvens(int [] nums) { /* Type your code here */} public static void main(String[] args) { int [] input = {1,2,3,4,5,6,7,8,9};int [] result = removeEvens(input); // Helper method Arrays.toString() converts int[] to a…
You are asked to re-implement the insertion sort (InsertionSort.java), with additional requirements. Particularly: 1. For each iteration, how a number from a unsorted region is placed in the correction posion in the sorted region; 2. How to make the whole array be sorted based on the previous step, and count the total number of shifts during the whole insertion sort process. To complete the whole implementation, you should write at least the following important methods: Part1: insertLast /** A method to make an almost sorted array into fully sorted. @param arr: an array of integers, with all the numbers are sorted excepted the last one @param size: the number of elements in an array */ public static void insertLast(int[] arr, int size) { // your work } In this method, you are required to print the following information for each iteration until the termination of the loop: •The intermediate array content and •The comparing pair information Part2: insertionSort /** A method to make an…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education