CS231 (Sp03) Review Topics for Exam 2


  1. primitive types
    1. int
    2. boolean
    3. double
    4. char
  2. operators and expressions
    1. /*-+% || && !
    2. Expressions have a value and a type
    3. messages whose methods are non-void are expressions
    4. What are the types and values of the following expressions? In case the expression is illegal, explain why.
      1. 17
      2. 1+2
      3. 1/2
      4. 1.0/2
      5. 1+2.0
      6. 1+2*3/4
      7. (1+2*3/4)%5
      8. ((1+2)*3)/(4%5)
      9. (1+2)*(3/4)%5
      10. true
      11. 1 < 2
      12. !(1 < 2)
      13. '!'
      14. "!"
      15. "ho"
      16. "ho" + "me"
      17. "ho" + "me" + "run"
      18. "ho" + "me" + "run" + '!'
  3. conversion between types
    1. int to String -- String s = "" + 17;
    2. int to char -- char ch = (char) 123;
    3. char to int -- int i = (int) 'a';
    4. String to int -- int i = Integer.parseInt("1234");
    5. double to int -- int i = (int) 1.234;
    6. int to double -- double d = 17; // !
  4. parameters
    1. formal -- void foo (int x, int y)
    2. actual -- someObject.foo(17,123);
    3. linkage - when a message is sent, before the method body is executed, the value of each actual parameter is copied to the corresponding formal parameter (in the example above 17 would be assigned to x, and 123, to y.
  5. classes
    1. constructors
    2. accessors
    3. toString
  6. Arrays
    1. declaring
    2. initializing
    3. using
  7. syntax
  8. Java statements
    1. assignment
    2. message
    3. block
    4. if
    5. for
    6. while
    7. switch
    8. return
  9. Problem solving techniques
    1. count
    2. understand the problem
    3. stepwise refinement (top-down design)
    4. remove a constraint
    5. add a constraint
    6. adopt a different perspective
    7. ABC - analysis by cases
    8. solve a simpler (but similar) problem
    9. solve a smaler (but similar) problem
  10. Graphics
    1. Color class
    2. RGB colors

Review exercises for CS231

These start off very easy and get pretty difficult. Work at the level that is right for you. This is an important part of learning to program; or learning any difficult skill -- you must be aware of what you understand and what you don't. You must realize consciously when you are confused and then do the (sometimes) difficult work of determining by what are you confused -- the good news is that by focussing on identifying the confusing aspects of the problem (or the confused parts of your thinking), you will have useful work to do and so will experience less pain and frustration.
  1. Simple use of Symantec Form designer -- Button, TextField and TextArea
      • UI: A button
      • Function: When the button is pressed, write "hi" to System.out
      • UI: A button and a TextField
      • Function: When the button is pressed, write "hi" to the TextField
      • UI: A button and 2 TextFields
      • Function: When the button is pressed, copy the contents of one TextField to the other
      • UI: A button and 2 TextFields
      • Function: When the button is pressed, copy the contents of each TextField to the other (i.e. if TF1 has "this" and TF2 has "that", after the button push, TF2 should have "this" and TF1, "that");
      • UI: A button and a TextArea
      • Function: Whenever the button is pressed, append "hello!" to the TextArea.
      • UI: Two buttons and a TextArea
      • Function: Whenever one button is pressed, append "hello!" to the TextArea. When the other button is pressed, clear the TextArea -- ta.setText("").
  2. Simple arithmetic from TextFields:
      • UI: A button and a TextField  
      • Function: Count the number of times the button is pressed and display that number in the TextField  
    1.  
      • UI: 2 buttons and 2 TextFields  
      • Function: Low end calculator. Label the buttons "+" and "clear".  When they push "+", add the number in the input TF to the total and display it in the total TF. Clear clears.   
  3. File reading
    1. UI: 2 TFs a button and aTextArea
    2. Function: On button press: open a file and (assuming the file has a series of word, one per line) output the number of instances of the word in one TF that are in the file.  
  4. File writing
    1. Write "hi" into a file.
    2. Write the contents of a TF to a file.
    3. Copy one file to another.
    4. Let the user choose both files for the I/O
  5. Strings and character manipulation
    1. Input a String from a TF and output it one character per line.
    2. Input a String from a TF and output it all in lowercase.
    3. Input a String from a TF and output it all in lowercase with all spaces and punctuation deleted.
    4. Write a method that counts the number of 'e's in a String passed as a parameter and returns that number.
    5. Write a method that counts the number of vowels in a String (passed as a parameter) and returns that number.
    6. Write a method that returns true if the char passed it is an 'e'.
    7. Write a method that returns true if the char passed it is a vowel.
    8. Write a method that returns true if all of a String parameter's characters are vowels (hint, use the vowel method from previous Q).
    9. Write a method that returns true if more of a String parameter's characters are vowels than consonants.
    10. Write a method that returns true if its String parameter is a palindrome.
    11. Write a method that returns true if its first String parameter is an anagram of its second.
  6. Statistics and things
    1. Input a series of numbers (from a file, assuming there is one number on each line) and:
      • Output their sum.
      • Output their average.
      • Output their maximum.
      • Output their median.
      • Output their mode.
      • Report any number which occurs twice in a row
      • Report any number which occurs three times in a row
      • Report any number which occurs n times in a row
      • Report the number which occurs the most times in a row
    2. Do the last 4 for chars, then for Strings.
  7. Classes
    1. Write a Player class with a name, ranking (int) and score(int).
      • Include a default constructor, and one that takes the obvious three parameters.
      • Include accessors for all three.
      • Include a constructor that is passed a MyReader and reads the info for the new player from it. Assume that each item of a player's info is on a single line in whatever order seems convenient.
      • Include a toString method that returns all the info with labels.
    2. Write a Account class with a name, balance (int) and account number (int).
      • Include a default constructor, and one that takes the obvious three parameters.
      • Include accessors for all three.
      • Include a constructor that is passed a MyReader and reads the info for the new account from it.
      • Include a toString method that returns all the info with labels.
    3. Write an AccountList class that can store up to 1000 Accounts. Include methods,
      void addItem(Account), Account deleteLast(), public String toString(), and int length().
    4. Write an PlayerList class that can store up to 1000 Players. Include methods,
      void addItem(Player), Player deleteLast(), public String toString(), and int length().
    5. You will notice that PlayerList and AccountList are very similar. So, although, it is easy to copy and paste the one to make the other, maybe there is some way to combine them. How might you do that?
    6. Write a Tournament class which used a PlayerList.
      • Include a constructor that is passed a MyReader and reads the info for the all the players from it.
      • Include a default constructor, and one that takes the obvious three parameters.
      • Include accessors (!).
      • Include a toString method.
    7. Write a Bank class which uses an AccountList.
    8. Write a Circle class with radius, x and y coordinates of the center.  Include constructors, accessors and a display(Graphics) method.
    9. Write a FilledCircle class that extends Circle, adds a Color variable, and overrides display(Graphics) to use fillOval in the appropriate color.  Add the accessors for color.
    10. Write a Card class, where each Card has a number and an Image.
    11. Write a Deck class that has 52 Cards in a CardList; like the one you did in lab. Include a constructor that creates all 52 Cards, toString(), and Card getNextCard()

[top]

[CS 231 Review Page]