Académique Documents
Professionnel Documents
Culture Documents
http://solutionzip.com/downloads/lab3-bitmap-test/
Goals
1) Be able to work with individual bits in java.
2) Understand the serializable interface.
3) Understand the comparable interface.
4) Answer questions about a general-purpose class to be developed.
5) Understand the use of a driver program for glass box debugging.
6) Develop a program that can grade true/false tests.
Description
1) The first step is to develop a general-purpose class that will be able to perform operations on strings of bits. The
class API follows:
public class BitMap implements Comparable, Serializable
{ public static final int BITSIZE = 64;
private long bitString;
public BitMap() // Three constructors.
public BitMap(String s)
throws IndexOutOfBoundsException,ArithmeticException
public BitMap(boolean[] bits)
throws IndexOutOfBoundsException
2) The next step is to debug the class that was created in the above step. I provide the program driver.java for this
purpose; its code is at the bottom of this document. Dont modify this program in any way; use it to test your class. It
contains a menu that has options to test every option. Once the testing is complete, BitMap, could be used as a
general tool for working with bits and could be used in many programs.
3) Use notepad to create a file of true/false questions.
4) Now write a program (CreateTest.java) that constructs a true/false test. This program reads the file created in step
3 to ask a series of true false questions and record the resulting answers in a bit map object. Be sure to use a
fileChooser to ask the user for the file name. Make sure you catch all exceptions (programs should never crash).
You can use your TextReader from the previous lab as the starting point for this program. Better yet, just instantiate a
BufferedReader and read lines from the text file till you encounter a null line.
Make sure to have at least 25 questions in your test. When the test is completed, the program should use an
ObjectOutputStream to write one record (the BitMap object) to a sequential binary file. That is why the BitMap class
must have implements serializable on its signature line. Name the disk file ans.bin. Hopefully, youll know the
answers to your questions so the answer file will represent a perfect score.
5) Finally, create a new application (Test.java). You can copy and paste the program that you just wrote (and save it
as Test.java), and then modify it appropriately. This program should read the answer file (using an
ObjectInputStream) and compare the answers given by someone taking the test to ans.bin. Display the score earned
by the test taker.
6) Answer the synthesis questions in an rtf or doc file (answers.rtf or answers.doc). Type your name and the lab
number on this file and include the questions with the answers.
7) Zip your Eclipse project along with the synthesis answers and email to harveyd@sou.edu.
Driver.java
// Driver program to test the BitMap class.
import java.io.*;
public class Driver
{ static BitMap bitMap[];
static BufferedReader in = new BufferedReader
(new InputStreamReader(System.in));
// Method to start the driver program.
public static void main(String[] args)
{ int bit, map, option;
BitMap bitMap = new BitMap();
BitMap secondMap;
Download:
http://solutionzip.com/downloads/lab3-bitmap-test/