Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30ab5c8

Browse files
Kyu 8 | Abbreiate a Two Word Name
1 parent bd46ce6 commit 30ab5c8

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

‎src/main/java/kyu8/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Kata Found realized
1818

1919
- [A wolf in sheep's clothing](aWolfInSheepClothing)
2020

21+
- [Abbreviate a Two Word Name](abbreviateATwoWordName)
22+
-
2123
- [Find Nearest square number](findNearestSquareNumber)
2224

2325

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kyu8.abbreviateATwoWordName;
2+
3+
public class AbbreviateTwoWords {
4+
public static String abbrevName(String name) {
5+
name = name.toUpperCase();
6+
return name.charAt(0) + "." + name.charAt(name.indexOf(" ") + 1);
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Abbreviate a Two Word Name
2+
3+
Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.
4+
5+
The output should be two capital letters with a dot separating them.
6+
7+
It should look like this:
8+
9+
```Sam Harris``` => ```S.H```
10+
11+
```Patrick Feeney``` => ```P.F```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package kyu8.abbreviateATwoWordName;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testAbbreviateTwoWords {
8+
@Test
9+
public void testFixed() {
10+
assertEquals("S.H", AbbreviateTwoWords.abbrevName("Sam Harris"));
11+
assertEquals("P.F", AbbreviateTwoWords.abbrevName("Patrick Feenan"));
12+
assertEquals("E.C", AbbreviateTwoWords.abbrevName("Evan Cole"));
13+
assertEquals("P.F", AbbreviateTwoWords.abbrevName("P Favuzzi"));
14+
assertEquals("D.M", AbbreviateTwoWords.abbrevName("David Mendieta"));
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /