CS231 (Sp03) Review Topics for Exam 2
- primitive types
- int
- boolean
- double
- char
- operators and expressions
- /*-+% || && !
- Expressions have a value and a type
- messages whose methods are non-void are expressions
- What are the types and values of the following expressions? In case the expression is illegal, explain why.
- 17
- 1+2
- 1/2
- 1.0/2
- 1+2.0
- 1+2*3/4
- (1+2*3/4)%5
- ((1+2)*3)/(4%5)
- (1+2)*(3/4)%5
- true
- 1 < 2
- !(1 < 2)
- '!'
- "!"
- "ho"
- "ho" + "me"
- "ho" + "me" + "run"
- "ho" + "me" + "run" + '!'
- conversion between types
- int to String -- String s = "" + 17;
- int to char -- char ch = (char) 123;
- char to int -- int i = (int) 'a';
- String to int -- int i = Integer.parseInt("1234");
- double to int -- int i = (int) 1.234;
- int to double -- double d = 17; // !
- parameters
- formal -- void foo (int x, int y)
- actual -- someObject.foo(17,123);
- 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.
- classes
- constructors
- accessors
- toString
- Arrays
- declaring
- initializing
- using
- syntax
- Java statements
- assignment
- message
- block
- if
- for
- while
- switch
- return
- Problem solving techniques
- count
- understand the problem
- stepwise refinement (top-down design)
- remove a constraint
- add a constraint
- adopt a different perspective
- ABC - analysis by cases
- solve a simpler (but similar) problem
- solve a smaler (but similar) problem
- Graphics
- Color class
- 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.
- 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("").
- 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
-
- 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.
- File reading
- UI: 2 TFs a button and aTextArea
- 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.
- File writing
- Write "hi" into a file.
- Write the contents of a TF to a file.
- Copy one file to another.
- Let the user choose both files for the I/O
- Strings and character manipulation
- Input a String from a TF and output it one character per line.
- Input a String from a TF and output it all in lowercase.
- Input a String from a TF and output it all in lowercase with all
spaces and punctuation deleted.
- Write a method that counts the number of 'e's in a String passed
as a parameter and returns that number.
- Write a method that counts the number of vowels in a String (passed
as a parameter) and returns that number.
- Write a method that returns true if the char passed it is an 'e'.
- Write a method that returns true if the char passed it is a vowel.
- Write a method that returns true if all of a String parameter's
characters are vowels (hint, use the vowel method from previous Q).
- Write a method that returns true if more of a String parameter's
characters are vowels than consonants.
- Write a method that returns true if its String parameter is a palindrome.
- Write a method that returns true if its first String parameter is
an anagram of its second.
- Statistics and things
- 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
- Do the last 4 for chars, then for Strings.
- Classes
- 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.
- 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.
- Write an AccountList class that can store up to 1000 Accounts. Include methods,
void addItem(Account), Account deleteLast(), public String toString(), and int length().
- Write an PlayerList class that can store up to 1000 Players. Include methods,
void addItem(Player), Player deleteLast(), public String toString(), and int length().
- 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?
- 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.
- Write a Bank class which uses an AccountList.
- Write a Circle class with radius, x and y coordinates of
the center. Include constructors, accessors and a display(Graphics)
method.
- 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.
- Write a Card class, where each Card has a number and an Image.
- 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]