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

  Create method that prints a rectangle of characters console

Create a method that prints a rectangle of characters to the console. The method should use a character set that parameter to the method.

  Write a program that calculate the speed of sound

write a program that calculate the speed of sound (a) in air of a given temperature t (f) formula to compute the seed in ft/sec a=1086 \(\sqrt{5t+297/247}\) please i need to run this program in visual studio win32 please i need help thank you

  Centralized and distributed computing architectures

"Centralized and Distributed Computing Architectures" Please respond to the following:

  Part of your first project

On completion of this course you are hired by the company Tickets R Us. Part of your first project is to develop an application to assist with the selling of tickets. After discussing with your client

  What are the pro''s and con''s of digital rights managment

What are the pro's and con's of Digital Rights Managment

  Write java program that allows the user to enter wall space

Write a Java program (from scratch) that allows the user to enter the wall space to be painted and the price of paint per gallon.

  Write quickest and easiest way to recover data

What is the quickest and easiest way to solve most urgent problem, recovering data? Write the major steps in that process.

  Acilisis, lacinia, curabitur egestas

Acilisis, lacinia, curabitur egestas, lorem, risus. Class Ac amet laoreet parturient, quam justo interdum hendrerit erat faucibus, facilisi scelerisque commodo, odio. Ligula conubia potenti, per praesent est egestas felis a facilisis potenti vehicula..

  Hardware and system software qualify as infrastructure

What is infrastructure? In what was do hardware and system software qualify as infrastructure? What basic strategic planning questions should be addressed with respect to infrastructure?

  Point out which following functions exist and which cannot

Point out which of the following functions can exist and which cannot. Provide either reasons for functions that cannot exist, or examples for functions that can exist a. A bijection from Ø to 2^Ø b. A bijection from ? to ?

  A one-variable quadratic expression

A one-variable quadratic expression is an arithmetic expression of the form ax^2+bx+c, where a,b, and cc are some fixed numbers (called the coefficients) and x is a variable that can take on different vaues

  Write a complete program in a class named showdesign

Write a complete program in a class named ShowDesign that uses the DrawingPanel The window is 200 pixels wide and 200 pixels tall. The background is white and the foreground is black.

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