Lab 08 exercises (to be posted tonight along with Homework 06): 

page 357 exercise R7.5 (just a, b and e)
page 358 exercise R7.6 (e) and R7.7 (e) 
page 359 exercise R7.12 (only a)  
page 359 exercise R7.14 (all of them)
page 361 exercise R7.32 (all questions), R7.34 (all questions)

This is for Mon midnight (grace period Tue) and the reading assignment is Ch. 7 for Mon. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> "whatever" == "what" + "ever" 
false
> String a, b;
> // give a b some values
> a == b // the only sure thing is: I have no idea (true or false)

Here's what you should do:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> "whatever" == "what" + "ever"
false
> "whatever".equals("what" + "ever")
true


Nicholas asked about:

https://forum.unity3d.com/threads/double-or-float-a-few-questions.26438/

What about R6.19? 

Put one class per file also make classes public. 

Also I want zipped files in Homework and Lab assignments from now on. 

Maybe we should practice that tomorrow. 

Here's how you can start your diamond:


public class One {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    for ( int lines = 0 ; lines < size ; lines = lines + 1 ) {
      for (int columns = 0; columns < size; columns = columns + 1) {
        if ( lines + columns > size / 2 && lines + size/2 > columns ) {
          System.out.print("* "); 
        } else {  
          System.out.print("  ");         
        }
      } // end of line 
      System.out.println(); 
    }
  }
}

I run this and I get: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\testing
> run One 13
                          
            *             
          * * *           
        * * * * *         
      * * * * * * *       
    * * * * * * * * *     
  * * * * * * * * * * *   
* * * * * * * * * * * * * 
* * * * * * * * * * * * * 
* * * * * * * * * * * * * 
* * * * * * * * * * * * * 
* * * * * * * * * * * * * 
* * * * * * * * * * * * * 
> run One 25
                                                  
                        *                         
                      * * *                       
                    * * * * *                     
                  * * * * * * *                   
                * * * * * * * * *                 
              * * * * * * * * * * *               
            * * * * * * * * * * * * *             
          * * * * * * * * * * * * * * *           
        * * * * * * * * * * * * * * * * *         
      * * * * * * * * * * * * * * * * * * *       
    * * * * * * * * * * * * * * * * * * * * *     
  * * * * * * * * * * * * * * * * * * * * * * *   
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * 


I still have to carve the lower half (with a boolean condition) but I am halfway done too. 

--

Student

Ankney, Garrett    Berry-Simms, Khalea     Clark, Daniel
Cooper, Keiland    Cotter, Ryan            Gan, Kang Jie
Hay, Stuart        He, Kefei               Hiraga, Misato
Hu, Tao            Jing, Elise             Kaefer, John
Kowala, Katherine  Liu, Li                 Matlock, Noah 
Navarro, Nicholas  Nieves, Rafael not here yet? 
O'dell, Taylor     Parker, Patrick         Pena, Jillian
Qian, Jiang        Reba, Christopher not here yet 
Ruiz, Daniel totally here                  Salazar, Luis not here yet?
Shen, Bihan        Stamets, Justin         Wang, Iris    
Wang, Yibo

public class Circle {
  Point center; // instance variable
  double radius; // instance variable 
  public Circle(Point center, double radius) { // formal params, like local 
    this.center = center; 
    this.radius = radius; 
  }
  public double area() {
    return Math.PI * Math.pow(this.radius, 2); 
  }
  public boolean overlaps(Circle other) {
    double distance = this.center.distanceTo(other.center); 
    boolean answer;
    if (distance <= this.radius + other.radius)
      answer = false; 
    else 
      answer = true; 
    return answer; 
  }
}

1. A method has exactly one return statement.
2. A method has at least one return statement.
3. A method has at most one return value.
4. A method with return value void never has a return statement.
5. When executing a return statement, the method exits immediately.
6. A method without parameter variables always returns the same value

class Wizard {
   
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Wizard a = new Wizard()
> a
Wizard@4eb82b7a
> new Wizard()
Wizard@5fdff5


public class Wizard {
  public boolean fun() {
     double a = Math.random(); 
     if (a < 0.5) 
       return false;
     else 
       return true;
  }
}

So the first question answer is: false. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Wizard a = new Wizard()
> a
Wizard@413e42b7
> a.fun()
true
> a.fun()
false


public class Wizard {
  public boolean fun() {
     double a = Math.random(); 
     if (a < 0.5) 
       return false;
     else 
       return true;
  }
  public void spider() {
    System.out.println("        //  \\\\"); 
    System.out.println("       _\\\\()//_"); 
    System.out.println("      / //  \\\\ \\");
    System.out.println("       | \\__/ |"); 
  }
}

So the answer to the second question: false.

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Wizard a = new Wizard()
> a.fun()
false
> a.spider()
        //  \\
       _\\()//_
      / //  \\ \
       | \__/ |


3. A method has at most one return value. 

On page 203 of your textbook the term "return value" is defined. 

It doesn't mean "return type". A method has only one return type. 

But as is shown in the answer to the first question a method can return two or more values. 

(But not at the same time!) 

In fact the simplest justification to this question is: no return type has cardinality one. 

void has cardinality zero, boolean has cardinality two and everything else is by and large infinite.

http://silo.cs.indiana.edu:8346/c212/spr2013/eeesols.phps

Do we mean at the same time or not? 

At the same time: true. 

Not at the same time: false. 

Do we mean return type or not? (We discussed this above.) 

4. The answer is false because I built a counterexample:

public class Wizard {
  public boolean fun() {
     double a = Math.random(); 
     if (a < 0.5) 
       return false;
     else 
       return true;
  }
  public void spider() {
    System.out.println("        //  \\\\"); 
    System.out.println("       _\\\\()//_"); 
    System.out.println("      / //  \\\\ \\");
    System.out.println("       | \\__/ |"); 
  }
  public void spider(int n) {
    if (n % 2 == 1) {
      return; 
    } else {
      System.out.println("        //  \\\\"); 
      System.out.println("       _\\\\()//_"); 
      System.out.println("      / //  \\\\ \\");
      System.out.println("       | \\__/ |"); 
    } 
  }

}

5. True, maybe too obvious but here's evidence:

public class Wizard {
  public double something() {
     return Math.random(); 
     System.out.println("I am still here ha ha ...!"); 
  }
  public boolean fun() {
     double a = Math.random(); 
     if (a < 0.5) 
       return false;
     else 
       return true;
  }
  public void spider() {
    System.out.println("        //  \\\\"); 
    System.out.println("       _\\\\()//_"); 
    System.out.println("      / //  \\\\ \\");
    System.out.println("       | \\__/ |"); 
  }
  public void spider(int n) {
    if (n % 2 == 1) {
      return; 
    } else {
      System.out.println("        //  \\\\"); 
      System.out.println("       _\\\\()//_"); 
      System.out.println("      / //  \\\\ \\");
      System.out.println("       | \\__/ |"); 
    } 
  }

}

2 errors found:
File: C:\Users\dgerman\Desktop\Wizard.java  [line: 4]
Error: unreachable statement
File: C:\Users\dgerman\Desktop\Wizard.java  [line: 5]
Error: missing return statement

Second error a bit off, fix errors one at a time (the first) then recompile.

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Math.random()
0.6597285584828276
> Math.random()
0.12533028926301681
> Math.random()
0.582014356232058
> Math.random()
0.6592756598894901
> Math.random()
0.8580502278438071
> Math.random()
0.8871857306266232
> Math.random()
0.27537232695403346


6. The answer is: false, and here's the evidence: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Math.random()
0.6597285584828276
> Math.random()
0.12533028926301681
> Math.random()
0.582014356232058
> Math.random()
0.6592756598894901
> Math.random()
0.8580502278438071
> Math.random()
0.8871857306266232
> Math.random()
0.27537232695403346


See you tomorrow for the exam. 

--