Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

assume that you have two references, txt1 and txt2, to two JTextField objects. I

ID: 3553723 • Letter: A

Question

assume that you have two references, txt1 and txt2, to two JTextField objects. If the first text field (referenced by txt1) has the this as its content


simplicity

and the following code is executed


String s = txt1.getText();
String s2 = s.toUpperCase();
txt2.setText(s);
txt1.setText(s2);

Then indicate what values are displayed in the two textfields.

Question options:

1)


simplicity
simplicity

2)


SIMPLICITY
SIMPLICITY

3)


simplicity
SIMPLICITY

4)


SIMPLICITY
simplicity

Question 2

Assume that you have two references, txt1, txt2 and txt3 to three JTextField objects. The three textfields start with these contents, respectively: "and", "or" and "then". Give the contents of the three text fields after these lines of code were run.


txt1.setText( txt2.getText() );
String s = txt2.getText();
txt3.setText( s.substring(0, 1) );

Indicate what values are displayed in the three textfields.

Question options:

1)


and
or
not

2)


and
and
a

3)


and
and
an

4)


or
or
o

5)


or
or
or

6)


and
or
o

Question 3

Assume that you have two references, txt1 and txt2, to two JTextField objects, and a reference myList to a JList. The text fields have the values "green" and "blue", respectively. The JList has four values in it ("one", "two", "alpha", "beta") and currently the "alpha" entry is selected. What are the values of txt1 and txt2 after the following code has been executed?


String s = (String) myList.getSelectedValue();
txt1.setText(s);
int x = myList.getSelectedIndex();
String s2 = "num: " + x;
txt2.setText(s2);

Indicate what values are displayed in the two textfields.

Question options:

1)


alpha
num: 3

2)


alpha
num: 2

3)


two
num: 2

4)


two
num: 1

1)


simplicity
simplicity

2)


SIMPLICITY
SIMPLICITY

3)


simplicity
SIMPLICITY

4)


SIMPLICITY
simplicity

Question 2

Explanation / Answer

Question 1 :

Code :String s = txt1.getText();

String s2 = s.toUpperCase();
txt2.setText(s); //this will simply print 'simplicity'
txt1.setText(s2); //this will get converted to Uppercase dues to method called and will Print as 'SIMPLICITY'


Answer : 4th Option



Question 2 :

Code :
txt1.setText( txt2.getText() ); //replaces txt1 with value of txt2; txt1 =or
String s = txt2.getText();   //fills variable 's' with value of txt2; s=or
txt3.setText( s.substring(0, 1) ); //first letter of variable 's' txt3=o


Answer : 4th Option



Question 3 :

The text fields have the values "green" and "blue", respectively. The JList has four values in it ("one", "two", "alpha", "beta") and currently the "alpha" entry is selected. What are the values of txt1 and txt2 after the following code has been executed?


String s = (String) myList.getSelectedValue(); //gets alpha into variable 's'
txt1.setText(s); //txt1 is set as 'aplha'
int x = myList.getSelectedIndex(); //x=2 as index starts with 0
String s2 = "num: " + x; //s2= num: 2
txt2.setText(s2); //txt2=
num: 2


Answer : 2nd Option