CSE1030Z Practice Labtest 2 Questions

Introduction

Here are some practice questions for the second labtest. You can expect to see one question based on inheritance and one or two short questions based on recursion.

Inheritance

1. You are given an abstract base class that represents a bank account:

Implement the class SavingsAccount that extends AbstractBankAccount:

 

2. An old programming exercise.

 

3. You are given an abstract base class for simple word puzzles:

Implement the classes ReverseWordPuzzle and ScrambleWordPuzzle:

Recursion

1. You are given a minimal implementation of a linked list:

The linked list you are given does not have an attribute that stores the size (number of elements) of the list. Add the methods:

public int size()

public static <E> int size(Node<E> n)

that returns the size of the list. The first method is the method that a client would call, and the second method is a recursive method that actually computes the size of the list. Your method must use recursion to visit each element of the list to count the number of elements in the list.

 

2. Implement the method:

public static int sum(List<Integer> t)

that computes the sum of the elements in the list t. Your method must use recursion to compute the sum.

 

3. Implement the method:

public static String reverse(String s)

that returns the string that is equal to s in reverse order. For example, reverse("abcdef") should return the string "fedcba". Your method must use recursion and can only use methods from String.