package lab3out; import java.util.StringTokenizer; import java.lang.*; public class Sentence { private String[] array; private int num_words; public Sentence() { num_words = 0; } public Sentence(String sentence) { StringTokenizer st = new StringTokenizer(sentence, " "); int i = 0; array = new String[st.countTokens()]; num_words = st.countTokens(); while(st.hasMoreTokens()) { array[i] = st.nextToken(); i++; } } public int getWordCount() { return (num_words); } public String getWordAt(int position) { return (array[position - 1]); } public String sentence() { String sentence; StringBuffer sent = new StringBuffer (array[0]); char temp = array[0].charAt(0); int i = 0; if((sent.charAt(0) > 96) && (sent.charAt(0) < 123)) { temp -= 32; sent.setCharAt(0, temp); } sentence = new String(sent); for(i = 1; i < num_words; i++) { sentence = sentence.concat(" " + array[i]); } sentence = sentence.concat("."); return (sentence); } public String heading() { String sentence = new String(); StringBuffer sent; char temp; int i = 0; for(i = 0; i < num_words; i++) { if((i > 0) && (i < (num_words))) { sentence = sentence.concat(" "); } sent = new StringBuffer(array[i]); if((sent.charAt(0) > 96) && (sent.charAt(0) < 123)) { temp = array[i].charAt(0); temp -= 32; sent.setCharAt(0, temp); } sentence = sentence.concat(sent.toString()); } return(sentence); } public static void main(String[] args) { Sentence sentence = new Sentence(); } }