Midterm 2 Review¶
Your "reading" for this week is to prepare for the exam. Begin by taking the sample exam on your own so you know what you need to study.
Sample Questions¶
Take the exam below on your own, closed book, without a computer. Set a 50-minute timer so you can practice finishing in the time alloted. The actual exam will be similar in difficulty and length to this exam.
Note
Practice drawing memory diagrams for Question 2 (EarRing, LipRing, NavelRing, and NoseRing) of the sample exam.
- These specific questions should not be construed as a study guide. The questions do not necessarily provide information about what you should and/or shouldn't study. Try to write and answer different variants of each question. You may discuss your questions and answers with other students enrolled in the course.
AI: Generate More Questions ✨
You can use AI tools (like Copilot or ChatGPT) as a useful study tool!
Have it generate more questions similar to those on the sample exam:
"Without giving me the solution, create a question similar to: ..."
And paste the question text from the sample exam in place of the ellipsis. Then, try to answer the question on your own.
Once done, you can ask the AI tool to generate a solution for you to compare against your own. Or, you can give it your answer and ask for feedback.
"Please provide feedback on my answer: ... ""What is the answer to the previous question?""Give me a step-by-step solution to the previous question."
Memory Diagrams¶
You will need to draw memory diagrams for some questions on the exam. You must follow the format presented in class!
We recommend reviewing the solutions to the memory diagram activities on Canvas.
Ask your instructor to draw them during office hours or the in-class review session if you have questions!
Practice drawing memory diagrams for the following code snippets:
Exercise 1: Variables
long money = 50;
boolean good = true;
double price = money;
char hash = '#';
String rating = "PG";
Exercise 2: Arrays
int[] data = null;
int[] counts = {10, 3, 7, -5};
double[] scores = new double[3];
String[] words = new String[2];
String[] take = {"CS 159", "CS 227"};
int[] easy = {1, 2, 3};
int[] copy = easy;
Exercise 3: Methods
public static void main(String[] args) {
int[] nums = {159, 227};
printArray(nums);
}
public static void printArray(int[] a) {
System.out.print("{" + a[0]);
for (int i = 1; i < a.length; i++) {
System.out.print(", " + a[i]);
}
System.out.println("}");
}
Exercise 4: Objects
public class Card {
private int rank; // 1=Ace, ..., 11=Jack, 12=Queen, 13=King
private int suit; // 0=Clubs, 1=Diamonds, 2=Hearts, 3=Spades
public Card(int rank, int suit) {
this.rank = rank;
this.suit = suit;
}
public static void main(String[] args) {
Card c1 = new Card(8, 1);
Card c2 = new Card(12, 2);
Card c3 = c1;
c1 = c2;
}
}
Exercise 5: Static
public class BankAccount {
private static final String PREFIX = "1234";
private static int nextNumber = 1;
private String number;
private String owner;
private double balance;
public BankAccount(String owner) {
this.number = PREFIX + String.format("%04d", nextNumber);
this.owner = owner;
nextNumber++;
}
public static void main(String[] args) {
BankAccount ba1 = new BankAccount("Stacie");
BankAccount ba2 = new BankAccount("Trevor");
}
}
Review Videos¶
We have the following review videos from previous semesters that cover some of the topics on Exam 2.
Classes¶
This video by Dr. Weikle was posted for Exam 1 but is also a great review of classes and UML for Exam 2.