Assignment 5

Due: 4:00 PM on Wednesday, March 29, 2000


Question #1

Write a Java program bitplay.java that accepts up to 10 integers from a user, stores these numbers in an int array, extracts the first 8 bits from each stored integer, interprets these 8-bit chunks as characters, and prints the resulting string. Input of numbers is terminated either by entering 10 numbers or by entering -1 (see sample output below). For example, given the input numbers 65, 66, 67, and 68, the resulting string is "ABCD".

Your program's output must have the following format:


Question #2

Write a Java program pattern.java that accepts a string of non-blank characters from the user and determines if the following pattern occurs within that string: Examples of this pattern are acd, abbcd, and abccd. Sample strings including this pattern are Your program's output must have the following format:

Question #3

Write a Java program stacktest.java that implements a class Stack for the integer stack abstract data type as an int array of length MAX_STACK_DEPTH, where MAX_STACK_DEPTH is a constant (for the purposes of this assignment, MAX_STACK_DEPTH will be set to 3). All stack variables will be private to class Stack. Class Stack should have the following methods: The last two methods access an operation status variable associated with a stack object. This variable can have three values: Attempts to push an element on a full stack cause the operation status to be set to 2; attempts to pop or read the top element of an empty stack cause the operation status to be set to 1; all other operations cause the operation status to be set to 0. For printing error messages, you may also find it useful to store a code indicating the most recently requested operation, e.g., Finally, define a class stacktest and write a main method for this class that takes stack-manipulation commands from a user (see sample output below for command format), performs these commands using the methods in class Stack described above, and displays the results. Your program will initialize the stack before processing the first of these commands. The list of commands is terminated by the command end.

Your program's output must have the following format:

Hints

For question (a), you should use the Java class String to store the created string (and one should perhaps build this string by starting with an empty string and concatenating characters to it as necessary); using character arrays ios possible but could cause unexpected problems. Modulo differences in syntax and the necessity to define classes, your code for assignment #1 can be adapted very easily to solve all questions in this assignment.

Compiling and Running

See appropriate web pages for instructions on compiling and running java programs.

Testing Your Programs

Test suites for test-asn have been provided for each question and can be accessed by using "5a", "5b", or "5c" as the appropriate code in the call to test-asn, e.g.,

Please note that before you run test-asn, you must compile your Java files using javac as described above. Those wishing to see the complete test specification files should consult files a05a.t, a05b.t, and a05c.t in subdirectories test5a, test5b, and test5c, respectively, of directory /local/share/ASSIGNMENTS/cs3710.

Submitting Your Programs

Please submit your program files bitplay.java, pattern.java, and stacktest.java using system program submit-assignment and pass in hardcopies of these files to me by the assignment due date.


Additional Notes:


This page is adapted from that for CS3710 (Winter 1999) created by Mike Rendell.


Created: March 7, 2000
Last Modified: March 7, 2000