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]
3 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]3 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
Air at 500 kPa and 400 K enters an adiabatic nozzle at a velocity of 30 m/s and leaves at 300 kPa and 350 K. Using variable spec
adoni [48]

Answer: a) Efficiency = 0.92

b) V = 319.19 m/s

c) S = 0.012 kj/kg.k

Explanation: please find the attached files for the solution

3 0
3 years ago
Why does my car accelerate slowly when i press the gas
olya-2409 [2.1K]
If the pump stops working, malfunctions, or becomes clogged, it will not supply enough fuel to the injectors.
6 0
3 years ago
At what voltage would a () capacitor have the minimum energy to raise by ignoring all losses in the system? If needed, you may a
Charra [1.4K]

Answer:

V = 280.15 V

Explanation:

" The complete question is attached with figure"

Given:

- The capacitance of the capacitor C = 10 nF

- The amount of mass attached to motor m = 4 grams

- The amount of distance it is to be lifted h = 1 cm

- Ignore all other losses in the system

Find:

- The voltage required to lift the mass m through distance h?

Solution:

- The conservation of energy for the entire system is written as:

                            Work_gravity = U_c

Where,

           Work_gravity: Work done by gravity on mass m

           U_c: The amount of energy stored in a capacitor

                             m*g*h = 0.5*C*V^2

                             V^2 = 2*m*g*h / C

                             V = sqrt ( 2*m*g*h / C )

Plug in the values:

                             V = sqrt ( 2*0.004*9.81*0.01 / 10*10^-9 )

                             V = sqrt ( 78,480)

                             V = 28.15 V

8 0
3 years ago
Consider each statement below and determine which are correct concerning dietary fiber. Select all that apply. View Available Hi
PIT_PIT [208]

Answer:

Increasing the amount of fiber in your diet can aid in achieving and maintaining a healthy weight. This is correct if you are consuming less than 25-30gms of fiber per day. exceding this limit won't be beneficial.

Consuming a high-fiber diet most likely promotes the health of the digestive system. This is correct. Fibers are important for the digestive system´s health, especially for intestines and colon.

Fiber and other carbohydrates like starch and sugar are digested and absorbed in the same manner. This is Incorrect. Fiber is absorbed and digested at a much slower rate than sugar or starch.

Consuming a diet high in dietary fiber increases LDL "the bad" cholesterol. This is incorrect. Consuming a diet high in dietary fiber would decrease the LDL.

Most American women consume more than 20 g of fiber per day, and most American men consume more than 30 g per day. This is incorrect. The data obtained by the University of California San Francisco said that currently the amount of fiber intake by Americans adults is about 15g a day, which is half the recommended amount.

7 0
3 years ago
Read 2 more answers
A 1.5 m x1.5 m square footing is supported by a soil deposit that contains a 16.5 m thick saturated clay layer followed by the b
iren [92.7K]

Answer:

somewhere around 34.2223 meters thick but that's what I am estimating.

7 0
2 years ago
Other questions:
  • Two forces, one of which double the other has resultant of 280N. if the direction of the large force is reversed and the remaini
    6·1 answer
  • The sum ofall microscopic forms of energy of a system is quantified as flow energy. a)True b) False
    5·1 answer
  • (3) In the following power system, the transformer is assumed to be ideal. Determine the: a) currents and voltages across each i
    9·1 answer
  • Add a calculated field named AccountTime that calculates the number of days each client's accounts have been open. Assume today'
    6·1 answer
  • 1.0•10^-10 standard form
    6·1 answer
  • What is the basic formula for actual mechanical advantage?
    12·1 answer
  • Suppose you are choosing between four different desktop computers: one is an Apple Mac Intosh and the other three are PC-compati
    14·1 answer
  • Breh/bro <br><br>what is this, finally I can learn programming​
    12·1 answer
  • A system consists of a disk rotating on a frictionless axle
    14·1 answer
  • What is the difference between an arch and a dome?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!