### Present Remotely

Send the link below via email or IM

• Invited audience members will follow you as you navigate and present
• People invited to a presentation do not need a Prezi account
• This link expires 10 minutes after you close the presentation

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

# TEST 5 Study Buddy

BLANK TEMPLATE
by

## Sarah Welty

on 3 January 2018

Report abuse

#### Transcript of TEST 5 Study Buddy

Test 5 Study Buddy
Reference: Chapter 2 Page 25
QUESTION 1
Reference: Chapter 2 Page 25
Reference: Chapter 2 Page 15
Compiler Error
Reference: Chapter 3 Page 54
ITSC 1212
QUESTION 3
QUESTION 4
Reference: Chapter 3 Page 43
QUESTION 5
Hello World
Reference: Chapter 6 Page 183
QUESTION 6
Option B
Reference: Chapter 6 Page 183
Question 7
QUESTION 8
True
QUESTION 10
August
Reference: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
Reference: Chapter 2 Page 29
Compiler Error
Reference: Chapter 3 Page 54
QUESTION 9
True
QUESTION 11
Reference: Chapter 6 Page 183
Reference: Chapter 3 Page 43
QUESTION 12
QUESTION 13
Reference: Chapter 11 Page 350
QUESTION 14
Reference: Chapter 3 Page 70
QUESTION 16
QUESTION 17
QUESTION 18
QUESTION 19
QUESTION 2
Reference: Chapter 2 Page 34
QUESTION 15
Reference: Chapter 3 Page 66
QUESTION 20
QUESTION 21
Reference: Chapter 3 Page 66
Reference: Chapter 11 Page 345
false
QUESTION 22
Reference: Chapter 6 Page 183
Reference: Chapter 3 Page 54
Reference: Chapter 3 Page 57
Output

> int baboons = 4;
> System.out.println("I saw " + baboons + " baboons at the zoo yesterday!" );

What will the following print out?
I saw 4 baboons at the zoo yesterday!
When Java concatenates this String, it prints exactly what is in the parenthesis, and then with the + operator, it concatenates the next value, which is the variable baboons, which is equal to 4. After that, the next + operator, indicates another String is to be added, which is the last set of parenthesis.

Java will always print out EXACTLY what is in those parenthesis, Strings are IMMUTABLE which means they can NOT be modified, they can be copied, added together, etc, but whenever you do something to a String value, Java makes a copy of the original String and adjusts it accordingly.
Output

> int baboons = 4;
>System.out.println("I saw " + (baboons-2) + " baboons at the zoo yesterday!" );

What will the following print out?
I saw 2 baboons at the zoo yesterday!
Object Creation
True or False:
You can create an infinite amount of objects from a class definition.
When concatenating Strings, you are still able to combine variables, or conduct mathematical operations. Use the parenthesis to do these operations around the variables.
To get the 1200 plus 40, you would need to put (numTurtle + increase), this tells Java that inside these parenthesis, there will be arithmetic that needs to be done.
For example
>int numTurt = 1200;
>int increase = 40;
>System.out.println ("There were " + numTurt + increase + " turtles left on the island" );
>System.out.println ("There were " + (numTurt + increase) + " turtles left on the island" );
Constructors
You have a class called Diploma. You want to create a new object from this class, and the constructor requires that when you create the object, you have to enter the last name of the student as a String and the number of credits as an int.
How would you create a new Diploma object for a student last name James, and a total of 128 credits?
Diploma
object1 = new
Diploma
("James", 128);
When creating an object of a class, remember that the first class reference (highlighted in green) is the Reference Variable TYPE. So the type of object that this object1 is and it will have access to that classes methods.

The second class reference (highlighted in red) is the constructor used to create this object, this would decide the characteristics of this object and how it is created. You will learn alot more about this in 1213, with Polymorphism. Keep this in mind.
You can create as many objects of the same class as you would like, or as much as your computer memory will allow. They can not have the same reference variable name though if they are all in the class level.
Methods
Imagine you have a fully defined public void method called drawStar. You have a Turtle object todd and he is placed at (10,10) in a World w with his pen DOWN.

What commands would you give todd to draw the star at the coordinates (100,50)?
>todd.penUp();
>todd.moveTo(100,50);
>todd.penDown();
>todd.drawStar();
When moving your Turtle object, remember to pick your pen up first. By using the moveTo method, you can easily go to an exact location. Put the pen down upon arrival and then call on the objRefVariable todd.drawStar();
This indicates that drawStar() is an object method, and needs an object to be referenced.
How many objects of a class would you need to perform 10 different methods(all of the same class)?

A) one
B) ten
C) five
D) none
Objects
You only need one object to perform multiple methods or actions. The Java compiler completes these one at a time, in order and you can use the same object over and over again. If you wanted additional objects to do things simultaneously with the first object, then having multiple can be beneficial.
But you could use one object to, for example, draw 100 squares in a world if you'd like. They don't get tired.
Datatypes
You need to keep track of the exact amount of money raised from a fundraiser, assuming you will raise bewteen five and ten thousand dollars. What datatype would you use?

A) int
B) double
C) boolean
D) String

By using the double datatype, you are able to maintain decimals and get the exact, to the penny amount of money raised.

Datatypes
What datatype would you use to store a list of names for a concert?
The String class is used as if it were one of the eight primitive datatypes.

So it is still considered a datatype, just not a primitive one.

The String class is a sequence of characters (including spaces, punctuation, etc.) delimited on either end with a double quote character.
Method Parameters
Assume the following class and method definition, what is the appropriate way to add 4 turtles to numTurtles and to set the price to \$10.99, assuming you have a TurtleTest object called todd.
todd.updateTurtle(4, 10.99);
To use this method, you must pass in two values, in order. The first is an int value (4) and the second is the double value of 10.99 for the price.
You always list your parameters to reflect the order of those in the method declaration, and separate them by commas.
Variables
What is the correct way to declare a variable for storing the amount of items sold from a vendor, and setting the initial value to 50? (variable name = numItems)
int numItems = 50;
The data type int would be useful here because you are only tracking the total number of items, by assigning it the value fifty in the declaration it is initially set to equal fifty.
Given the following code, which of the following best describes 'price'?

A) private field
B) private method
C) constructor
D) return type
Concepts
private field
The variable 'private int price' is a field in this class. Also known as a Class Variable.
It is set to private access which means only members of the class may access this variable.
Would the following class compile?

public class Test() {

//field variables
private final int SHIRTS = 24;
private int numPants= 14;

//Constructor
public Test(int blueJeans, int tankTops){
SHIRTS = tankTops + SHIRTS;
numPants = blueJeans+ numPants;

}//end of constructor

}//end of class
Variables
The class would not compile because you can not change the value of a FINAL variable. In the example, the final variable SHIRTS is changed in the Test method. This is not allowed.

The only way to adjust the value of a final variable is to change it at the line of declaration.
What is a correct way to create an object of this class?

public class Test() {

//field variables
private final int SHIRTS = 24;
private int numPants= 14;
private int tanks =0;
//Constructor

public Test(int blueJeans, int tankTops){
tanks = tanks + tankTops;
numPants = blueJeans+ numPants;

}//end of constructor

}//end of class
Object Creation
Test clothing = new Test(12, 16);
When creating an object in this class, you are required to pass in two arguments (int, int).

In Java, if the only constructor for an object takes any arguments, you have to input those properly in order to create an object of that class.
Object Pointers
You type the following code into the Interactions pane:

> World w = new World()
> Turtle tom = new Turtle(w)
> Turtle jerry = new Turtle(w)
> import java.awt.Color
> tom.setPenColor(Color.pink);
> jerry.setPenColor(Color.green)
> tom.setPenColor(Color.red)
> jerry = tom;
> jerry.forward(10);

What color pen will jerry the turtle be using when she moves forward 10?
A) red
B) green
C) pink
D) black
RED
The pen would be red, because the variable jerry now points to the tom object. They are now pointing to the same object, so the pen color would be the last color that tom set it to, which was red.

When you re assign an reference variable like this to another object, the old object that is no longer being pointed to will be garbage collected (no longer accessible in memory and frees up space)
How many object exist at the end of the following code in the interactions pane?

> World w = new World()
> Turtle tom = new Turtle(w)
> Turtle jerry = new Turtle(w)
> Turtle bob = new Turtle(w);
> Turtle num4 = new Turtle(w);
> jerry = tom;
> bob = jerry
> num4 = bob;

A) 2
B) 3
C) 4
D) 1
Object Pointers
There will only be one object left after the code is ran.
> jerry = tom;
> bob = jerry
> num4 = bob;
Say this outloud:
All of the variables now point to the tom object, so technically there is only one object left. The objects that num4, jerry and bob were all pointing to are no longer accessible.
NOTE: equals is not the technical phrase for the assignment operator '='. Just using it here for training purposes.
("num4 equals bob, bob equals jerry and jerry equals tom")
Conditions
What will be the output of the following statements:

int dog = 8;
int cat = 19;
if ((dog > 5) && (cat < 20))
{
System.out.println(“Hello World”);
} else {
System.out.println(“Else Statement”);
}
Java uses boolean tests to evaluate conditions. The boolean values true and false are returned when an expression is compared or evaluated. The use of logical operators such as && (AND) and || (OR) allow you to combine comparisons to execute the code necessary.

If everything in the if && statement is TRUE, than the if code will execute. In an && statement, if one part is false the conditon is FALSE and the else statement will execute. So if Java finds something to be false in an && statement, it will cease parsing and go to the else statement, if applicable.

If there is an || (or statement) than only one part has to be true to execute the if statement, if it is all false it executes the else statement. In an || statement like this, once Java finds one condition that is true, it does not check any further; only one part had to be true, it is, so execute code and carry on.
Conditions
String color = "green";
int x = 50;

if ((color == "green") && (x < 40)) {
System.out.println("Hello World");
} else {
System.out.println("Sunshine");
}
Option A
Option B
String color = "green";
int x = 50;

if ((color == "green") || (x < 40)) {
System.out.println("Hello World");
} else {
System.out.println("Sunshine");
}
Which option would print out "Hello World"?
Notice the only difference between the two code segments is that one has the logical && operator and the other has the || operator.

Since only one condition needs to be true in order for the || (or) statement to execute, it is Option B since String color does equal "green". Option A would not work because both of the conditions would have to be true, and x is not less than 40.
Switch Statements
What would be the output of the following main method?
public static void main(String[] args) {

int month = 8;
String monthString;
switch (month) {
case 1: monthString = "January";
break;
case 2: monthString = "February";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
case 5: monthString = "May";
break;
case 6: monthString = "June";
break;
case 7: monthString = "July";
break;
case 8: monthString = "August";
break;
case 9: monthString = "September";
break;
case 10: monthString = "October";
break;
case 11: monthString = "November";
break;
case 12: monthString = "December";
break;
default: monthString = "Invalid month";
break;
}
System.out.println(monthString);
}

In the main method, the switch statement is evaluating the value assigned to the int variable month, which is set to 8.

The switch statement will stop at the case 8 block of code, since there is a break after the String value is set. If there wouldn't have been a break here in the switch statement that corresponds to the tested value, then the switch statement would actually begin to execute every block until it hits a break statement.

NOTE: The switch will start at the case at which the tested value is equal to, and forward. It will not execute the cases that have already been disregarded.
Variables
What would be the result of the following method?

public void testing() {

}
The method would cause a compiler error, because you can not re declare a variable once it has been declared.
You would need to removed the second 'int' from the variable grade, so that way it would print out the original value, update it, and then print out the new value.
True or false:
Garbage Collection is when objects that no longer have an object variable pointing to them are deleted automatically
Concepts
Garbage collection occurs when there is no longer a pointer to an object.

This object becomes unreachable which makes it uneeded. So Java, to save memory and space, deletes these objects.
What will be the output of the following statement:

> System.out.println(!false == true);
Boolean Logic
The ! operator, means "not", so in this statement not false == true, which is true. So true is the result.
With boolean logic, it will always be true or false, if the condition being compared is true, than the output is true,and if it is not true, than the output is false.
Boolean Logic
What would the following code print out?

>int x = 10;
>int y = 10;
>System.out.println(x!=y);

Java will read this statement as, "x does not equal y" Since x and y both equal 10, this statement is false. Pay attention to the logic operators used in boolean statements. Here are a few important ones:
|
the OR operator
&
the AND operator
!
the NOT operator
||
the short-circuit OR operator
&&
the short-circuit AND operator
==
the EQUAL TO operator
!=
the NOT EQUAL TO operator
Reference: Chapter 2 Page 34
Full transcript