title: Fractional Knapsack java implementation
body: <p>So I get the whole idea of the fractional knapsack problem, which is to optimally fill your container with fractional amounts of the given items that you have. </p>
  
  <p>However, I'm confused to how I can implement this algorithm into a java function? I need to solve it for my Coursera course. So if anyone can explain how to write this function I would really appreciate it. This is the question prompt:</p>
  
  <blockquote>
    <p>Task. The goal of this code problem is to implement an algorithm for the > fractional knapsack problem.
    Input Format. The first line of the input contains the number n of items > and the capacity W of a knapsack.
    The next n lines define the values and weights of the items. The i-th > line contain integers vi and wi —
    the value and the weight of i-th item, respectively.
    Constraints. 1 ≤ n ≤ 103</p>
  </blockquote>
  
  <p>This is what I have so far (this includes starter code from which the course provided to me) </p>
  
  <p>`</p>
  
  <pre><code>public class FractionalKnapsack {
    private static double getOptimalValue(int capacity, int[] values, int[] weights) {
          //filling array vallues with 0
          Arrays.fill(values,0);
          //total value is 0
          double value = 0;
  
          for(int i=0; i&lt;values.length; i++){
              if(W==0){
                  return 
              }
          }
          //write your code here
          //fit first the item with the maximal value per unit
  
          //while knapsack is not full
          //choose item with maxmimum v/wi
          //if item fits into knapsack, take all of it
          //else take so much to fill knapsack to end
          //return total value and amounts taken
  
          return value;
      }
  
      public static void main(String args[]) {
          Scanner scanner = new Scanner(System.in);
          int n = scanner.nextInt();
          int capacity = scanner.nextInt();
          int[] values = new int[n];
          int[] weights = new int[n];
          for (int i = 0; i &lt; n; i++) {
              values[i] = scanner.nextInt();
              weights[i] = scanner.nextInt();
          }`   
  </code></pre>