File tree Expand file tree Collapse file tree
algorithms/roundUpToHundred/src/com/java/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55public class RoundUpToHundred {
66
7- public static void main (String [] args ) {
8-
9- Scanner scanner = new Scanner (System .in );
10- double input = scanner .nextDouble ();
11- scanner .close ();
12-
13- RoundUpToHundred .round (input );
14- }
15-
16- static int round (double input ) {
17-
18- int i = (int ) Math .round (input );
19- return ((i + 99 ) / 100 ) * 100 ;
20- };
7+ public static void main (String [] args ) {
8+ Scanner scanner = new Scanner (System .in );
9+ double input = scanner .nextDouble ();
10+ scanner .close ();
11+
12+ RoundUpToHundred .round (input );
13+ }
14+
15+ static int round (double input ) {
16+ int i = (int ) Math .ceil (input );
17+ return ((i + 99 ) / 100 ) * 100 ;
18+ };
2119
2220}
Original file line number Diff line number Diff line change 22
33import static org .junit .Assert .assertEquals ;
44
5- public class RoundUpToHundredTest {
6- public void roundupTest () {
7-
8- assertEquals ("Rounded up to hundred" , 100 ,
9- RoundUpToHundred .round (99 ));
10-
11- assertEquals ("Rounded down to two hundred " , 200 ,
12- RoundUpToHundred .round (200.2 ));
5+ import org .junit .Test ;
136
14- assertEquals ("Returns same rounded value" , 300 ,
15- RoundUpToHundred .round (300 ));
16-
17- }
7+ public class RoundUpToHundredTest {
8+ @ Test
9+ public void givenInput_whenRoundedUp_thenTrue () {
10+ assertEquals ("Rounded up to hundred" , 100 , RoundUpToHundred .round (99 ));
11+ assertEquals ("Rounded up to three hundred " , 300 , RoundUpToHundred .round (200.2 ));
12+ assertEquals ("Returns same rounded value" , 400 , RoundUpToHundred .round (400 ));
13+ }
1814}
You can’t perform that action at this time.
0 commit comments