CS 120 Final Exam Review Answers

Problem 1 isn't really a problem — it prepares you to answer Problems 2 and 3

Problem 2

Problem 3

Problem 4

Problem 5

Problem 6

Problem 7:
See examples from Exam1, Exam2 and Exam3, as well as many examples in the material from class lectures and activities.  Be able to read program code and predict the output generated by the program.
Problem 8:
    80
    0
    20
    0
    2
    3
    7
    4
Problem 9:
  1.     public Boolean parameterIsAQuestion( String text ) {
    	
            Integer positionOfLastChar = text.length() - 1;
    	
            if ( text.charAt( positionOfLastChar ) == '?' ) {
                return true;
            }
    
            return false;
        }
    
  2. There are several different ways to solve this problem; one solution would be:
        public Boolean parameterContainsAnInternalSpace( String text ) {
    
            String middlePart = text.substring(1, text.length()-1 );
    	
            if ( middlePart.indexOf(" ") >= 0 ) {
                return true;
            }
    	
            return false;
        }
    
    You could also use the contains method in combination with the substring and/or charAt methods to solve this problem.
  3.     70
        p
        Apr
        many flowers this year!
        28
        53
        6