Colorado State University

Recitation R18 - File Formats
Spring 2014

CS160: Foundations in Programming


The purpose of this lab is to:

Phase 1

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

    inputFile.txt

  3. Create methods with the following signatures:

    static double computeAreaCircle( double radius ){ }

    static double computeAreaRectangle( 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. Make a data file that has several shapes, with the types intermixed, for testing.
Show your R18.java program to the TA for grading and submit to RamCT to get credit for this lab.

© 2014 CS160 Colorado State University. All Rights Reserved.