Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java Program that calculates the maximum profit: Hint:~ Answer should be

ID: 3823160 • Letter: W

Question

Write a Java Program that calculates the maximum profit:

Hint:~ Answer should be 183.86, You can use this Code from here https://pastebin.com/k0qMqPRw
but Modify it so it displays the Max Profit bc in its current state it outputs/prints the maximum loss. We need to find out the Maximum Profit

CSV File Link - https://www.dropbox.com/s/tpyvapym5t8xx80/Data.csv?dl=0

Please paste the code below as the answer to the problem with a screenshot of the output to prove it worked..

Problem The stock market generates a massive amount of data each day, so much so that computerized methods are required to manage the volume. You are asked to write a program that uses real data to evaluate a stock. Requirements Write a Java program that will read and analyze the provided real stock price data and determine the maximum profit possible based on buying at a low price and selling at a high price. The program will read data from a file called "Data csv" to retrieve the date and value per share (adicose). The only columns of interest in this comma separated value file are the first and the last columns: the "Date" column and the "Adi Close" column respectively We can find the profit per share by searching through the closing share values and finding the largest positive difference between a pair of values. Obviously, the shares must be bought before they can be sold. The profit realized between any two days is computed as the difference between the later share value and the earlier share value. You will note that the file is arranged by date starting with the latest values and going back in time. output You are required to output only the buy and sell dates and the profit per share that could have been realized for making the best possible trade.

Explanation / Answer

public class MaximumProductSubarray {

public static void main(String args[])

{

int[] arr={30,2,0,5,6,1,-1};

System.out.print(maxProductSubarray(arr,arr.length));

}//main

public static int maxProductSubarray(int[] arr,int n)

{

int frontProduct = 1;

int backProduct = 1;

int maxProduct = 0;

for (int i = 0; i < n; i++) {

frontProduct *= arr[i];

backProduct *= arr[n - i - 1];

maxProduct = max(maxProduct,max(frontProduct,backProduct));

frontProduct = frontProduct == 0 ? 1 : frontProduct;

backProduct = backProduct == 0 ? 1 : backProduct;

}

return maxProduct;

}

static int max(int a, int b)

{ return a>b ? a : b; }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote