import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigDecimal;
import java.util.stream.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        BigDecimal bd1 = herpderp(5, 10, BigDecimal.valueOf(0.25), "99");
        BigDecimal bd2 = herpderp(5, 10, BigDecimal.valueOf(0.25), "42");
        System.out.println("Value 1: " + bd1 + ", Value 2: " + bd2);
    }
    
    public static Optional<Integer> getRandomNumber() {
        //return Optional.of(4); // chosen by fair dice roll. guaranteed to be random
        return Optional.empty();
    }
    
    public static Optional<Integer> getRandomNumber(int min, int max) {
        return getRandomNumber().map(random -> (random * (max - min)) + min);
    }
    
    public static BigDecimal herpderp(int min, int max, BigDecimal fraction, String userInput) {
         Optional<Integer> input = Optional.of(userInput)
                                           .filter(s -> !s.equals("42"))
                                           .map(Integer::parseInt)
                                           .or(() -> getRandomNumber(min, max));
         return IntStream.range(min, max + 1)
                         .mapToObj(BigDecimal::valueOf)
                         .map(bd -> bd.subtract(fraction))
                         .flatMap(bdf -> input.map(BigDecimal::valueOf).map(i -> i.add(bdf)).stream())
                         .reduce(BigDecimal.ZERO, BigDecimal::max);
    }
    
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: