Howdy. 

Wed exam. 

Closed-book, written, in class. 

Lab this week: self-assessment (open book, open Internet, can talk to anyone). 

Turn in all answers with explanations:

  (a) if the answer was good say so and explain 

  (b) if it's wrong, what's the right answer and why did you get it wrong

Give partial credit where appropriate, then submit lab. 


Simplify  b == true

  b    b == true   b
-----------------------
true   true       true 
false  false      false 

Simplify  b != true 

  b    b != true    !b 
-----------------------
true   false      false  
false  true       true 

If n is an int variable

  simplify (n <= 3) || (n >= 5)

Answer: n != 4

  simplify f(n) = (n <= 5) || (n >= 3)

Answer: true 

n            3       5
---------------------------
n <= 5 T T T T T T T T F F F F F
---------------------------
n >= 3 F F F T T T T T T T T T T
---------------------------
f(n)   T T T T T T T T T T T T T 

Simplify b || !b when b is boolean 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> System.out.println( System.out )
java.io.PrintStream@357cd939


Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> int a
> int b[]
> int[] c
> b
null
> c
null
> b = new int[6];
> c = new int[3]
{ 0, 0, 0 }
> b
{ 0, 0, 0, 0, 0, 0 }
> b[1] = 4
4
> b
{ 0, 4, 0, 0, 0, 0 }
> b[b.length - 1] = -2
-2
> b
{ 0, 4, 0, 0, 0, -2 }


import java.util.Arrays; 

public class Something {
  public static void main(String[] args) {
    int[] a = new int[10]; 
    System.out.println( Arrays.toString( a ) ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> int[] a = new int[3]
> a.length
3
> int[] b = new int[0]
> b
{  }
> b.length
0
> a
{ 0, 0, 0 }
> a[0] = 4
4
> a[1] = 1
1
> a[2] 7
Invalid top level statement
> a[2] = 7
7
> a
{ 4, 1, 7 }
> a
{ 4, 1, 7 }
> Arrays.copyOf( a, a.length + 1)
Static Error: Undefined name 'Arrays'
> java.util.Arrays.copyOf( a, a.length + 1)
{ 4, 1, 7, 0 }
> import java.util.Arrays
> java.util.Arrays.copyOf( a, a.length + 1)
{ 4, 1, 7, 0 }
> java.util.Arrays.copyOf( a, a.length + 1)
{ 4, 1, 7, 0 }
> int[] u = java.util.Arrays.copyOf( a, a.length + 1)
> u
{ 4, 1, 7, 0 }
> u[u.length - 1] = 6
6
> u
{ 4, 1, 7, 6 }
> a
{ 4, 1, 7 }
> a = u
{ 4, 1, 7, 6 }
> a
{ 4, 1, 7, 6 }
> a
{ 4, 1, 7, 6 }
> a = Arrays.copyOf(a, a.length+1)
{ 4, 1, 7, 6, 0 }
> a
{ 4, 1, 7, 6, 0 }
> a[a.length-1] = -3
-3
> a
{ 4, 1, 7, 6, -3 }



import java.util.Arrays; 
import java.util.Scanner; 

public class Something {
  public static void main(String[] args) {
    int[] nums = new int[0]; 
    Scanner in = new Scanner(System.in); 
    System.out.print("Type: "); 
    String line = in.nextLine(); 
    while (! line.equals("bye")) {
      int num = Integer.parseInt(line); 
      nums = Arrays.copyOf(nums, nums.length+1);
      nums[nums.length-1] = num; 
      System.out.println( Arrays.toString( nums ) ); 
      System.out.print("Type: "); 
      line = in.nextLine(); 
    }
    Arrays.sort( nums ); 
    System.out.println( Arrays.toString( nums ) );     
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Something
Type:  [DrJava Input Box]
[3]
Type:  [DrJava Input Box]
[3, 2]
Type:  [DrJava Input Box]
[3, 2, 5]
Type:  [DrJava Input Box]
[3, 2, 5, 4]
Type:  [DrJava Input Box]
[3, 2, 5, 4, 1]
Type:  [DrJava Input Box]
[1, 2, 3, 4, 5]


Name your lab instructors

For each one 

  (a) say something good (if any) 

  (b) say something bad (if any)

  (c) tell me which one of (a) or (b) is more important right now

The answers are confidential. 

--

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>cd \

C:\>cd Users

C:\Users>cd dgerman

C:\Users\dgerman>cd Desktop

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 02E4-5424

 Directory of C:\Users\dgerman\Desktop

09/18/2017  02:42 PM    <DIR>          .
09/18/2017  02:42 PM    <DIR>          ..
09/18/2017  02:42 PM             9,719 iceblox.gif
09/18/2017  02:42 PM               191 iceblox.html
09/18/2017  02:41 PM            17,926 Iceblox.java
               3 File(s)         27,836 bytes
               2 Dir(s)  272,635,293,696 bytes free

C:\Users\dgerman\Desktop>javac
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dgerman\Desktop>"c:\Program Files\Java\jdk1.8.0_144\bin\javac.exe"
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified profile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file


C:\Users\dgerman\Desktop>"c:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" *.java
Note: Iceblox.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 02E4-5424

 Directory of C:\Users\dgerman\Desktop

09/18/2017  02:45 PM    <DIR>          .
09/18/2017  02:45 PM    <DIR>          ..
09/18/2017  02:45 PM            14,798 Iceblox.class
09/18/2017  02:42 PM             9,719 iceblox.gif
09/18/2017  02:42 PM               191 iceblox.html
09/18/2017  02:41 PM            17,926 Iceblox.java
               4 File(s)         42,634 bytes
               2 Dir(s)  272,635,224,064 bytes free

C:\Users\dgerman\Desktop>"c:\Program Files\Java\jdk1.8.0_144\bin\appletviewer.exe" iceblox.html
Warning: Can't read AppletViewer properties file: C:\Users\dgerman\.hotjava\properties Using defaults.

C:\Users\dgerman\Desktop>"c:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" -d . BeatBox.java

C:\Users\dgerman\Desktop>"c:\Program Files\Java\jdk1.8.0_144\bin\java.exe" chap13.BeatBox

C:\Users\dgerman\Desktop>