/home/evankemp/NetBeansProjects/CS1/src/stringthing/StringThing.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package stringthing;
  7 
  8 /**
  9  *
 10  * @author evankemp
 11  */
 12 public class StringThing {
 13 
 14     /**
 15      * @param args the command line arguments
 16      */
 17     public static void main(String[] args) {
 18         //POINT A: CREATE AND PRINT SOME STRINGS THAT REPRESENT NAMES
 19         String singer = "Holiday, Billie";
 20         String sculptor = "Claudel, Camille";
 21         String painter = "Picasso, Pablo";
 22         String dancer = "Zotto, Osvaldo";
 23         String self = "Van Kempen, Elina";
 24         System.out.println("\nNames ...");
 25         System.out.println(singer);
 26         System.out.println(sculptor);
 27         System.out.println(painter);
 28         System.out.println(dancer);
 29         System.out.println(self);
 30         
 31         
 32         //POINT B: COMPUTE AND PRINT THE LENTGHS OF THE STRINGS, WITHOUT LABELS
 33         int singerLength = singer.length();
 34         int sculptorLength = sculptor.length();
 35         int painterLength = painter.length();
 36         int dancerLength = dancer.length();
 37         int selfLength = self.length();
 38         System.out.println("\nName Lengths ...");
 39         System.out.println(singerLength);
 40         System.out.println(sculptorLength);
 41         System.out.println(painterLength);
 42         System.out.println(dancerLength);
 43         System.out.println(selfLength);
 44         
 45         //POINT C: COMPUTE AND PRINT THE LOCATION OF THE COMMA WITHIN EACH STRING, NO LABELS
 46         int singerCommaPosition = singer.indexOf(",");
 47         int sculptorCommaPosition = sculptor.indexOf(",");
 48         int painterCommaPosition = painter.indexOf(",");
 49         int dancerCommaPosition = dancer.indexOf(",");
 50         int selfCommaPosition = self.indexOf(",");
 51         System.out.println("\nComma positions ...");
 52         System.out.println(singerCommaPosition);
 53         System.out.println(sculptorCommaPosition);
 54         System.out.println(painterCommaPosition);
 55         System.out.println(dancerCommaPosition);
 56         System.out.println(selfCommaPosition);
 57 
 58         
 59         //POINT D: COMPUTE AND PRINT THE FIVE FIRST NAMES, WITH NO LABELS
 60         String singerFirst = singer.substring(singerCommaPosition + 2);
 61         String sculptorFirst = sculptor.substring(sculptorCommaPosition + 2);
 62         String painterFirst = painter.substring(painterCommaPosition + 2);
 63         String dancerFirst = dancer.substring(dancerCommaPosition + 2);
 64         String selfFirst = self.substring(selfCommaPosition + 2);
 65         System.out.println("\nFirst names ...");
 66         System.out.println(singerFirst);
 67         System.out.println(sculptorFirst);
 68         System.out.println(painterFirst);
 69         System.out.println(dancerFirst);
 70         System.out.println(selfFirst);
 71 
 72         //POINT E: COMPUTE AND PRINT THE FIVE LAST NAMES, WITH NO LABELS
 73         String singerLast = singer.substring(0,singerCommaPosition);
 74         String sculptorLast = sculptor.substring(0,sculptorCommaPosition);
 75         String painterLast = painter.substring(0,painterCommaPosition);
 76         String dancerLast = dancer.substring(0,dancerCommaPosition);
 77         String selfLast = self.substring(0,selfCommaPosition);
 78         System.out.println("\nLast names ...");
 79         System.out.println(singerLast);
 80         System.out.println(sculptorLast);
 81         System.out.println(painterLast);
 82         System.out.println(dancerLast);
 83         System.out.println(selfLast);
 84 
 85         
 86         //POINT F: COMPUTE AND PRINT THE FIRST NAMES, AGAIN
 87         System.out.println("\nFirst names, once again ...");
 88         System.out.println(firstName(singer));
 89         System.out.println(firstName(sculptor));
 90         System.out.println(firstName(painter));
 91         System.out.println(firstName(dancer));
 92         System.out.println(firstName(self));
 93         
 94         //POINT G: COMPUTE AND PRINT THE LAST NAMES, AGAIN
 95         System.out.println("\nLast names, once again ...");
 96         System.out.println(lastname(singer));
 97         System.out.println(lastname(sculptor));
 98         System.out.println(lastname(painter));
 99         System.out.println(lastname(dancer));
100         System.out.println(lastname(self));
101         
102         //POINT H: COMPUTE AND PRINT THE FULL NAMES, NATURAL STYLE
103         System.out.println("\nFull names, natural style ...");
104         System.out.println(fullName(singer));
105         System.out.println(fullName(sculptor));
106         System.out.println(fullName(painter));
107         System.out.println(fullName(dancer));
108         System.out.println(fullName(self));
109         
110     }
111 
112     private static String firstName(String directoryStyleName) {
113         String directoryStyleNameFirst = directoryStyleName.substring(directoryStyleName.indexOf(",")+2);
114         return directoryStyleNameFirst;
115     }
116 
117     private static String lastname(String directoryStyleName) {
118         String directoryStyleNameLast = directoryStyleName.substring(0,directoryStyleName.indexOf(","));
119         return directoryStyleNameLast;
120     }
121 
122     private static String fullName(String dsn) {
123         dsn = firstName(dsn) + " " + lastname(dsn);
124         return dsn;
125     }
126     
127 }
128