辅导案例-CS101

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Final Exam Practice Questions
CS101 - Introduction to Computer Science
Spring 2020
The format of the final is similar to the midterm.
The focus of the final exam is material from after Midterm Exam #2 and covers Ch 11, 12, 13 - and stacks.
You will need to know about static and instance variables and methods, loops, local variables, parameters,
primitive types, reference types, pass by reference/pass by value, classes and objects, etc. in order to write code
for the exam.
Here are some additional concepts to think about and know…
ArrayList: How to read/write an array list vs. an array?
See the slides and the book. To access elements in an array list we use the methods provided by the array list
class. To access elements in an array we use [array index value]. Review the code provided for array lists in
Resources, the slides, and the textbook. Write some code to test your understanding.
Stacks: How is a system stack used vs. how is a user stack is used?
The System Stack is what we've been talking about since the start of the semester - it's where the activation
frame (stack frame) for each method called is pushed. We reviewed examples of call by value and call by
reference by drawing the System Stack. We never directly push/pop the System Stack; an activation frame (for an
activated method, i.e., a called method) is pushed on the stack by the JVM (Java runtime).
A user stack - like StackOfCharacters which was provided in Resources - is a stack that we can directly push/pop
as we see fit. It can be used to reverse a string, but it can also be used to store anything - even a Matrix or other
reference type. It's a good idea to add some println() statements to the push(), pop(), etc. methods in
StackOfCharacters to trace the variables and understand how each method works.

! | P a g e 2
1
2
3
In what order are constructors in a class hierarchy called, executed, completed?

How does constructor chaining work?

Describe what would happen if class B had no constructor defined?
Describe what would happen if classes A and B had no constructor defined?
! | P a g e 3
4
5
6a
6b
6c

Show how to open a file for reading.

! | P a g e 4
7
8 Explain what the implements keyword is used for.

9 Show how to open a file for writing.


! | P a g e 5
12 Which one, an abstract class or an interface, is not part of a class hierarchy?

10 What happens when you open an existing file (one that has some data in it) with PrintWriter vs. what
happens when you open that same file with Scanner?

11 When do you use an abstract class?


! | P a g e 6
13 Can a given class implement more than one interface?

14 Can a given class extend more than one abstract class?

15 Can an abstract class have concrete methods?

16 Can an interface have concrete methods?

17 Describe polymorphism.

Array Lists
a) How do you create an array list?
b) How is it different from an array?
c) How do you read from and write to an array list? How would you do the same with an array?
! | P a g e 7
18
Stacks
a) How is a system stack used vs. how is a user stack (like StackOfCharacters) used?
b) What are the main user stack operations (methods) we can call?
c) How are the peek() and poke() operations different from pop() and push()?
d) Draw a stack to show each of the following as a sequence of operations on the same user stack, s1:
- starting stack - empty stack
- s1.push(‘A’);
- s1.push(‘B’);
- s1.push(‘C’);
- char x = s1.pop();
Be sure to show where the bottom of the stack is, and show the top of stack pointer as it changes from operation
to operation. Show how the elements were placed on the stack. What is the value of variable x at the end?
! | P a g e 8
19
Stacks (continued)
e) Using a stack, write code that can check if a string is a palindrome.
! | P a g e 9
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468