StringThing.java
1    package stringthing;
2    
3    public class StringThing {
4        public static void main(String[] args) {
5    
6            // POINT A : CREATE A 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 = "Marin, Justice";
12           System.out.println("\nNames");
13           System.out.println("singer = " + singer);
14           System.out.println("sculptor = " + sculptor);
15           System.out.println("painter = " + painter);
16           System.out.println("dancer = " + dancer);
17           System.out.println("self = " + 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("singer length = " + singerLength);
27           System.out.println("sculptor length = " + sculptorLength);
28           System.out.println("painter length = " + painterLength);
29           System.out.println("dancer length = " + dancerLength);
30           System.out.println("self length = " + 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("\nSinger comma position = " + singerCommaPosition);
40           System.out.println("Sculptor comma position = " + sculptorCommaPosition);
41           System.out.println("Painter comma position = " + painterCommaPosition);
42           System.out.println("Dancer comma position = " + dancerCommaPosition);
43           System.out.println("Self comma position = " + selfCommaPosition);
44   
45           // POINT D : COMPUTE AND PRINT THE FIVE FIRST NAMES, WITH NO LABELS
46           String singerFirst = singer.substring(9);
47           String sculptorFirst = sculptor.substring(9);
48           String painterFirst = painter.substring(9);
49           String dancerFirst = dancer.substring(7);
50           String selfFirst = self.substring(7);
51           System.out.println("\nFirst names ...");
52           System.out.println("Singer first name is " + singerFirst);
53           System.out.println("Sculptor first name is " + sculptorFirst);
54           System.out.println("Painter first name is " + painterFirst);
55           System.out.println("Dancer first name is " + dancerFirst);
56           System.out.println("Self first name is " + selfFirst);
57   
58           // POINT E : COMPUTE AND PRINT THE FIVE LAST NAMES, WITH NO LABELS
59           String singerLast = singer.substring(0, 7);
60           String sculptorLast = sculptor.substring(0, 7);
61           String painterLast = painter.substring(0, 7);
62           String dancerLast = dancer.substring(0, 5);
63           String selfLast = self.substring(0, 5);
64           System.out.println("\nLast names ...");
65           System.out.println("Singer last name is " + singerLast);
66           System.out.println("Sculptor last name is " + sculptorLast);
67           System.out.println("Painter last name is " + painterLast);
68           System.out.println("Dancer last name is " + dancerLast);
69           System.out.println("Self last name is " + selfLast);
70   
71           // POINT F : COMPUTE AND PRINT THE FIRST NAME, AGAIN
72           System.out.println("\nFirst names, once again ...");
73           System.out.println(firstName(singer));
74           System.out.println(firstName(sculptor));
75           System.out.println(firstName(painter));
76           System.out.println(firstName(dancer));
77           System.out.println(firstName(self));
78   
79           // POINT G : COMPUTE AND PRINT THE LAST NAMES, AGAIN
80           System.out.println("\nLast names, once again ...");
81           System.out.println(lastName(singer));
82           System.out.println(lastName(sculptor));
83           System.out.println(lastName(painter));
84           System.out.println(lastName(dancer));
85           System.out.println(lastName(self));
86   
87           // POINT H : COMPUTE AND PRINT THE FULL NAMES, NATURAL STYLE
88           System.out.print("\nFull names, natural style ... ");
89           System.out.print(fullName(singer));
90           System.out.print(fullName(sculptor));
91           System.out.print(fullName(painter));
92           System.out.print(fullName(dancer));
93           System.out.print(fullName(self));
94   
95       }
96   
97       private static String fullName(String dsn) {
98           String fullName = dsn.substring(0);
99           String fullNameYes = fullName + " | ";
100          return fullNameYes;
101      }
102  
103      private static String firstName(String directoryStyleName) {
104          int firstComma = directoryStyleName.indexOf(",");
105          String firstName = directoryStyleName.substring(firstComma + 2);
106          return firstName;
107  
108      }
109  
110      private static String lastName(String directoryStyleName) {
111          int lastComma = directoryStyleName.indexOf(",");
112          String lastName = directoryStyleName.substring(0, lastComma);
113          return lastName;
114      }
115  }
116