Java Suppose that you are given a list of daily gains (incre
Java Suppose that you are given a list of daily gains (increases) in the price of a stock.The investment threshold is defined as the number of days that you must hold that stock before the accumulated gains reach a certain total.For example,if your goal is to earn $1,000,then your investment threshold for a given stock would equal the number of days you need to hold that stock before your accumulated profits reach $1,000.Example:Suppose that a stock sees the following gains over 6 days:5,3,8,2,9,1,and that your goal is to earn a profit of $17.The investment threshold would be 4,because it takes 4 days for the accumulated gains to reach 17 (5 + 3 + 8 + 2 = 18).(a) Write a Java method with the following header:public static int threshold (double [] gains,double goal)The first argument is an array of double values corresponding to the daily increases in a stock investment (i.e.,the profit you made over the previous day).The second argument is a double that represents your desired profit goal.The method returns an int representing the minimum number of days that you need in order to reach (or exceed) your profit goal.If the profit goal cannot be reached using the values in the list of increases,the method returns -1.General algorithm:Set earned to 0Set days to 0While earned < goal and you have not yet reached the end of the array:Add the next dayʼs increases to earnedAdd 1 to daysMove to the next element in the arrayDecide whether to return days or -1(b) Complete your program by writing a main() method that asks the user to enter a profit goal.Youmay define your own array of stock increase values.Your program should then calculate and print outthe investment threshold for that profit goal,or state that the goal cannot be reached.(c) Modify your program so that it works from a randomly-generated array of stock gains.
最佳回答
(year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
最新回答共有2条回答
-
2026-03-30 19:14:06粗心的牛排
回复(year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
热门文章
- 康达学院专转本五年制
- 高考一个考场分ab卷吗
- not only but also用法
- 某物体做自由落体运动,从释放开始计时,则物体在前2s内的平均速度为______m/s,物体下落2m时的速度大小为______m/s.
- 三角函数公式大全表格
- 地理中考必背知识点2022
- 2013-2014学年小学六年级科学上学期期末考试试卷及答案
- 人教版2014-2015学年小学五年级英语第二学期期中教学质量检测试卷及答案
- 【Linux驱动开发】设备树详解(二)设备树语法详解
- 别跟客户扯细节
- 在别的城市买房子能落户吗
- 卖房前要把装修贷还完吗
- 高中政治教学提高教学效果的方法探究
- “互联网+”背景下的初中英语课堂教学改革与创新策略研究
- 2022年终止合同范本
- 租房合同范本范文
- 如何挑选土豆
- 如何挑选土鸡
