o CISC 3115 — Lab #2

CISC 3115
Introduction to Modern Programming Techniques
Lab #02
Classes

How to Develop and Submit your Labs

Overview

This lab is a parallel to Lab 01; it consists of the exercises in that lab rewritten as classes (and associated apps with main.

Each lab from Lab 1 will be presented here as two exercises: the class itself, and then the app class containing main (and possibly supporting methods, such as my doIt and printQuadrantInfo in my lecture implementations(.

Implementation Suggestions

There are actually two paths to implementing the following exercises:

The Second Approach — Transforming Procedural Code into OOP Code

Transforming the Lab 1 app into their corresponding class equivalents is fairly straightforward for most of them: Note: The above is for these introductory examples. In general (i.e., outside of this lab), you will be starting from scratch, rather than from a 1115-style (what is known as procedural) example.

Lab 2.1 Counter

Lab 2.1.1 A Counter Class (Counter) (Approval)

Write a counter class corresponding to the counter of Lab 1.1.1. Do not include a main method (that's the next exercise)

Lab 2.1.2 An App Class for 2.1.1 (UpperBoundedCounterApp) (Approval)

Write an app class containing a main method (and any other supporting methods you want) that illustrates the use of your class from Lab 2.1.1. The app should consume the same input and produce the same output as in Lab 1.1.1.

What's the Point of This Lab?

Lab 2.2 Container

Lab 2.2.1 — A Container Class (Container) (Approval)

Implement Lab 1.2 as a class.

The method should print the elements as a comma-separated sequence suyrround by {}'s (as in the corresponding class in Lecture 2).

Lab 2.2.2 — A Container Class App (ContainerApp) (Approval)

Write the app class for Lab 2.2.1

What's the Point of This Lab?

Lab 2.3 Color

Lab 2.3.1 — An RGB Color Class (Color)) (Approval)

Implement the color app of Lab 1.3 as a Class, where the r, g, and b values become instance variables.

Lab 2.3.2 — An RGB Color App Class (ColorApp)) (Approval)

Write the app class for Lab 2.3.1
stdout
r: 0 g: 0 b: 0
is valid: true
hex: #000000
name: Black
is grey: true
is primary: false

r: 0 g: 0 b: 255
is valid: true
hex: #0000ff
name: Blue
is grey: false
is primary: true

r: 0 g: 255 b: 0
is valid: true
hex: #00ff00
name: Green
is grey: false
is primary: true

r: 0 g: 255 b: 255
is valid: true
hex: #00ffff
name: Aqua
is grey: false
is primary: false

r: 255 g: 0 b: 0
is valid: true
hex: #ff0000
name: Red
is grey: false
is primary: true

r: 255 g: 0 b: 255
is valid: true
hex: #ff00ff
name: Magenta
is grey: false
is primary: false

r: 255 g: 255 b: 0
is valid: true
hex: #ffff00
name: Yellow
is grey: false
is primary: false

r: 255 g: 255 b: 255
is valid: true
hex: #ffffff
name: White
is grey: true
is primary: false

r: 10 g: 20 b: 30
is valid: true
hex: #0a141e
name: Unknown color (#0a141e)
is grey: false
is primary: false

 === Printing out the pre-defined Color objects

BLACK: (0, 0, 0)
WHITE: (255, 255, 255)
RED: (255, 0, 0)
GREEN: (0, 255, 0)
BLUE: (0, 0, 255)

What's the Point of This Lab?

Lab 2.4 Quadrilateral

Lab 2.4.1 — Quadrilateralsl Class (Quadrilateral) (Approval)

Implement the quadrilateral app of Lab 1.4 as a class.

I've supplied the Line and Point classes (both as source and class files; you might want to experiment with your IDE in how to add .class files to your project.

Lab 2.4.2 — Quadrilateral App Class (QuadrilateralApp) (Approval)

Code the app class for Lab 2.4.1

What's the Point of This Lab?

Phonebook

Lab 2.5.1 — Phonebook (Phonebook) (Approval)

Implement the Phonebook of Lab 1.5 as a class

Lab 2.5.2 — Phonebook App (PhonebookApp) (Approval)

Write the app for Lab 1.5.1. (I've supplied the PhonebookEntry class source file as well the Phonebook file).

stdout

{Arnow, David: 123-456-7890, Harrow, Keith: 234-567-8901, Jones, Jackie: 345-678-9012, Augenstein, Moshe: 456-789-0123, Sokol, Dina: 567-890-1234, Tenenbaum, Aaron: 678-901-2345, Weiss, Gerald: 789-012-3456, Cox, Jim: 890-123-4567, Langsam, Yedidyah: 901-234-5678, Thurm, Joseph: 012-345-6789}
lookup, reverse-lookup, quit (l/r/q)? last name? first name? David Arnow's phone number is 123-456-7890

lookup, reverse-lookup, quit (l/r/q)? phone number (nnn-nnn-nnnn)? 456-789-0123 belongs to Augenstein, Moshe

lookup, reverse-lookup, quit (l/r/q)? last name? first name? -- Name not found

lookup, reverse-lookup, quit (l/r/q)? last name? first name? Gerald Weiss's phone number is 789-012-3456

lookup, reverse-lookup, quit (l/r/q)? phone number (nnn-nnn-nnnn)? -- Phone number not found

lookup, reverse-lookup, quit (l/r/q)? 
3 lookups performed
2 reverse lookups performed

What's the Point of This Lab?