Java Suppose that you are given a list of daily gains (incre
来源:学生作业帮 编辑:大师作文网作业帮 分类:英语作业 时间:2024/11/12 07:23:36
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 0
Set days to 0
While earned < goal and you have not yet reached the end of the array:
Add the next dayʼs increases to earned
Add 1 to days
Move to the next element in the array
Decide whether to return days or -1
(b) Complete your program by writing a main() method that asks the user to enter a profit goal.You
may define your own array of stock increase values.Your program should then calculate and print out
the 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.
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 0
Set days to 0
While earned < goal and you have not yet reached the end of the array:
Add the next dayʼs increases to earned
Add 1 to days
Move to the next element in the array
Decide whether to return days or -1
(b) Complete your program by writing a main() method that asks the user to enter a profit goal.You
may define your own array of stock increase values.Your program should then calculate and print out
the 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)
Java Suppose that you are given a list of daily gains (incre
英翻中翻译器Suppose that you (Albert Meyer) are a supervisor of Ke
口语suppose that you were given one billion of RMB ,what would
Please _ a list of things that you are going to buy.(A.make
英语作文建议Suppose you will be given a monthly allowance of 100 y
Suppose you are a designer of a future robot,What kind of ro
写一篇英文商务信Suppose you are the manager of a supermarket,and you
求英语作文.要求;suppose you are running a cram school that aims at
英语翻译要求;suppose you are running a cram school that aims at he
1个面试的问题```急《Suppose you are a supervisor of a big company》
写作:suppose you are on holiday in a place of interest.write a
英语翻译Dear Zhulan,You may,I suppose did perceive,that one of a