
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
To the HighArray class in the highArray.java, add a method called getMax() that returns the value of the highest key in the array, or 01 if the array is empty. Add some code in main() to exercise this method. You can assume all the keys are positive numbers.
![class HighArray
private long [] a; // zef to array a
private int nElems; // number of data items
//---
public HighArray (int max) // constructor
a = new long (max]; // create the array
nElems = 0; // no items yet
//--
public boolean find (long searchkey)
{ // find specified value
int j;
for (j=0; j<nElems; j++) // for each element,
if (alj] == searchkey) // found item?
break; // exit loop before end
if (j == nElems) // gone to end?
return false; // yes, can't find it
else
return true; // no, found it
} // end find ()
/-
public void insert (long value) // put element into array
a [nElems] = value; // insert it
nElems++;// incremment sise
//
public boolean delete (1long value)
int j;
for (j=0; jenElems; j++) // look for it
if ( value = alj))
break;
if (j==nElems) // can't find it
return false;
else // found it
for (int k=j; k<nElems; k++) // move higher ones doem
a[k] = a[k+1];
nElems--; // decrement sise
return true;
} // end delete ()
//---
public void display () // displays array contents
for (int j=0; j<nElems; j++) // for each element,
System.out.print (a(j) + "); // display it
System.out.println ("");
/-
} // end class HighArray
public class HighArrayApp{
public statie void main (String(] args) {
int max3ize = 100; // array size
HighArray arr; // reference to array
arr = rew HighArray (max3ise); // create the array
arz.insert (77); // insert 10 items
arz.insert (99);
arz.insert (44);
arz.insert (55);
.insert (22) ;
arz.insert (08);
arz.insert (11);
arr.insert (00) ;
arr.insert (66);
arr.insert (33);
azz.display); // display items
int searchkey = 35; // search for item
if( arr.find (searchKey))](https://content.bartleby.com/qna-images/question/cc7f96b0-6dc0-4972-bfe0-9c219792bf84/78a6be47-9f51-453e-b41d-def7b037a409/elfhh7o_thumbnail.jpeg)
Transcribed Image Text:class HighArray
private long [] a; // zef to array a
private int nElems; // number of data items
//---
public HighArray (int max) // constructor
a = new long (max]; // create the array
nElems = 0; // no items yet
//--
public boolean find (long searchkey)
{ // find specified value
int j;
for (j=0; j<nElems; j++) // for each element,
if (alj] == searchkey) // found item?
break; // exit loop before end
if (j == nElems) // gone to end?
return false; // yes, can't find it
else
return true; // no, found it
} // end find ()
/-
public void insert (long value) // put element into array
a [nElems] = value; // insert it
nElems++;// incremment sise
//
public boolean delete (1long value)
int j;
for (j=0; jenElems; j++) // look for it
if ( value = alj))
break;
if (j==nElems) // can't find it
return false;
else // found it
for (int k=j; k<nElems; k++) // move higher ones doem
a[k] = a[k+1];
nElems--; // decrement sise
return true;
} // end delete ()
//---
public void display () // displays array contents
for (int j=0; j<nElems; j++) // for each element,
System.out.print (a(j) + "); // display it
System.out.println ("");
/-
} // end class HighArray
public class HighArrayApp{
public statie void main (String(] args) {
int max3ize = 100; // array size
HighArray arr; // reference to array
arr = rew HighArray (max3ise); // create the array
arz.insert (77); // insert 10 items
arz.insert (99);
arz.insert (44);
arz.insert (55);
.insert (22) ;
arz.insert (08);
arz.insert (11);
arr.insert (00) ;
arr.insert (66);
arr.insert (33);
azz.display); // display items
int searchkey = 35; // search for item
if( arr.find (searchKey))

Transcribed Image Text:System.out.println ("Found "
+ searchkey);
else
System. out.printin ("Can't find " + searchkey);
arr.delete (00); // delete 3 items
arr.delete (55);
arr.delete (99);
arr.display (); // display items again
} // end main()
} // end class HighArrayApp
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

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
- In java, Write a method void popMult(int k) for the ArrayBoundedStack class which will pop k items from this. Throw a StackUnderflowException and don't pop anything if there are fewer than k items on this. This is a method of the ArrayBoundedStack class. DO NOT USE ANY OTHER METHODS OF THE ARRAYBOUNDEDSTACK CLASS.arrow_forwardI 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?arrow_forwardhow would you do this in a simple way? this is a non graded practice labarrow_forward
- Show your code and console with the exact sample run. Thankyouarrow_forwardin Java, please. Please add comments. Thank youarrow_forwardThis array method must be written by me. One at a time, shift all of the components to the right one at a time. position. 1 4 9 16 25 would become 25 1 4 9 16 in this case. Why can't I figure out how to make it to shift to the right instead of the left?Java 6th E. E7.10.b is the source of the issue.arrow_forward
- Define an empty array with 4 elements inside the "main" method. The value '-1' from the user to this arrayRecord the numbers entered by the user in order until they arrive. User array with 4 elementsAfter adding, write the required method so that it can continue adding elements. This method will take the array as a parameter, expand the size of the array and return the array variable.will return. Using this method you defined, the user can add elements to the array.make it continue.arrow_forwardNeeds to be written in java: Write a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values.1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below).2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. (print result from main())3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). (print result from main())Sample output:Enter a number:22Enter a number:34Enter a number:21Enter a number:35Enter a…arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. Write a method that takes in an array of Point2D objects, and then analyzes the dataset to find points that are close together. Be sure to review the Point2D API. In your method, if the distance between any pair of points is less than 10, display the distance and the (x,y)s of each point. For example, "The distance between (3,5) and (8,9) is 6.40312." The complete API for the Point2D ADT may be viewed at http://www.ime.usp.br/~pf/sedgewick-wayne/algs4/documentation/Point2D.htmlLinks to an external site.. Do not compare a point to itself! Try to write your program directly from the API - do not review the ADT's source code. (Don't worry too much about your answer compiling - focus on using an API from its documentation.) Your answer should include only the method you wrote, do not write a complete program.arrow_forward
- Without using any pre-defined method. Don't copy from internet Two array is given and you check whether these array is equal or not in java. Without using any pre-defined methodarrow_forwardI need help with Chapter 10. Practice exercise 10.9 of the Introduction to Java 11 edition book. I tried using the textbook example but I got a few errors I couldn't figure out how to fix.arrow_forwardWrite a class ArrayClass, where the main method asks the user to enter the four numbers. Create a method printArray that prints the array whenever required (use Array.toString method). Make the program run as shown in the Sample Run below. Use Array.sort, Arrach.bianrySearch, Array.equalsarrow_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