You are on page 1of 2

/******************************************************************************

Welcome to GDB Online.


GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP,
Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS,
SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/

// Problem Statement:
// From the Given stocks and their daily volume, do the following:
// Level 1: Add the given stocks to the given Data Structure "stockVolume"
// Level 2: Solve the bug to get the percentage daily volume difference for each
given stock
// Level 3: Write the code to get the most traded stock among the given stocks

import java.util.*;

public class Main


{
private static Map<String,List<Integer>> stockVolume = new
HashMap<String,List<Integer>>();

// Level 1
static void addStock(String stock, int dailyVol[])
{
// Write the logic here...

// Level 2
static List<Double> dailyVolumeDifference(String code)
{
// Fix the bug here..

List<Double> perDifference = new ArrayList<Double>();

List<Integer> l = ((List<Integer>)stockVolume.get(code));

double prev = 0;

double curr = 0;

for(int i = 0; i < l.size()-1; i++)


{
prev = l.get(i);
curr = l.get(i+1);

double difference = ((curr - prev)/(prev))*100;

perDifference.add(difference);
}

return perDifference;
}
// Level 3
static String mostTradedStock()
{
String code="";

// Write the logic here...


for(int )

return code;
}

public static void displayDifference(String stock)


{
if(stockVolume.size()==0) return;

List<Double> volDifference = dailyVolumeDifference(stock);


System.out.println("Difference in volume for " +
stock);

for(double d : volDifference)
{
Formatter f = new Formatter();
f.format("%5.2f",d);
System.out.print(f + "% ");
}
System.out.println("\n");
}

public static void main(String[] args)


{
// We are adding the last 5 days traded volumes for each
stock...

addStock("ONGC",new int[]{125504,227808,418706,518706,618706});
addStock("ICICI",new int[]
{642675,505563,655457,555457,645457});
addStock("TCS",new int[]{314534,416543,213766,313766,237667});
addStock("HDFC",new int[]{161907,262122,359839,459839,379839});

System.out.println("Displaying the difference in


daily volume for each stock...\n");
displayDifference("ONGC");
displayDifference("TCS");
displayDifference("HDFC");
displayDifference("ICICI");

System.out.println("\nMost traded stock : " +


mostTradedStock());
}
}

You might also like