daniel_lawson9999

Daniel Lawson Chapter 10 Powerpoint Exercises

Mar 1st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. /**
  2.  * Created by danie on 3/1/2017
  3.  */
  4. //Daniel Lawson powerpoint exercise
  5. import java.util.*;
  6. public class Exercises {
  7.     public static void main(String[] args){
  8.         ArrayList<String> list = new ArrayList<>(Arrays.asList("foodS","more","tests","food","weird"));//make an array
  9.         System.out.println("Original: " + list.toString()); // print the first array
  10.         reverse(list); // call the reverse method
  11.         System.out.println("Reversed order: " +list.toString()); // print out the array after it is reversd
  12.         capitalizePlurals(list); // call the method for capitalizing the plurals
  13.         System.out.println("Capitalized plurals: " + list.toString()); // print the array after the plurals are capitalized
  14.         removePlurals(list); // call the method to remove all plurals
  15.         System.out.println("Removed Plurals: " + list.toString()); // print out the array after plurals are removed
  16.  
  17.  
  18.     }
  19.     public static void reverse(ArrayList<String> list){
  20.         for(int i = list.size()-1; i >0;i--){
  21.             String word = list.get(0); // store the first word in the array
  22.             list.remove(0); // remove it
  23.             list.add(i,word); // add it to the last place minus what number after the first one it is
  24.         }
  25.     }
  26.     public static void capitalizePlurals(ArrayList<String> list){
  27.         for(int i = 0; i<list.size();i++){
  28.             String s = list.get(i); // get a word
  29.             if(s.toLowerCase().endsWith("s")){ // if it ends with a s
  30.                 list.set(i,s.toUpperCase()); // set it to be uppercase
  31.             }
  32.         }
  33.     }
  34.     public static void removePlurals(ArrayList<String> list){
  35.         for(int i = 0; i<list.size(); i++){
  36.             if(list.get(i).toLowerCase().endsWith("s")){ // if a word ends with s
  37.                 list.remove(i); // remove  it
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment