Colorado State University Logo | CS 163/4: Java Programming (CS 1) Colorado State University Logo | CS 163/4: Java Programming (CS 1)
CS 163/4: Java Programming (CS 1)
Computer Science

Practical Four - STEM University Demographics - Part 2

“Living with your code” is an essential skill for any programmer. That is because we rarely work on something one time, and never come back to it. Instead, we are constantly coming back to a project and extending it. Future classes, will have you do that, and a few classes even have you work on the same project every semester. If you think about it, that is true for nearly every program you use. What version of the program is your operating system? Those are all iteration cycles of code the programmers had to “live with”.

For this practical, we will be going back to the code for Practical 3 and building upon it. You will need to make sure Practical 3 is working (mostly - the main changes completely), to be successful for this practical, so it would be good to work on that before continuing forward. In practical 3, you created a program that prompted the client for information, and printed out the statistics on the screen, for this one, you will take in program arguments and either print to the screen or write out an HTML file with the information.

You will learn about:

  • File Writing
  • Program Arguments
  • Building on past code

Scenario

Institutional Research liked the work you did on the last project, but they would like you to adapt it to be a program that runs based on the command line arguments pass into it. The goal would be to have the option to either display the data the screen, or more importantly, write out an HTML file for the data statistics to be stored and pulled up in the future.

Requirements

The program will be entirely based using the command line (no direct client interaction) If two arguments are passed into the program when it is executed, then it will print out just like the last project with the assumption the two arguments match the file to load, and the term to display. For example:

> java Main STEM_Diversity_Data.csv 202110

Would print out:

Natural Sciences:        Major     Male       Female
                    Psychology     23.70%     76.30%
                       Zoology     17.61%     82.39%
                  Data Science     70.27%     29.73%
            Biological Science     27.71%     72.29%
              Computer Science     83.61%     16.39%
                    Statistics     65.08%     34.92%
                     Chemistry     44.53%     55.47%
                  Biochemistry     40.07%     59.93%
                   Mathematics     54.67%     45.33%
  Applied Computing Technology     85.07%     14.93%
                       Physics     80.56%     19.44%
              Natural Sciences     41.67%     58.33%

Engineering:             Major     Male       Female
Biomedical Engineering with ME     53.08%     46.92%
Biomedical Engineering with EE     66.67%     33.33%
        Mechanical Engineering     87.55%     12.45%
Chemical & Biological Engineer     63.49%     36.51%
        Electrical Engineering     88.89%     11.11%
          Computer Engineering     91.53%      8.47%
             Civil Engineering     75.98%     24.02%
     Environmental Engineering     53.26%     46.74%
Biomedical Engineering with CB     42.47%     57.53%
    Engrg Sci and Intl Studies     42.86%     57.14%
           Engineering Science     71.43%     28.57%
Biomedical Engineering with EL     66.67%     33.33%
       Engineering Open Option    100.00%      0.00%

However, if they put in three command line arguments, the program will then write out an HTML file. For example,

> java Main STEM_Diversity_Data.csv 202110 Spring21.html

would write out to a file, using HTML markup. Here is the output for Spring21.html. Note that you can right-click on the page and view page source.

The HTML file format will include a header stating STEM Demographics Report, followed by the friendly name of the term. It will then have an HTML table for each college. It does not need to use stylesheets (html formatting options), so it will look fairly plain.

They look forward to seeing the update, so they can help generate webpages for displaying university information. Random tidbit of information, here is the actual IR reporting website.

Coding Specifications

For grading purposes, we are asking you to follow the following format. You will notice, most the files are the same as Practical 3 with the addition of two files. While Main.java looks the same, most of it is an entire rewrite, so it probably just makes the most sense to copy CollegeDemographics.java, CSVReader.java, Data.java, and MajorDemographics.java from Practical 3, and start fresh with Main.java, Tag.java, and DemographicDataWriter.java.

Full breakdown for the required methods can be found in the javadoc. Make sure to map out how the files are interacting, and work with a TA early.

Seven classes will be made and submitted:

  • Main.java - the main driver of the program, focuses on reading the program arguments.
  • CSVReader - Helps you read a Comma Separated Value file by using a Scanner to grab each line, and String.split to break up the lines into String arrays. NO CHANGES.
  • Data - Uses CSVReader to read the data, and keeps track of the CollegeDemographics as an array of two elements. Methods added to grab the stored data.
  • CollegeDemographics - Keeps track of the various MajorDemographics (majors) in a single College. Builds a String value of the table to print out unique to each college. Added the printing of HTML formatted Strings, for the “table” objects
  • MajorDemographics - Keeps the total gender counts for a major, so percents can be easily calculated when asked. Added the printing of HTML formatted Strings for the “row” data for the tables.
  • Tag - Contains all static methods will take a String, and return the String with HTML markup tags.
  • DemographiicDataWriter - Either writes the Data values out to the screen or writes out to an HTML file.

Like practical 3, you wll also be asked to write tests in separate main methods for your classes, and you will want to add onto your past tests as you implement additional methods. It is always important to test thoroughly before submitting.

Where to Start?

Here are some hints on how to start

  1. Make sure your Practical 3 code is working!
  2. Write down on paper what you want to do, and what changes need to be made.
    • do you understand the specifications? If not, ask on MS Teams!
    • Draw out the program flow. Can you picture how the program will work?
      The picture doesn’t have to be clear, but seeing a picture can help you see how classes interact.
    • Sometimes it helps to develop empty classes, with comments on what to do
      in your own words in each class (you can even turn them in, to get your “does it compile” point)
  3. Look at the problems, divide and conquer.
    • What do you know how to do?
    • What is ‘self-contained’, meaning you can write it without dependence on the other classes?
    • Tag - Is a great place to start on this one. It is 100% self-contained, and really only formatting Strings. Make sure to write tests.
    • Other Class Updates - Add your new methods to implement in your current classes. Make sure to test the new methods, and make sure you didn’t “break” anything with adding them.
  4. A quick reminder, when working with most IDEs (IntelliJ and Eclipse), the file path reads from the root project directory (not src), so you should place your CSV file in the project root.
  5. Here is IntelliJ’s howto on program arguments, but it is a more than you need (complex). Here is another one by Baeldung.

The biggest problem when starting with code is getting lost in a “where to start mental loop”. Take your time to think it through, but don’t take too long. You should start writing code, even if the code is simply to help you figure out how to do something (read a file for example, or print out your program arguments). That type of “warm up” will then get your brain working on how to work on the entire problem. Basically, don’t stare at the problem and do nothing. It doesn’t hurt to try, fail, try again.

Learning HTML

If you haven’t learned HTML, you can go to W3Schools or many other websites out there that teach it. In particular, you will need to learn about the table tag. To save time, don’t learn about all of the HTML world now! You probably don’t need to spend five minutes on it.

Overall, HTML is a way to “markup” (Hyper Text Markup Language) text files. It is not a programming language by itself, but just a way to add structure to a text document. Your browser then displays that information. If you right-click and “view page source” for this webpage, you can see (more complex) html.

For this assignment, we will be making use of the following tags:

<table>
<caption>Table caption</caption>
<thead>
 <tr>
  <th>Table head</th>
 </tr>
</thead>
<tbody>
 <tr> 
  <td>Table element</td>
 </tr>
</tbody>
</table>

Additionally

<h1></h1>
<h2></h2>
<h3></h3>
<h4></h4>

Remember, you don’t need to be an expert in HTML, but it would be wise to learn more of it.

Going Further
You explored two major areas in computer science with this practical. Data Visualization / Human Centered Computing and Big Data. While admittedly, the data we provided is not big data, it has a lot of potential to grow into very large datasets. Going beyond this course, we have two concentrations in the department you may want to look at. If you enjoyed the idea of how to display and interact with the data, HCC would be something good to look with a focus on stats. If you really like getting and figuring out how to deal with extremely large data sets, Systems is important in how you do that. You can learn about the research labs at CSU, and many undergrads are encouraged to get involved in research.

Computer Science Department

279 Computer Science Building
1100 Centre Avenue
Fort Collins, CO 80523
Phone: (970) 491-5792
Fax: (970) 491-2466

CS 163/4: Java Programming (CS 1)

Computer Programming in Java: Topics include variables, assignment, expressions, operators, booleans, conditionals, characters and strings, control loops, arrays, objects and classes, file input/output, interfaces, recursion, inheritance, and sorting.