1. What is the difference between a class and a class object?
2. Suppose that s1 and s2 are String variables. Explain the difference between the comparison s1.equals(s2) and the comparison s1 == s2.
3. What is the difference between a primitive type variable and a class type variable?
4. Why can't a static method of a class call (access) a non-static method of the class?
5. When designing a data class what kinds of methods should be considered for inclusion in the class?
6. Consider the following statements:
String s1 = new String(''abcdef'');
String s2 = new String(''123abc'');
What are the values of the following expressions?
a. s1.substring(5)
b. s1.substring(2,3)
c. s1.charAt(0) == s2.charAt(4)
d. s1.substring(0,3).equals(s2.substring(3))
e. s1.substring(0,3) == s2.substring(3)
7. Suppose we have the declaration:
int x = 37;
What are the values of the following expressions?
a. 37 % 7
b. 37 / 7
c. 6 * (x / 6) +( x % 6)
8. Suppose we have the following statement:
String s = ''Miami Fl 176 37.37'';
Write a code segment to extract Miami into a String variable, FL into a String variable, 176 into an int variable and 37.37 into a double variable.
9. Suppose a person's full name is in a String object referenced by the String variable fullName in the format first name, a space, a middle initial, a period, a space, last name. For example: William T. Kraynek. Write Java statement(s) to remove the middle initial and the period and reverse the order of the names with a comma and space separating the names and reference the result by the String variable lastFirstName. For example if fullName refered to ''William T. Kraynek'' then after the Java statement(s) lastFirstName would refer to ''Kraynek, William''.
12 pts.
11. What is displayed after the following Java code segment has been executed?
ArrayList<String> words = new ArrayList<String>();
numbers.add("FIU");
numbers.add("Miami");
numbers.add("Heat");
numbers.add("Pittsburgh");
numbers.add("Marlins");
numbers.add("FSU");
numbers.add("UF");
numbers.add(4,"Steelers");
numbers.remove(7);
numbers.remove(numbers.indexOf("FSU"));
numbers.remove("FIU");
JoptionPane.showMessageDialog(null,words);
.
12. Suppose an ArrayList<String> variable named words has been declared and many words (Strings) have been added to it. Write a Java code segment to remove all of the occurrences of the String "FSU" from words.
13. Connsider the method:
void aMethod(int z, String s, ArrayList<Integer> a) {
z = z + 1;
int y = a,get(z);
a.set(z, y+2);
s = "Pittsburgh";
}
What is displayed after the following code segment is executed?
ArrayList<String> numbers = new ArrayList<Integer>();
numbers.add(23);
numbers.add(37);
numbers.add(2);
numbers.add(5);
int x = 0;
String w = “Miami”
aMethod(x,w,numbers);
JOptionPane.showMessageDialog(null,x + '' '' + w + '' ''+ numbers);
15. Write a method
String concatenateAll(ArrayList<String> words)
that accumulates all of the words in the ArrayList<String> words into a single String with an end-of-line between each word and returns the result.
16. Design a class similar to the TeamStats of NCAA assignments. The class will have two private fields, a String field representing a team name and an ArrayList<String> field representing the list of teams that the team in the first field beat. Include a constructor from a team name, accessors, modifiers, the equals methods ( objects of the class are equal if the team names are equal ) and a toString method.
17. Write a Java main class to read the NCAA data file, which has the form
year:winning team:score:losing team:score
for example
1996:UCLA:95:FIU:56
and display each team along with all the teams that that team beat in the NCAA tournament. Use the class in the previous problem.