Machine Problem 1, due Sept 28

Part of the homework for CS:2820, Fall 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  • Consider the posted solution to Homework 3 Problem 3 as a starting point.

    Write a Java program, in file LogicCircuit.java that can be run as follows to read data from a file called f (presuming that this file exists):

    [HawkID@serv15 project]$ java LogicCircuit f
    

    When your program is run, it should read a description of a logic circuit written in the notation of Homework 3 Problem 3 part c, and built a data structure of objects using the basic object classes outlined in Homework 3 Problem 3 parts a and b. Having created this data structure, the program should print out a description of the circuit it created, in exactly the same notation as is used in the input file, but to the standard output stream.

    Error messages: Your program should report any errors it detects: If it can't open the input file, lines that don't start with wire or gate, missing fields on a line, wires that reference non-existant gates, etc. Your error messages should be helpful, but need not be elaborate. Consider this input file:

    gate perhaps b x
    gate not     a 9.0
      wire b c d   1.5
      wire a a in  1.0000
    

    Your program might report the following error messages as a result of trying to read this file:

    Error: perhaps, no such type of gate
    Error: x, number expected
    Error: b, no such gate
    Error: c, no such gate
    

    The complaint that b is not the name of a gate is because input lines (gate or wire definitions) that contain errors should be ignored, and the definition of b contained two errors. The error complaining about x is optional. Your program may report this error or it may ignore it because the previous error on the same input line caused the remainder of the line to be skipped.

    Output: After reporting any errors, your program should traverse the data structures it has built to produce an output file describing the circuit. This file should conform to the same rules as the input file. For example, after reading the input file given above, it might output the following:

    gate not a 9.0
    wire a a in 1.0
    

    Note that the default behavior of the scanner was to skip as many blanks as needed to get to the next item, but the output only put one blank. Note that the output prints floating-point values in a standard compact form, without any leading or trailing zeros that might have been used in the input. And note that there is no hint of any parts of the logic circuit that contained errors.

    Types of gates: Your code should support the following types of gates:

    and with 2 intputs, in1 and in2
    or with 2 intputs, in1 and in2
    not with 1 intput, in

    Of course, there are other gate types, but these suffice for this assignment.

    Grading criteria: No credit will be given to programs that do not represent a substantial attempt at meeting the requirements of this assignment. Your program must:

    Note that the requirements for header comments in the file header are absolute. Your name must appear in the form that it appears on your ID card. The TA will not waste his time doing detective work to attempt to figure out who submitted what code.

    Submission: Your solution should consist of a single file, with one public method, main. (Later, we will chop the file into smaller more managable pieces, as it grows.)

    To submit your solution, make sure it is in a file called LogicCircuit.java (this requires that the main method be in a class called LogicCircuit. This must be in the current directory. Then, follow the following dialogue with the Linux shell (what you type is given in boldface):

    [HawkID@serv16 ~/project]$ submit LogicCircuit.java
    Course (22C:016 would be c_016): CS2820
    Possible submit directories for /group/submit/CS2820 are:
    
    section1/mp1
    section1/mp2
    section2/mp1
    section2/mp2
    
    Choice:   section1/mp1
    LogicCircuit.java
    * File/directory LogicCircuit.java has been 
    *  copied to /group/submit/CS2820/section1/mp1/LogicCircuit.java.HawkID.
    [HawkID@serv16 ~/project]$ 
    

    The final output ("File ... copied to ...") is your confirmation that the file was successfully submitted. If you make multiple submissions, only the last one will be counted. The date of your final submission must be before midnight on the due date.

    Note that the submit program doesn't know what section you are in. Please give your section (either section1 or section2). You must know what section you are enrolled in!