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

Fall 2012 .S Pes) what the output o, .he bew coda men. , [5 pts) what is the out

ID: 3601228 • Letter: F

Question

Fall 2012 .S Pes) what the output o, .he bew coda men. , [5 pts) what is the output of tho below code? string hane Mack int valname JengthO ystem.out printinival) 7. [15 pts) See coding instructions lower on the page implement a class Cube. A cube has side length (a double) Provide a constructor with one argument public Cube (double sideLength) and methods public double getsideLength) public double get Vo lume / //volumes Ls calculated a side side side publie double growcube (double growength) increases the Supply a CubeTester class that tests all methods. You may lose points if you don't pay special attention to the following in your program: . Your code should be properly indented . Use appropriate data types, e.g, use integer data types where there will be no need to store floating point numbers. . Avoid magic numbers, i.e., use named constants instead of numeric/string literals and wri a short comment that explains its purpose. E.g., final double Pl = 3.14; //value of pi area Pl radius radius; instead of area 3.14 radius radius Mid Exam Page 3 of 4

Explanation / Answer

1) valid/Invalid

3_stooges --> Invalid suffix "_stooges" on integer constant

stooges#3 --> Invalid stray #

threeStooges --> Valid variable name

3stooges --> Invalid suffix on integer constant

2) code segment is

int mystery = 0; // Initial value of mystery is "0"

mystery = val + 10; // now, mystery stores the value 10. i.e, mystery = 0+10 = 10.

3) Program

public class Test // Test is class name

{

public static void main(String[] args)

{

System.out.println("45 + 6"); // It displays 45+6 as output.

System.out.println(45 + 6); // It displays 51 as output.

}

}

Output

45 + 6

51

4) Given sequence

int mystery = 5; // Initial value of mystery is "5"

mystery = 2 * mystery + 1; // now, mystery stores the value 11. i.e, mystery = 2*5+1 = 11.

mystery = mystery - 1; // mystery = 11-1 = 10.value 10 is stored in mystery variable.

5) code fragment

String river = "Thames"; // String variable river stores "Thames"

river = river.replace("hame","am"); // It replaces the string "Thames" as "am" insteed of "hame".

System.out.println(river); // It displays output as --> Tams.

Output

Tams

6) code

String name = "Mark"; // String variable name stores "Mark"

int val = name.length(); // length of string that stored in name variable is taken and stores the length in val variable.i.e, Mark has 4 letters.

System.out.println(val); // It displays output as --> 4 .

Output

4