OC userin Computer Science·2 Mar 201819. (2 points) Given the Rocket class from program 6 which includes instance variables xVel and yvel, write a method called safeLanding () that could be added to the Rocket class and returns true if the rocket made a safe landing and false otherwise. Assume the rocket has landed and you are only deciding if it was a safe landing or not. A safe landing is one in which both the x and y velocities are between -0.4 and 0.4. class Rocket { float xVel, yvel; // most of the class is omitted and not needed for this question // put your safeLanding method here
OC userin Computer Science·4 Mar 20188. We use transistors to construct gates, the diagram below represents the gate. Source Emitter Ground a. NOT b. AND c. OR d. XOR
OC userin Computer Science·1 Mar 201855. Line 3 (A) for (int j = height; j< height - i; j+-height) { (B) for (int j = 0; j< 2 + height; j+=height) { (C) for (int j = 0; j< height - i * 2; j++) { (D) for (int j = 0; j< height - i-1; j++) { (E) for (int j = 0; j< height ; j++) {
OC userin Computer Science·1 Mar 201812. What does this program print? The function print() is like println() except that it does not print a new line character after printing the value so if more than one of the print() statements executes all output will be on one line int x = 10, y = 10, z = 5; if (x == y) { print ("A"); A. A if (x > 2) B. AB print("B"); C. ABC D C else if (y > 2) E. AC print("C");
OC userin Computer Science·27 Feb 2018Recursion Question 5. In the following question, you will be asked to program the following using recursion. If you have an iterative solution, you may use it, but the most you can get for the question will be half credit. (5) points) Consider the following mathematical function h which operates on integers. (1, if n < 2 h(n) = n(n-1) +n if n > 2 and n is even han -2) +2*n if n > 2 and n is odd In Java, use recursion to write a method h which takes as input an int n and returns h (n). public static int h(int n) {
OC userin Computer Science·1 Mar 2018Part (e) [1 MARK) What additional piece of information do you know about the sorted section during selection sort that you don't know during insertion sort?
OC userin Computer Science·27 Feb 201816. What prints when the following snippet of code is executed? int[] foo = {1,2,3); int() foo2 = foo; int[] bar = {1,1,1); foo2 [1] = 1; bar[2] = 3; System.out.print (foo [1]); System.out.print(" "); System.out.println(foo == bar);
OC userin Computer Science·28 Feb 201831. The result of adding two 10-bit numbers: 1111111111 + 0000000001 in 2's complement, is a) 0000000000 x b) overflow c) 1000000000 d) underflow e) None of the above
OC userin Computer Science·26 Feb 2018Coding Question - Sorted array You are to write a method that takes as input an array of integers, returns true if the array is sorted, and returns false otherwise. For example, if a is the array {1,12,5,6,2,87}, then the method has to return false as it is not sorted. Use the 5 following questions to "write" your code. Pay close attention to how your answers group together with each other. 33. Line 1 (A) public static boolean Sorted (int[] a) { (B) public static void Sort (int[] a) { (C) public static int[] Sorted (int a) { (D) public static boolean Sorted() { (E) public static void main(String[] s) {
OC userin Computer Science·25 Feb 2018• Given that the two legs (i.e. not hypotenuse) of a right triangle have lengths A and B (doubles), write a Java expression to calculate the length of the hypotenuse in terms of A and B. (Remember that if the two legs of a right triangle have length A and B, then the length of the hypotenuse I can be calculated using the formula H2 = A + B2)
OC userin Computer Science·26 Feb 2018I. [10 marks For each row in the table below, determine what would happen if you opened DrScheme and tried to evaluate the given code. If there is an error, brielly explain what is wrong (be more specific than saying "invalid Scheme expression"). If there is no error, give the value produced by DrScheme. The first two rows have been completed for you as examples. Answer Scheme Code (+ 12) (+ 1 2)) (7 + 12) Error. There is an extra) (+ 4 (* 1 (+ 4 2))) ( 1 ((reraircer 27 9) (sqr 5))) (/ 10 (-3 (-14))) (= 'apple 'banana) (and (< 3 4) 19 10)) (- 12 (string-length. "iya")) (reso rest (rest (rest (cors'a (cons 3 (cons 5 empty))))))) (cond [(> 3 8) "happy! [(-34) 'sad) [(even? 9) 'oops] ) (posn-X (first (rest (coris (make-posn 3 4) (cons (make-posr. 56) empty)))))
OC userin Computer Science·24 Feb 201847. Line 3 (A) int counter = 0; (B) int counter; (C) if (current == null); { (D) while (current != null) { (E) if (current != null); {
OC userin Computer Science·23 Feb 20181. Which of the following is NOT a legal Java statement: (A) double x = "3"; (B) int x = 3; (C) double x = 7 / 2; (D) double x = 3; (E) double x = 3.0;
OC userin Computer Science·24 Feb 20187. 16 marks Complete the Scheme function within which consumes a number n, a non-negative number base, and a non-negative number range, and produces crue il n satisfies (base - range) < n <= (base + range), and fa-se if not. For example, (within 10 5 6) => true, and within 10 5 2) => false. (define (within n base rarge)