Skip to content

Instantly share code, notes, and snippets.

@DavidGinzberg
Created September 13, 2016 14:29
Show Gist options
  • Save DavidGinzberg/86e581b34e30d4ccb35b87f0d62a63a4 to your computer and use it in GitHub Desktop.
Save DavidGinzberg/86e581b34e30d4ccb35b87f0d62a63a4 to your computer and use it in GitHub Desktop.
Reusing Classes Labs

Rotate Array

Objectives

  1. To demonstrate your understanding of objects and functions
  2. To demonstrate your understanding of controlling execution
  3. To demonstrate your understanding of access control
  4. To demonstrate your understanding of reusing classes

Overview

Create a class that subclasses the built-in List class. Write a function that rotates a list by k elements. For example [1,2,3,4,5,6] rotated by two becomes [3,4,5,6,1,2]. Try solving this without creating a copy of the list. How many swap or move operations do you need?

Unit Test

No Unit Test

Instructions

  1. In your main class, initialize your custom List with values
  2. In your main class call the method that rotates your array
  3. Print original and rotated List values to screen

Rotate Array

Humans and Superhumans

Objectives

  1. To demonstrate your understanding of objects and functions
  2. To demonstrate your understanding of controlling execution
  3. To demonstrate your understanding of access control
  4. To demonstrate your understanding of reusing classes

Overview

Create a 'Human' class that has fields for: name, age, gender, occupation, and address. Also create methods for retreiving and outputing this data to screen.Then create a SuperHuman class that subclasses the first with fields for good or bad, hero name, super ability. As before, create methods for retrieving field data and printing to screen.

Unit Test

No Unit Test

Instructions

  1. In your main class initialize a few human and superhuman instances
  2. Demonstrate calling methods inherited from Human on your SuperHuman instances
  3. Print all output to screen

Class Manager

Product Inventory Project

Objectives

  1. To demonstrate your understanding of objects and functions
  2. To demonstrate your understanding of controlling execution
  3. To demonstrate your understanding of access control
  4. To demonstrate your understanding of reusing classes

Overview

Create an application which manages an inventory of products. Create a product class which has a price, id, and quantity on hand. Then create an inventory class which keeps track of various products and can sum up the inventory value.

Unit Test

UML is required Unit test in place before proceeding with code

Instructions

  1. In your main class initialize your manager and populate your inventory
  2. Demonstrate calling methods on your manager
  3. Print all output to screen

Abstract Class

Bank Account Manager

Objectives

  1. To demonstrate your understanding of objects and functions
  2. To demonstrate your understanding of controlling execution
  3. To demonstrate your understanding of access control
  4. To demonstrate your understanding of reusing classes

Overview

Create a class called “Account” which will be an abstract class for three other classes called “CheckingAccount”, “SavingsAccount” and “BusinessAccount”. Manage credits and debits from these accounts through an ATM style program.

Unit Test

UML is required Unit test in place before proceeding with code

Instructions

  1. In your main class initialize your ATM
  2. Demonstrate calling methods on your ATM with creating, deleting and managing account data
  3. Print all output to screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment