1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Montano1993 [528]
2 years ago
13

2.4: Add a method called setValue(), and the description of setValue is: public int setValue(long searchKey) In this method, the

array will be examined if searchKey is already in the array. If this is the case, the index of found searchKey in the array will be returned; If searchKey is not in the array, insert it to the array and return the index where it is inserted. Add some code in main() to exercise this method.
Engineering
1 answer:
Yanka [14]2 years ago
6 0

Answer:

Below is java code that must be used for the given question:

// highArray.java

// demonstrates array class with high-level interface

// to run this program: C>java HighArrayApp

////////////////////////////////////////////////////////////////

class HighArray

  {

  private long[] a;                 // ref 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 setValue find(long searchKey)

     {                              // find specified value

     int j;

     for(j=0; j<nElems; j++)            // for each element,

        if(a[j] == 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++;                      // increment size

     }

  //-----------------------------------------------------------

  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

////////////////////////////////////////////////////////////////

class HighArrayApp

  {

  public static void main(String[] args)

     {

     int maxSize = 100;            // array size

     HighArray arr;                // reference to array

     arr = new HighArray(maxSize); // create the array

     arr.insert(77);               // insert 10 items

     arr.insert(99);

     arr.insert(44);

     arr.insert(55);

     arr.insert(22);

     arr.insert(88);

     arr.insert(11);

     arr.insert(00);

     arr.insert(66);

     arr.insert(33);

     arr.display();                // display items

     int searchKey = 35;           // search for item

     if( arr.find(searchKey) )

        System.out.println("Found " + searchKey);

     else

        System.out.println("Can't find " + searchKey);

     }  // end main()

  }  // end class HighArrayApp

Explanation:

You might be interested in
Technician A says amperage cannot exist without both voltage and resistance. Technician B says if amperage is high, then you kno
Ivan

Answer:

Technician A

Explanation:

Ohms law:  I= E/R so rest resistance must be present along with E/potential difference.  Even if just wire shorted together there is resistance but very little.

Tech B: Again ohms law.  Current flow is directly proportional to the voltage and inversely  proportional to R (resistance or impedance).

8 0
3 years ago
What material resources and intellectual resources were used in self driving cars?
fomenos

Answer: material resources: cameras, light detection and ranging systems, radar, sensors, advanced GPS, and millions of miles of training data, and more

I don't know about the intellectual resources sorry

5 0
3 years ago
I’m doing a project on renewable energy. There are 6 energy sources. Solar, wind, geothermal, hydroelectric, tidal, and biomass.
nalin [4]

Answer:

"Biofuels"

Explanation:

I don't know if this counts but I guess it's not one of those.

6 0
2 years ago
Read 2 more answers
Pedro holds a heavy science book over his head for 10 minutes. Petro is doing work during that time. True or False
algol [13]

Answer:

True because he is working his arms to lift and hold the weight

Explanation:

4 0
3 years ago
Can you solve this question​
Alecsey [184]

Answer:

eojcjksjsososisjsiisisiiaodbjspbcpjsphcpjajosjjs ahahhahahahahahahahahahahahahhhahahahaahahhahahahahaahahahahaha

6 0
2 years ago
Read 2 more answers
Other questions:
  • The popularity of orange juice, especially as a breakfast drink, makes it an important factor in the economy of orange-growing r
    14·1 answer
  • Five bolts are used in the connection between the axial member and the support. The ultimate shear strength of the bolts is 320
    5·1 answer
  • WHAT IS A TOROID IN HYDRAULUCS?
    11·2 answers
  • ITS FOR DRIVERS ED!!
    13·2 answers
  • For all the problems describe all pieces to the equations. 1.What is the equation for normal stress? 2.What is the equation for
    7·1 answer
  • You are given a C program "q2.c" as below. This program is used to calculate the average word length for a sentence (a string in
    5·1 answer
  • Consider a step pn junction made of GaAs at T = 300 K. At zero bias, only 20% of the total depletion region width is in the p-si
    11·1 answer
  • What is one of the most common ways in which workers get hurt around machines?
    14·1 answer
  • How many times greater is the value of the 2 of the 270413 than the valuce of the 2 in 419427?
    8·1 answer
  • A kitchen contains one section of counter that's 20 inches
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!