Added Math.ceil method to round up.
This commit is contained in:
parent
21ed59cb25
commit
6391285dd2
|
@ -5,7 +5,6 @@ import java.util.Scanner;
|
||||||
public class RoundUpToHundred {
|
public class RoundUpToHundred {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
double input = scanner.nextDouble();
|
double input = scanner.nextDouble();
|
||||||
scanner.close();
|
scanner.close();
|
||||||
|
@ -14,8 +13,7 @@ public class RoundUpToHundred {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int round(double input) {
|
static int round(double input) {
|
||||||
|
int i = (int) Math.ceil(input);
|
||||||
int i = (int) Math.round(input);
|
|
||||||
return ((i + 99) / 100) * 100;
|
return ((i + 99) / 100) * 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,13 @@ package com.java.src;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class RoundUpToHundredTest {
|
public class RoundUpToHundredTest {
|
||||||
public void roundupTest() {
|
@Test
|
||||||
|
public void givenInput_whenRoundedUp_thenTrue() {
|
||||||
assertEquals("Rounded up to hundred", 100,
|
assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99));
|
||||||
RoundUpToHundred.round(99));
|
assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2));
|
||||||
|
assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400));
|
||||||
assertEquals("Rounded down to two hundred ", 200,
|
|
||||||
RoundUpToHundred.round(200.2));
|
|
||||||
|
|
||||||
assertEquals("Returns same rounded value", 300,
|
|
||||||
RoundUpToHundred.round(300));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue