StringThing.java
1    package stringthing;
2    
3    public class StringThing {
4    
5        public static void main(String[] args) {
6            //POINT A: CREATE AND PRINT SOME STRINGS THAT REPRESENT NAMES
7            String singer = "Holiday, Billie";
8            String sculptor = "Claudel, Camille";
9            String painter = "Picasso, Pablo";
10           String dancer = "Zotto, Osvaldo";
11           String self = "Wingard, Ezra";
12           System.out.println("\nNames ...");
13           System.out.println(singer);
14           System.out.println(sculptor);
15           System.out.println(painter);
16           System.out.println(dancer);
17           System.out.println(self);
18   
19           //POINT B: COMPUTE AND PRINT THE LENGTHS OF THE STRINGS, WITHOUT LABELS
20           int singerLength = singer.length();
21           int sculptorLength = sculptor.length();
22           int painterLength = painter.length();
23           int dancerLength = dancer.length();
24           int selfLength = self.length();
25           System.out.println("\nName lengths ...");
26           System.out.println(singerLength);
27           System.out.println(sculptorLength);
28           System.out.println(painterLength);
29           System.out.println(dancerLength);
30           System.out.println(selfLength);
31   
32           //POINT C: COMPUTE AND PRINT THE LOCATION OF THE COMMA WITHIN EACH STRING, NO LABELS
33           int singerCommaPosition = singer.indexOf(",");
34           int sculptorCommaPosition = sculptor.indexOf(",");
35           int painterCommaPosition = painter.indexOf(",");
36           int dancerCommaPosition = dancer.indexOf(",");
37           int selfCommaPosition = self.indexOf(",");
38           System.out.println("\nComma positions ...");
39           System.out.println(singerCommaPosition);
40           System.out.println(sculptorCommaPosition);
41           System.out.println(painterCommaPosition);
42           System.out.println(dancerCommaPosition);
43           System.out.println(selfCommaPosition);
44   
45           // POINT D: COMPUTE AND PRINT THE FIVE FIRST NAMES, WITH NO LABELS
46           String singerFirst = singer.substring(9, 15);
47           String sculptorFirst = sculptor.substring(9, 16);
48           String painterFirst = painter.substring(9, 14);
49           String dancerFirst = dancer.substring(7, 14);
50           String selfFirst = self.substring(9, 13);
51           System.out.println("\nFirstNames ...");
52           System.out.println(singerFirst);
53           System.out.println(sculptorFirst);
54           System.out.println(painterFirst);
55           System.out.println(dancerFirst);
56           System.out.println(selfFirst);
57           //POINT E: COMPUTE AND PRINT THE FIVE LAST NAMES, WITH NO LABELS
58           String singerLast = singer.substring(0,6);
59           String sculptorLast = sculptor.substring(0,6);
60           String painterLast = painter.substring(0,6);
61           String dancerLast = dancer.substring(0,4);
62           String selfLast = self.substring(0,6);
63           System.out.println("\nLast names ...");
64           System.out.println(singerLast);
65           System.out.println(sculptorLast);
66           System.out.println(painterLast);
67           System.out.println(dancerLast);
68           System.out.println(selfLast);
69   
70           //POINT F: COMPUTE AND PRINT THE FIVE FIRST NAMES, AGAIN
71           System.out.println("\nFirst names, once again... ");
72           System.out.println(firstName(singer));
73           System.out.println(firstName(sculptor));
74           System.out.println(firstName(painter));
75           System.out.println(firstName(dancer));
76           System.out.println(firstName(self));
77   
78           //POINT G: COMPUTE AND PRINT THE LAST NAMES, AGAIN
79           System.out.println("\nLast names, once again... ");
80           System.out.println(lastName(singer));
81           System.out.println(lastName(sculptor));
82           System.out.println(lastName(painter));
83           System.out.println(lastName(dancer));
84           System.out.println(lastName(self));
85   
86           //POINT H: COMPUTE AND PRINT THE FULL NAMES, NATURAL STYLE
87           System.out.println("\nFull names, natural style ...");
88           System.out.println(fullName(singer));
89           System.out.println(fullName(sculptor));
90           System.out.println(fullName(painter));
91           System.out.println(fullName(dancer));
92           System.out.println(fullName(self));
93       }
94   
95       private static String firstName(String directoryStyleName) {
96           int index = directoryStyleName.indexOf(",");
97           String first =directoryStyleName.substring(index + 1, directoryStyleName.length());
98           return first;
99       }
100      private static String lastName(String directoryStyleName) {
101          int index = directoryStyleName.indexOf(",");
102          String second = directoryStyleName.substring(0, index);
103          return second;
104      }
105      private static String fullName(String directoryStyleName) {
106          int index = directoryStyleName.indexOf(",");
107          String third = firstName(directoryStyleName) + " " + lastName(directoryStyleName);
108          return third;
109      }
110  
111  }
112  
113