Commit c432c8f9 authored by Vyshna-Sri's avatar Vyshna-Sri

Updated FractionValue code

parent 44b8fe51
...@@ -3,13 +3,16 @@ package com.elearning.probabilityandstatisticsanalyserandeducator.dataExtraction ...@@ -3,13 +3,16 @@ package com.elearning.probabilityandstatisticsanalyserandeducator.dataExtraction
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class FractionValue { public class FractionValue {
public FractionValue(){} public FractionValue(){}
public Double fractionToDouble(String question){ public List<Double> fractionToDouble(String question){
Double value = null; List<Double> value = new ArrayList<Double>();
question="4/52"; question="4/52";
if (question != null) { if (question != null) {
if (question.contains("/")) { if (question.contains("/")) {
...@@ -18,11 +21,11 @@ public class FractionValue { ...@@ -18,11 +21,11 @@ public class FractionValue {
BigDecimal d1 = BigDecimal.valueOf(Double.valueOf(numbers[0])); BigDecimal d1 = BigDecimal.valueOf(Double.valueOf(numbers[0]));
BigDecimal d2 = BigDecimal.valueOf(Double.valueOf(numbers[1])); BigDecimal d2 = BigDecimal.valueOf(Double.valueOf(numbers[1]));
BigDecimal response = d1.divide(d2, MathContext.DECIMAL128); BigDecimal response = d1.divide(d2, MathContext.DECIMAL128);
value = response.doubleValue(); value = Collections.singletonList(response.doubleValue());
} }
} }
else { else {
value = Double.valueOf(question); value = Collections.singletonList(Double.valueOf(question));
} }
} }
// if (value == null) { // if (value == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment