Write a method priceisright

Assignment Help Basic Computer Science
Reference no: EM13306573

Write a method priceIsRight that accepts an array of integers bids and an integerprice as parameters. The method returns the element in the bids array that is closest in value to price without being larger than price. For example, if bids stores the elements {200, 300, 250, 999, 40}, then priceIsRight(bids, 280) should return 250, since 250 is the bid closest to 280 without going over 280. If all bids are larger than price, then your method should return -1.

The following table shows some calls to your method and their expected results:

Arrays Returned Value
int[] a1 = {900, 885, 989, 1}; priceIsRight(a1, 800) returns 1
int[] a2 = {200}; priceIsRight(a2, 120) returns -1
int[] a3 = {500, 300, 241, 99, 501}; priceIsRight(a3, 50) returns -1

You may assume there is at least 1 element in the array, and you may assume that the price and the values in bids will all be greater than or equal to 1. Do not modify the contents of the array passed to your method as a parameter.

 

Reference no: EM13306573

Questions Cloud

Find the position of the first dark band : Light of wavelength 600 nm falls on a 0.49 mm wide slit and forms a diffraction pattern on a screen 1.0 m away. Find the position of the first dark band on each side of the central maximum
Show that curve lies lies on intersection of the cylinders : show that the curve lies lies on the intersection of the cylinders y=[2(z+1)^2]/9 and x=[(z+1)^4]/81
Write a method named longestsortedsequence : Write a method named longestSortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array.
Calculate the thickness of the oil slick : A transparent oil with index of refraction 1.22 spills on the surface of water (index of refraction 1.33), determine the thickness of the oil slick
Write a method priceisright : You may assume there is at least 1 element in the array, and you may assume that the price and the values in bids will all be greater than or equal to 1. Do not modify the contents of the array passed to your method as a parameter.
Calculate the increase in its internal energy : A 2.00-mol sample of hydrogen gas is heated at constant pressure from 302 K to 414 K. Calculate the increase in its internal energy
What is the weight of the heaviest bear : The density of ice is 917 kg/m3, and the density of sea water is 1025 kg/m3. What is the weight of the heaviest bear that the ice can support without sinking completely beneath the water
What is the total cost for replacement : If you cannot find a good match for your current system, what might have to be purchased (processor, memory, etc.)? What is the total cost for replacement?
What needs to be done to avoid such problem : Based on our class discussion regarding E-R Diagrams, if an attribute is appearing in a number of entity sets does this situation lead to the issue of data redundancy? If yes, what needs to be done to avoid such problem?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Evaluation process to seven-step acquisition model

Discuss in scholarly detail the acquisition evaluation process to the Seven-Step Acquisition Model.

  Explain how the web user interfaces help donors

Explain how the Web user interfaces help donors to make decisions and relate the emotional thread demonstrated in the case study to the emotional design model as discussed in Chapter 5 of the textbook.

  Give the java statement needed

How do you specify that the color orange will be used as fill when using the Graphics class? Give the Java statement needed.

  Four ring architecture of operating systems

Opinion regarding what security benefit(s) would be seen if modern operating systems followed four ring architecture.

  Write a multithreaded program

Make sure it is able to compile a program prog.c with pthread, do "gcc -lpthread -o prog prog.c" Need the: a) The code b) Screenshot of the terminal showing your program running with at least 8 (different) numbers as run-time input.

  The heating element of a water heater in an apartment

The heating element of a water heater in an apartment building has a maximum power output of 28 kW. Four residents of the building

  What will be average access time when both read and write

What will be the average access time when both read and write are taken into consideration with write through strategy

  What is the numeric value of the string

What is the numeric value of the string for the following values of y? Note that the value of k is implied; e.g.for case i, k=3, etc. i: 101 ii: 10101 iii: 000111

  Write a program to manage a dictionary

Then ask whether the user wants to add this new word to the dictionary. If the answer is yes, do so and go back to request the next word.

  Display the new balances for both savers

Then set the annual InterestRate to 5%, calculate the next month's interest and display the new balances for both savers.

  Create 4 order class fields

Create 4 Order class fields: order number, customer name, quantity ordered, and total price. Create public accessors for each field except total price.

  Which machine has better performance

Which machine has better performance? By how much? Justify your answers. Instruction Class Cycles needed Instruction Frequency

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd