# Lab12 - ITI 1120 Lab#12 Contents Old CSI 1100 exam and how...

This preview shows pages 1–6. Sign up to view the full content.

1 ITI 1120 Lab #12 Contents: Old CSI 1100 exam, and how to do it! Question 1A [4] • Environment Canada will report a humidex value as part of a weather forecast if the temperature (T) is greater than or equal to 30 degrees, if the temperature is greater than or equal to 25 degrees and the humidity (H) is greater than 35%, or the temperature is greater than or equal to 20 degrees and the humidity is greater than or equal to 65%. • Write a Boolean expression that is true if Environment Canada will report a humidex value, and false otherwise.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Question 1A • Environment Canada will report a humidex value as part of a weather forecast if the temperature (T) is greater than or equal to 30 degrees, if the temperature is greater than or equal to 25 degrees and the humidity (H) is greater than 35%, or the temperature is greater than or equal to 20 degrees and the humidity is greater than or equal to 65%. •A n s w e r : T 30 OR (T 25 AND H > 35) OR (T 20 AND H 65) Question 1B [4] • Consider the following Java program : MyClass[] obj; int index; obj = new MyClass[2]; index = 15; while( index > 2 ) { obj[index % 2] = new MyClass( ); index = index / 2; } // Line X • How many instances of MyClass are created during the execution of this program? [2] • How many instances of MyClass are still accessible at Line X ? [2]
3 Question 1B obj index # objects Initial values ?? 1 index = index / 2; 7 while( index > 2 ) : true obj = new MyClass[2]; index = 15; 15 while( index > 2 ) : true obj[index % 2] = new MyClass( ); Question 1B obj index # objects From previous page 71 2 3 index = index / 2; 1 while( index > 2 ) : false obj[index % 2] = new MyClass( ); index = index / 2; 3 while( index > 2 ) : true obj[index % 2] = new MyClass( ); Number of objects created: 3 Number still accessible: 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Question 1C [4] class Foo { private int x1; public static int x2; public static Bar x3; public Foo(int x4) { ... } } class Bar { public int x5; public static int x6() { ... } public Foo x7() { ... } } Suppose that the following instructions are used in the main() method in a class Test . Each choice should be considered independently – as it if were in its own main() method. Circle the letter of the statement which causes a compilation error. (a) Foo[] a = new Foo[5]; d) int k = Foo.x3.x5; a[4] = new Foo(-1); (b) Foo f = Bar.x7(); e) Bar b = new Bar(); (c) Foo.x2 = Bar.x6(); Foo f = b.x7(); Question 1C class Foo { private int x1; public static int x2; public static Bar x3; public Foo(int x4) { ... } } class Bar { public int x5; public static int x6() { ... } public Foo x7() { ... } } a) OK Foo[] a = new Foo[5]; a[4] = new Foo(-1); Declare and create an array of 5 Foo object references. The references are all null . There is a public Foo constructor with 1 integer parameter.
5 Question 1C class Foo { private int x1; public static int x2; public static Bar x3; public Foo(int x4) { ... } } class Bar { public int x5; public static int x6() { ... } public Foo x7() { ... } } b) Compile error Foo f = Bar.x7(); The method x7() in the Bar class does not have the keyword static , so it is an instance method. Instance methods cannot be called using the class name.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

Lab12 - ITI 1120 Lab#12 Contents Old CSI 1100 exam and how...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online