/home/jfernan6/NetBeansProjects/CSX/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 jfernan6
 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 A 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 = "Fernandez, Jeremy";
 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           // POINT B: COMPUTE AND PRINT THE LENGTHS OF THE STRINGS, WITHOUT LABELS
 32           int singerLength = singer.length();
 33           int sculptorLength = sculptor.length();
 34           int painterLength = painter.length();
 35           int dancerLength = dancer.length();
 36           int selfLength = self.length();
 37           System.out.println("\nName lengths ...");
 38           System.out.println(singerLength);
 39           System.out.println(sculptorLength);
 40           System.out.println(painterLength);
 41           System.out.println(dancerLength);
 42           System.out.println(selfLength);
 43          
 44           // POINT C: COMPUTE AND PRINT THE LOCATION OF THE COMMA WITHIN EACH STRING, NO LABELS
 45           int singerCommaPosition = singer.indexOf(",");
 46           int sculptorCommaPosition = sculptor.indexOf(",");
 47           int painterCommaPosition = painter.indexOf(",");
 48           int dancerCommaPosition = dancer.indexOf(",");
 49           int selfCommaPosition = self.indexOf(",");
 50           System.out.println("\nComma positions ...");
 51           System.out.println(singerCommaPosition);
 52           System.out.println(sculptorCommaPosition);
 53           System.out.println(painterCommaPosition);
 54           System.out.println(dancerCommaPosition);
 55           System.out.println(selfCommaPosition);
 56          
 57           // POINT D: COMPUTE AND PRINT THE FIVE FIRST NAMES, WITH NO LABELS
 58         String singerFirst = singer.substring(singerCommaPosition +2);
 59           String sculptorFirst = sculptor.substring(sculptorCommaPosition +2);
 60           String painterFirst = painter.substring( painterCommaPosition +2);
 61           String dancerFirst = dancer.substring( dancerCommaPosition +2);
 62           String selfFirst = self.substring(selfCommaPosition +2);
 63           System.out.println("\nFirst names ...");
 64           System.out.println(singerFirst);
 65           System.out.println(sculptorFirst);
 66           System.out.println(painterFirst);
 67           System.out.println(dancerFirst);
 68           System.out.println(selfFirst);
 69        
 70           // POINT E: COMPUTE AND PRINT THE FIVE LAST NAMES, WITH NO LABELS
 71            String singerLast = singer.substring(0, singerCommaPosition);
 72           String sculptorLast = sculptor.substring(0, sculptorCommaPosition);
 73           String painterLast = painter.substring(0, painterCommaPosition);
 74           String dancerLast = dancer.substring(0, dancerCommaPosition);
 75           String selfLast = self.substring(0, selfCommaPosition);
 76           System.out.println("\nLast names ...");
 77           System.out.println(singerLast);
 78           System.out.println(sculptorLast);
 79           System.out.println(painterLast);
 80           System.out.println(dancerLast);
 81           System.out.println(selfLast);
 82          
 83           // POINT F: COMPUTE AND PRINT THE FIRST NAMES, AGAIN
 84            System.out.println("\nFirst names, once again ...");
 85            System.out.println(firstName(singer));
 86            System.out.println(firstName(sculptor));
 87            System.out.println(firstName(painter));
 88            System.out.println(firstName(dancer));
 89            System.out.println(firstName(self));
 90    
 91           // POINT G: COMPUTE AND PRINT THE LAST NAMES, AGAIN
 92            System.out.println("\nLast names, once again ...");
 93            System.out.println(lastName(singer));
 94            System.out.println(lastName(sculptor));
 95            System.out.println(lastName(painter));
 96            System.out.println(lastName(dancer));
 97            System.out.println(lastName(self));
 98  
 99           // POINT H: COMPUTE AND PRINT THE FULL NAMES, NATURAL STYLE
100            System.out.println("\nFull names, natural style ...");
101            System.out.println(fullName(singer));
102           System.out.println(fullName(sculptor));
103           System.out.println(fullName(painter));
104           System.out.println(fullName(dancer));
105           System.out.println(fullName(self));
106  
107      }
108  
109      private static String firstName(String name) {
110          int CommaPosition = name.indexOf(",");
111          String First = name.substring(CommaPosition +2);
112          return First;
113      }
114  
115      private static String lastName(String name) {      
116          int CommaPosition = name.indexOf(",");
117          String Last = name.substring(0,CommaPosition);
118          return Last;
119      }
120  
121      private static String fullName(String name) {
122          String fullname = (firstName(name) + " " + lastName(name));
123         return fullname;
124      }
125  
126  }