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
Structural engineers use wireless sensor networks to monitor the condition of dams and bridges.
qwelly [4]

Answer: True

Explanation:

Structural engineering is simply referred to as a branch of civil engineering, and they help in the designing of structures like buildings, dams, tunnels, bridges, tunnels, etc. Structural engineers typically work as consultants.

Wireless sensor networks are used by structural engineers to monitor the condition of dams and bridges. Wireless sensor network refers are dedicated sensors that are used in monitoring the physical conditions of the bridges and to know if they're still in good conditions.

8 0
3 years ago
You can safely place a jack on a floor pan to keep a vehicle steady.
Elis [28]

Answer: Yes

Explanation:

7 0
3 years ago
Read 2 more answers
¿Cuál era probablemente el activo más valioso de Persia?
laila [671]

Answer:

su suministro de aceite

Explanation:

(it's oil supply)

8 0
3 years ago
Read 2 more answers
Need help please????????!!!!!!
Alekssandra [29.7K]

Answer A the more traing the more you will know

Explanation:

4 0
3 years ago
What is a business cycle? a period of economic growth followed by economic contraction the amount of time it takes a business to
Rzqust [24]

Business cycle and its growth followed by economic contraction the amount of time it takes a business to produce products in the following way.

Explanation:

The business cycle is the periodic but irregular up-and-down movement in economic activity, measured by fluctuations in real gross domestic product (GDP) and other macroeconomic variables.

A business cycle is typically characterized by four phases—recession, recovery, growth, and decline—that repeat themselves over time.

Economists note, however, that complete business cycles vary in length. The duration of business cycles can be anywhere from about two to twelve years, with most cycles averaging six years in length.

FACTORS THAT SHAPE BUSINESS CYCLES

Volatility of Investment Spending

  • Variations in investment spending is one of the important factors in business cycles. Investment spending is considered the most volatile component of the aggregate or total demand (it varies much more from year to year than the largest component of the aggregate demand, the consumption spending), and empirical studies by economists have revealed that the volatility of the investment component is an important factor in explaining business cycles in the United States.

Momentum

Technological Innovations

Variations in Inventories

Fluctuations in Government Spending

Politically Generated Business Cycles

Monetary Policies

Fluctuations in Exports and Imports

7 0
3 years ago
Read 2 more answers
Other questions:
  • 1. Create a class called Name that represents a person's name. The class should have fields named firstName representing the per
    8·2 answers
  • You are comparing distillation column designs at 1 atm and 3 atm total pressure for a particular separation. You have the same f
    5·1 answer
  • 1. What is an op-amp? List the characteristics of an ideal op-amp
    11·1 answer
  • What is the heights part of Maine?
    5·1 answer
  • Convection is a function of temperature to the fourth power. a)-True b)-False
    9·1 answer
  • A seawall with an opening is used to dampen the tidal influence in a coastal area (and limit erosion). The seawall is 2.5 m long
    11·1 answer
  • Nitrogen enters a steady-flow heat exchanger at 150 kPa, 10°C, and 100 m/s, and it receives heat as it flows through it. Nitroge
    15·1 answer
  • 2.31 LAB: Simple statistics Part 1 Given 4 integers, output their product and their average, using integer arithmetic. Ex: If th
    5·2 answers
  • Which option identifies the type of engineering technician most likely to be involved in the following scenario?
    9·1 answer
  • 1. Band saw lower wheel does not require a guard *
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!