diff --git a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java index fe3868570c..3536b6a633 100644 --- a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java +++ b/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java @@ -4,19 +4,17 @@ import java.util.Scanner; public class RoundUpToHundred { - public static void main(String[] args) { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + double input = scanner.nextDouble(); + scanner.close(); - Scanner scanner = new Scanner(System.in); - double input = scanner.nextDouble(); - scanner.close(); + RoundUpToHundred.round(input); + } - RoundUpToHundred.round(input); - } - - static int round(double input) { - - int i = (int) Math.round(input); - return ((i + 99) / 100) * 100; - }; + static int round(double input) { + int i = (int) Math.ceil(input); + return ((i + 99) / 100) * 100; + }; } diff --git a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java b/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java index 457e762e09..a13aa1f8cc 100644 --- a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java +++ b/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java @@ -2,17 +2,13 @@ package com.java.src; import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class RoundUpToHundredTest { - public void roundupTest() { - - assertEquals("Rounded up to hundred", 100, - RoundUpToHundred.round(99)); - - assertEquals("Rounded down to two hundred ", 200, - RoundUpToHundred.round(200.2)); - - assertEquals("Returns same rounded value", 300, - RoundUpToHundred.round(300)); - - } + @Test + public void givenInput_whenRoundedUp_thenTrue() { + assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); + assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); + assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); + } }