Skip to content

Commit ab8640c

Browse files
Add files via upload
1 parent a8a687a commit ab8640c

5 files changed

Lines changed: 141 additions & 0 deletions

File tree

Project/Code Running.PNG

80.5 KB
Loading

Project/Project Skeleton.PNG

81.4 KB
Loading

Project/Source Code.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package devops;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
public class FizzBuzz {
7+
8+
String[] units = { "", "One", "Two", "Three", "Four",
9+
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
10+
"Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
11+
"Eighteen", "Nineteen" };
12+
13+
String[] tens = {
14+
"", // 0
15+
"", // 1
16+
"Twenty", // 2
17+
"Thirty", // 3
18+
"Forty", // 4
19+
"Fifty", // 5
20+
"Sixty", // 6
21+
"Seventy", // 7
22+
"Eighty", // 8
23+
"Ninety" // 9
24+
};
25+
26+
public String convert(int n) {
27+
28+
29+
if (n < 20) {
30+
return units[n];
31+
}
32+
33+
else if (n < 100) {
34+
return (tens[n / 10] + ((n % 10 != 0) ? " " : "") + units[n % 10]);
35+
}
36+
37+
38+
else{
39+
40+
return units[n / 100] + " Hundred" + ((n % 100 != 0) ? " " : "") + convert(n % 100);
41+
}
42+
43+
44+
}
45+
46+
public static void main(String[] args) throws IOException {
47+
48+
FizzBuzz numberWords=new FizzBuzz() ;
49+
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
50+
51+
while( true ) {
52+
System.out.print( "Enter number (0 to exit): " ) ;
53+
String value = reader.readLine() ;
54+
int number = Integer.parseInt( value ) ;
55+
if(number == 0) {
56+
System.out.println("Bye");
57+
return;
58+
}
59+
else if(number<0 || number>=1000)
60+
{
61+
System.out.println("Invalid number");
62+
return;
63+
}
64+
else{
65+
String result = numberWords.convert(number);
66+
System.out.println(result);
67+
}
68+
}
69+
}
70+
}

Project/Test File.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package devops;
2+
3+
import devops.FizzBuzz;
4+
import org.junit.*;
5+
6+
public class FizzBuzzTests {
7+
private FizzBuzz fizzBuzz ;
8+
9+
@Before
10+
public void setup() {
11+
fizzBuzz = new FizzBuzz() ;
12+
}
13+
14+
@Test
15+
16+
public void numberOutOfRangeReturnsError() {
17+
18+
//Assert.assertEquals( "Error", "Number out of range", fizzBuzz.convert( -1 ) ) ;
19+
20+
}
21+
22+
23+
@Test
24+
25+
public void test1() {
26+
27+
int input = 1;
28+
29+
String output = fizzBuzz.convert(input);
30+
31+
Assert.assertEquals("One", output);
32+
33+
}
34+
35+
36+
@Test
37+
38+
public void test20() {
39+
40+
int input = 20;
41+
42+
String output = fizzBuzz.convert(input);
43+
44+
Assert.assertEquals("Twenty", output);
45+
46+
}
47+
48+
49+
@Test
50+
51+
public void test99() {
52+
53+
int input = 99;
54+
55+
String output = fizzBuzz.convert(input);
56+
57+
Assert.assertEquals("Ninety Nine", output);
58+
59+
}
60+
61+
@Test
62+
63+
public void test256() {
64+
int input = 256;
65+
String output = fizzBuzz.convert(input);
66+
Assert.assertEquals("Two Hundred Fifty Six", output);
67+
}
68+
69+
70+
71+
}

Project/UnitTestCases.PNG

78.8 KB
Loading

0 commit comments

Comments
 (0)