Exam II Preparation Problems


1)

String word1="Mason";
String word2=word1.substring(2,5);

int size1=word1.length();
int size2=word2.length();

What is the value of size1?
What is the value of size2?

2)

String thestring="Happy Halloween!";

int index1=thestring.indexOf("low");
int index2=thestring.indexOf("goblin");

What is the value of index1?
What is the value of index2?

3)

String word="ANNE";
String name=word.toLowerCase();

What is the value of word?
What is the value of name?

4)	What is Unicode?  What is it's advantage over ASCII?

5)	What would the following Unix commands do?

	compress termpaper.doc
	
	finger hsmith9

	alias 108  cd it108/assignments/

6)	What would each of these commands do?

	g.drawRect(50,50,50,50);
	g.fillRect(200,100,50,100);

What import statements would you expect to need in a program that used the
above graphics commands?

7)	What would you expect the first line of this function to look
	like?

	getInput();


	What about this one?

	int x=getInput();

8)	Describe each of the following:

	flowlayout

	borderlayout

	gridlayout


9)	What is an event?

	What is a handler?

	What is a listener?

10)	Given:

	double [] temps={99.5,44.7,86.3};

	temps[1]=temps[2];

	What are the values of the array now?

11)	In the example above, what do we call [1]  (as in temps[1]) ?

12)	Using the example given in 10) above:

	int x=temps.length;

	What would be the value of x?

13)	If you type: javac  myprogram.java

	and you get an error message indicating that you have not declared	
	a variable, what type of error is this?

	If you type: java myprogram
	and your program gives incorrect output, what kind of error is
	this?

14)	Given:

	BufferedReader in= new BufferedReader(new
                FileReader("words.dat"));

	String word=in.Readline();

	Where is the value for word coming from?

15)	Given:

	PrintWriter out= new PrintWriter
                (new FileWriter("words.dat"));

	out.println("Mason");

	Where will the value "Mason" be stored?

	How would you close the file "words.dat"?
	
16)	Write an application that uses a for loop to read in 5
temperatures from the user and determines which number was the warmest
reading.

Sample execution:

Please enter 5 temperature readings:

>74.5
>68.0
>88.5
>78.0
>66.5

The warmest reading was 88.5
  
Solutions to Selected Questions
Solution to the programming problem above.