Colorado State University

Recitation R16 - File Formats
Fall 2013

CS160: Foundations in Programming


The purpose of this lab is to:

Phase 1

  1. Make a new project in Eclipse called R16, with a main method.
  2. Set up the Run Configurations so that R16 has the program arguments:

    inputFile.txt

  3. Create methods with the following signatures:

    static double computeAreaCircle( double radius ){ }

    static double computeCircumferenceCircle( double radius ){ }

    static double computeAreaRectangle( double height, double width ){ }

    static double computePerimeterRectangle( double height, double width ){ }

    static double computeAreaTriangle( double height, double base ){ }

    static void readFile( String inputFile ){ }


  4. Within the main method, call the readFile method with the first command line argument (args[0]).

Phase 2

Implement all of the methods shown above except for the readFile method. When in need of pi, it is acceptable to use Math.PI
Test each method using your own data values.


Phase 3

Now design a file format that specifies a keyword for a shape on each line, followed by the value(s) needed for that shape. The file format must allow a user to define any number of the following shapes in any order: Implement the readFile method such that it can read and parse the file, discarding the keywords and calling all appropriate methods for that shape. The keywords in the input file are chosen by you. Next print the results of each computation to the console, including the shape name, method name, input values, and calculated value.
Show your R16.java program to the TA for grading and submit to RamCT to get credit for this lab.

© 2013 CS160 Colorado State University. All Rights Reserved.