o CISC 3115 — Lab #1

CISC 1115
Introduction to Modern Programming Techniques
Lab #01
Classes

How to Develop and Submit your Labs

Lab 1.1 An Upper-Bounded Counter

The following two exercises implement a counter that can only be incremented to a specified limit. The first exercise (1.1.1) implements the object class, and the second (1.1.2) the app class

What's the Point of This Lab?

Lab 1.1.1 An Upper-Bounded Counter Class (UpperBoundedCounter) (Approval)

Write a class UpperBouncedCounter that models an up/down counter with an upper limit. The counter can always be decremented, but can only be incremented as long as the current value is less then the limit.

The class should contain the following state and behavior:

The next lab (1.1.2) illustrates the object in use; you might want to take a look at it before you start implementing your class.

What's the Point of This Lab?

Lab 1.1.2 An App Class for 1.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 1.1.1. The app should:
Here is a sample set of data:

counter_actions.text

0 5
+
+
+
+
+
+
-
-
-
+
+
+
Sample Test Run

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

After reading in ubc1: 0/5
Action is + ... up: true ... ubc1: 1/5
Action is + ... up: true ... ubc1: 2/5
Action is + ... up: true ... ubc1: 3/5
Action is + ... up: true ... ubc1: 4/5
Action is + ... up: true ... ubc1: 5/5
Action is + ... up: false ... ubc1: 5/5
Action is - ... down: true ... ubc1: 4/5
Action is - ... down: true ... ubc1: 3/5
Action is - ... down: true ... ubc1: 2/5
Action is + ... up: true ... ubc1: 3/5
Action is + ... up: true ... ubc1: 4/5
Action is + ... up: true ... ubc1: 5/5

Creating ubc2 with a value one more than ubc1's value and a limit twice that of ubc1's limit
Initially: ubc2: 6/10
Bumping ubc2 up to its limit
After an up: ubc2: 7/10
After an up: ubc2: 8/10
After an up: ubc2: 9/10
After an up: ubc2: 10/10
... and now down to ubc1's value
After a down: ubc2: 9/10
After a down: ubc2: 8/10
After a down: ubc2: 7/10
After a down: ubc2: 6/10
After a down: ubc2: 5/10

Here is the actual output from System.out (stdout or the standard output stream) as you will see in in CodeLab's test case tables. stdout

After reading in ubc1: 0/5
Action is + ... up: true ... ubc1: 1/5
Action is + ... up: true ... ubc1: 2/5
Action is + ... up: true ... ubc1: 3/5
Action is + ... up: true ... ubc1: 4/5
Action is + ... up: true ... ubc1: 5/5
Action is + ... up: false ... ubc1: 5/5
Action is - ... down: true ... ubc1: 4/5
Action is - ... down: true ... ubc1: 3/5
Action is - ... down: true ... ubc1: 2/5
Action is + ... up: true ... ubc1: 3/5
Action is + ... up: true ... ubc1: 4/5
Action is + ... up: true ... ubc1: 5/5

Creating ubc2 with a value one more than ubc1's value and a limit twice that of ubc1's limit
Initially: ubc2: 6/10
Bumping ubc2 up to its limit
After an up: ubc2: 7/10
After an up: ubc2: 8/10
After an up: ubc2: 9/10
After an up: ubc2: 10/10
... and now down to ubc1's value
After a down: ubc2: 9/10
After a down: ubc2: 8/10
After a down: ubc2: 7/10
After a down: ubc2: 6/10
After a down: ubc2: 5/10

What's the Point of This Lab?

Lab 1.3 — An RGB Color Class (Color)

Write a class, named Color, that supports RGB (red-green-blue) color values. RGB color values consist of three integers values (for the red, green, and blue primary values) each in the range of 0 … 255, with 0 being an absence of the corresponding primary, and 255 being full saturation.

Being that 255 is FF in hexadecimal, colors are often saintly representing as a six digit hex value, e.g. #000000 (for black — no color), or #ff0000 (for red — full red, no green or black).

The class supports the following state and behavior:

As with the previous pair of exercises, see Lab 1.2.2 for the sample output of the illustrative app

Lab 1.2.2 — An RGB Color App Class (ColorApp))

Write the app class for Lab 1.2.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?

color.data

0 0 0
0 0 255
0 255 0
0 255 255
255 0 0 
255 0 255
255 255 0
255 255 255
10 20 30
Sample Test Run

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

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

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

What's the Point of This Lab?