[go: up one dir, main page]

0% found this document useful (0 votes)
13 views5 pages

Math 1281 Unit 4

Statistical Inference unit 4

Uploaded by

sarahhauya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Math 1281 Unit 4

Statistical Inference unit 4

Uploaded by

sarahhauya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

University of the People

Sarah Hauya

Math 1281-01: Statistical Inference

Unit 4 Math Assignment

Due by 12th December, 2024

Ubaid Ahmed, Instructor


Calculating the average stock price:

To calculate the average stock price, you can sum up all the stock prices in the array and then divide the
sum by the number of elements in the array.

Here's an example implementation of the calculateAveragePrice method:

public static float calculateAveragePrice(float[] prices) {

float sum = 0;

for (float price : prices) {

sum += price;

return sum / prices.length;

Finding the maximum stock price:

In order to come up with the maximum stock price, we need to iterate through the array and keep track
of the maximum price encountered in the first place as follows;

public static float findMaximumPrice(float[] prices) {

float maxPrice = prices[0];

for (float price : prices) {

if (price > maxPrice) {

maxPrice = price;

return maxPrice;
}

Determining the occurrence count of a specific price:

To determine the occurrence count of a specific price, you can iterate through the array and count the
number of times the target price appears as follows;

public static int countOccurrences(float[] prices, float targetPrice) {

int count = 0;

for (float price : prices) {

if (price == targetPrice) {

count++;

return count;

Compute the cumulative sum of stock prices:

In order to come up with the computations for the cumulative sum of stock prices, we need to iterate
through the ArrayList and keep adding each price to a running sum. Then, add the running sum to a new
ArrayList at each position as follows;

import java.util.ArrayList;

public static ArrayList<Float> computeCumulativeSum(ArrayList<Float> prices) {

ArrayList<Float> cumulativeSum = new ArrayList<>();

float sum = 0;Compute the cumulative sum of stock prices:


Furthermore, to compute the cumulative sum of stock prices, you can iterate through the ArrayList and
keep adding each price to a running sum. The next step is to add the running sum to a new ArrayList at
each position as follows;

import java.util.ArrayList;

public static ArrayList<Float> computeCumulativeSum(ArrayList<Float> prices) {

ArrayList<Float> cumulativeSum = new ArrayList<>();

float sum = 0;

for (float price : prices) {

sum += price;

cumulativeSum.add(sum);

return cumulativeSum;

Conclusion

To conclude, above are explanations and programming answers in regards to the question asked in this
week's Programming Assignment for unit 4.

You might also like