Out: Saturday, 29 January
Due: Friday, 4 February
Turnin: Gradescope
This Java program is expected to print (10.0,20.0) when run:
public class Animal { protected double xPosition; protected double yPosition; public Animal() { xPosition=0.0; yPosition=0.0; } public void MoveTo(float xNew, float yNew) { SwimTo(xNew, yNew); } public void PrintPosition() { System.out.println("("+xPostion+", "+yPosition+")"); } public static void main(String[] args) { Fish f = new Fish(); f.MoveTo(10, 20); f.PrintPosition(); } }
public class Fish extends Animal { public Fish() {} public void SwimTo(double xNew, double yNew) { xPosition = xNew; yPosition = yNew; } }
However, it doesn't even compile.
Based on that, is Java statically typed or dynamically typed? Briefly explain, using the specific example of the sample code having an error during compilation.
Java is statically typed. Abstractly, there is nothing wrong with this program. Dynamically, when Animal.MoveTo() is actually called, it is called only on a Fish object, which supports the SwimTo() function. However, because Java is performing type checking at compile time (statically), all it can count on is that the object on which MoveTo() is invoked is an Animal. Animals don't have a SwimTo() method, so Java refuses to compile because of that type mismatch.
Draw a boolean circuit that evaluates this function, using only and, or, and not gates:
A | B | C | Output |
0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 1 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 0 |
(A) What is the function evaluated at B by this circuit? Give a truth table as your answer.
(not(A1 xor B1)) and (not(A0 xor B0))
(B) Give a high level, English description of the meaning of output B. What property of the inputs is true if output B is 1?
B is true if A is equal to B. That is, the bit string A1A0 is the same as the bit string B1B0.
Turnin a pdf file with your answers on Canvas.