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
Water flows steadily through the pipe as shown below, such that the pressure at section (1) and at section (2) are 300 kPa and 1
steposvetlana [31]

Answer:

The velocity at section is approximately 42.2 m/s

Explanation:

For the water flowing through the pipe, we have;

The pressure at section (1), P₁ = 300 kPa

The pressure at section (2), P₂ = 100 kPa

The diameter at section (1), D₁ = 0.1 m

The height of section (1) above section (2), D₂ = 50 m

The velocity at section (1), v₁ = 20 m/s

Let 'v₂' represent the velocity at section (2)

According to Bernoulli's equation, we have;

z_1 + \dfrac{P_1}{\rho \cdot g} + \dfrac{v^2_1}{2 \cdot g} = z_2 + \dfrac{P_2}{\rho \cdot g} + \dfrac{v^2_2}{2 \cdot g}

Where;

ρ = The density of water = 997 kg/m³

g = The acceleration due to gravity = 9.8 m/s²

z₁ = 50 m

z₂ = The reference = 0 m

By plugging in the values, we have;

50 \, m + \dfrac{300 \ kPa}{997 \, kg/m^3 \times 9.8 \, m/s^2} + \dfrac{(20 \, m/s)^2}{2 \times 9.8 \, m/s^2} = \dfrac{100 \ kPa}{997 \, kg/m^3 \times 9.8 \, m/s^2} + \dfrac{v_2^2}{2 \times 9.8 \, m/s^2}50 m + 30.704358 m + 20.4081633 m = 10.234786 m + \dfrac{v_2^2}{2 \times 9.8 \, m/s^2}

50 m + 30.704358 m + 20.4081633 m - 10.234786 m = \dfrac{v_2^2}{2 \times 9.8 \, m/s^2}

90.8777353 m = \dfrac{v_2^2}{2 \times 9.8 \, m/s^2}

v₂² = 2 × 9.8 m/s² × 90.8777353 m

v₂² = 1,781.20361 m²/s²

v₂ = √(1,781.20361 m²/s²) ≈ 42.204308 m/s

The velocity at section (2), v₂ ≈ 42.2 m/s

3 0
3 years ago
A shunt regulator utilizing a zener diode with an incremental resistance of 8 ohm is fed through an 82-Ohm resistor. If the raw
spayn [35]

Answer:

\triangle V_0=0.08V

Explanation:

From the question we are told that:

Incremental resistance  R=8ohms

Resistor Feed R_f=82ohms

Supply Change \triangle V=1

Generally the equation for  voltage rate of change is mathematically given by

 \frac{dV_0}{dV}=\frca{R}{R_1r_3}

Therefore

 \triangle V_0=\triangle V*\frac{R}{R_fR}

 \triangle V_0=1*\frac{8}{8*82}

 \triangle V_0=0.08V

7 0
3 years ago
Argue the importance to society of incorporating green building into an engineer's designs, with at least two examples.
stellarik [79]

Answer:

Green Design is your answer

Explanation:

4 0
3 years ago
Read 2 more answers
A fluid of density 900 kg/m3 passes through a converging section of an upstream diameter of 50 mm and a downstream diameter of 2
NISA [10]

Answer:

Q= 4.6 × 10⁻³ m³/s

actual velocity will be equal to 8.39 m/s

Explanation:

density of fluid = 900 kg/m³

d₁ = 0.025 m

d₂ = 0.05 m

Δ P = -40 k N/m²

C v = 0.89

using energy equation

\dfrac{P_1}{\gamma}+\dfrac{v_1^2}{2g} = \dfrac{P_2}{\gamma}+\dfrac{v_2^2}{2g}\\\dfrac{P_1-P_2}{\gamma}=\dfrac{v_2^2-v_1^2}{2g}\\\dfrac{-40\times 10^3\times 2}{900}=v_2^2-v_1^2

under ideal condition v₁² = 0

v₂² = 88.88

v₂ = 9.43 m/s

hence discharge at downstream will be

Q = Av

Q = \dfrac{\pi}{4}d_1^2 \times v

Q = \dfrac{\pi}{4}0.025^2 \times 9.43

Q= 4.6 × 10⁻³ m³/s

we know that

C_v =\dfrac{actual\ velocity}{theoretical\ velocity }\\0.89 =\dfrac{actual\ velocity}{9.43}\\actual\ velocity = 8.39m/s

hence , actual velocity will be equal to 8.39 m/s

6 0
3 years ago
What engineers call moment, scientists call
Svet_ta [14]

Answer:

yes

Explanation:

7 0
3 years ago
Other questions:
  • Methane gas at 25°C, 1 atm enters a reactor operating at steady-state and burns with 80% theoretical air entering at 227°C, 1 at
    10·1 answer
  • Someone claims that the shear stress at the center of a circular pipe during fully developed laminar flow is zero. Do you agree
    12·1 answer
  • In a production turning operation, the foreman has decreed that a single pass must be completed on the cylindrical workpiece in
    7·1 answer
  • Megan is an architect who is creating a building design. Which is a prominent technical aspect that she needs to keep in mind wh
    12·1 answer
  • An alloy is evaluated for potential creep deformation in a short-term laboratory experiment. The creep rate is found to be 1% pe
    7·1 answer
  • 10. To cut 1/4" (6 mm) thick mild steel at a rate of 40 inches per minute, the current would be set to
    7·1 answer
  • Which of the following tape measure techniques can be used to achieve accurate measurements? Choose all that apply.
    14·1 answer
  • Solve the inequality below.Use the drop-down menus to describe the solution and its graph.
    12·1 answer
  • (20 points) A 1 mm diameter tube is connected to the bottom of a container filled with water to a height of 2 cm from the bottom
    12·1 answer
  • How many hours should I charge a 4.8v 600mah battery (I need it by today please)
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!