Question
Hello, I will make sure to thumbs up if you can help with my cs homework :) Would appreciate it dearly /* TSA1 */ import
Hello, I will make sure to thumbs up if you can help with my cs homework :) Would appreciate it dearly
/* TSA1 */ import java.util.Random; import java.util.Scanner; import java.util.Arrays; public class TSA1 { public static int[] prepareData(int[] prices){ /* Data is prepared by inserting random values up to 100. Data items may be repeated. Please refer to slides for the problem definiton. */ Random rand = new Random(); for (int i = 0; i
return span; }
public static void main(String[] args) { System.out.println("Enter the no of days:"); Scanner scan = new Scanner(System.in); int days = scan.nextInt(); int[] prices_initialized = new int[days]; int[] prices_populated = prepareData(prices_initialized);
// a set of days and their respective prices. /* does a random distribution of prices. */ /* Implement the computeSoan method, so as to get the correct results.*/ int[] span = computeSpan(prices_populated); /* The two lines below will print the output. Do not uncomment these lines. */ System.out.println("Prices:\t" + Arrays.toString(prices_populated)); System.out.println("Span:\t" + Arrays.toString(span)); } } ------
/* TSA2 */ import java.util.Random; import java.util.Scanner; import java.util.Arrays; public class TSA2 { public static int[] prepareData(int[] prices){ /* Data is prepared by inserting random values up to 100. Data items may be repeated. Please refer to slides for the problem definiton. */ Random rand = new Random(); for (int i = 0; i
return span; }
public static void main(String[] args) { System.out.println("Enter the no of days:"); Scanner scan = new Scanner(System.in); int days = scan.nextInt(); int[] prices_initialized = new int[days]; int[] prices_populated = prepareData(prices_initialized);
// a set of days and their respective prices. /* does a random distribution of prices. */ /* Implement the computeSoan method, so as to get the correct results.*/ int[] span = computeSpan(prices_populated); /* The two lines below will print the output. Do not uncomment these lines. */ System.out.println("Prices:\t" + Arrays.toString(prices_populated)); System.out.println("Span:\t" + Arrays.toString(span)); } }
More info:
computeScan and ADT examples from slides
Part 01 - A Time Series problem implementation (15 points) Implement the Time Scrics problem using a scries of requirements outlined below. 1. The problem definition is provided below: 2. The span Si of a stock's price on a certain day i is the maximum number of consecutive days (up to the current day) the price of the stock has been less than or equal to its price on day i. Let us suppose we are given with the stock prices for different days. Identify the span S for those days. Price vs. Day IL..Il Span[0,1,2,3,4,5,61 = {1,1,1,2,1,4,6} 3. Please refer to lesson 3 and 4 and your notes for more details from class discussion related to this problem. 4. In order to casily access the Time Series algorithm Version 1 is provided below: Algorithm - ComputeSpan P) Input: an n-element array P of numbers such that Pil is the price of the stock on a day i. of numbers such that S[i] is the span of the stock on a day i. Output: an n-element array 1: for i = 0 ton - 1 do 4 5: while h =P[D.top()) then D.pop() else done = true end if end while if Dis empty then h -1 15: else 16 h = D.top() 17: end if 18: S[iich 19. D.push(i) 20: end for 21: returns 10. The starter code file is provided inside the lab repository in a file named, TSA2. java. Here TSA refers to Time Series Algorithm. 11. Implement the computeSpan method using the approach 2 algorithm provided above by integrating the Stack ADT to the program. The details on how to implement the method are purposefully left out so as to challenge the students to think about the implementation on their own. 12. A sample code file named StackUsage.java is provided in the repository. The sample code may be used as a tool to learn how to use the built-in Stack ADT in Java. 13. For more details on the requirements for this program, please look at the comments in the source code file. 14. To validate the correctness of the output of the program, please pick an example from the slides and/or your notes and validate the correctness of the program. StackUsage.java 1 /* 2 Please refer to the link below for more examples: 3 https://www.geeksforgeeks.org/stack-class-in-java/ 4 */ import java.util.Arrays; import java.util.Scanner; import java.util.stack; public class stackusage { static void printstack(stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started