Java Project: Gender Representation

The United Nations (UN) has set forth 17 goals for sustainable development. Goal 5 is designed to “Achieve gender equality and empower all women and girls.” In many parts of the world, females are at a disadvantage socially and economically due to long-standing practices and other factors. By working to eliminate discriminatory policies and practices, eradicate violence against women, and enhancing educational opportunities, nations can “level the playing field” and empower women to take control of their economic and social destiny.

In this project, we will consider one indicator of gender equality: gender representation in the legislative process.

Gender Equality

The term gender equality means many things, but in a nutshell it means that members of both sexes (male and female) have access to the same resources, opportunities, and basic rights. This equality enables individuals of both genders to realize their potential and enjoy the basic elements of modern life, such as life, liberty, and property. The following short video captures this idea:

Gender equality can be facilitated by ending discriminatory polices and practices against women, among other things. In many parts of the world women are limited in their access to such things as health care, education, and basic property rights. Some women are forced into marriage at a young age, and violence against women  – including human trafficking, sanctioned domestic violence, and female gender mutilation – still occurs. While many first-world nations have made great strides in gender equality, many less developed nations still have a long way to go.

Gender Representation

One basic measure of gender equality is participation in public affairs. We can examine the level of male and female participation in voting and political office as compared to the percentage of the overall population; if the levels are in alignment, we have a good statistical indicator that both genders have equal participation in political affairs and policy-making. Keep in mind, however, that there are a number of other factors that can impact the proportion of participation and political representation – the quality of candidates, among other things.

According to the United Nations, the Nordic countries (e.g. Sweden, Finland, Norway) have the highest percentage of female legislators at the national level (42.5%) as of 2019. In the United States, female participation is a mixed bag, and varies by state. As of 2019, there are 102 (23.4%) females in the House of Representatives and 25 U.S. Senators (25.0%). As a nation, females comprise approximately 50.8% of the population, as of 2018, according to the United States Census Bureau.

Where Can I Learn More?

Here are some links to additional information on this topic:

In this program, we will utilize Java arrays and methods to examine the distribution males and females in the 50 state legislatures.


Java Project: Gender and State Legislature Representation

This project will provide you with an introduction to the fundamentals of one-dimensional arrays and file I/O in Java. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Develop code to read data from a text file and write data in a prescribed format to a text file.
  • Write code that conforms to a programming style specified by the instructor.
  • Select and implement the appropriate control structure(s) for this problem.
  • Decompose the given problem into a sequence of single-purpose methods that are highly cohesive and loosely coupled.
  • Declare, define, and initialize one-dimensional arrays of a fixed size.
  • Demonstrate the ability to read from and write to an arbitrary array element using array indices.
  • Demonstrate an ability to process the entire array, one element at a time, performing both read and write operations.

As you write your code, be sure to properly document your code. Consult the Java Coding Guidelines document (provided by the instructor) for style expectations. Well-written code is easier to debug, easier to maintain over time, and easier to extend as new requirements arise.

Exercise #1: Let’s begin creating a simple program to analyze data on the gender distribution of state legislatures. Create a class file called GenderRepresentation.java in your Java development environment. Add a new method to the class named inputFilename. This method will prompt the user for a filename, input the filename, and return the filename to themain method. Next, add code to your main method to call inputFilename, store the return value, and echo-print it back to user. Make sure your program permits entry of a string with spaces! Use the following test case as a trial run:

Test Case #1

Please enter the name of a file: sample.txt
You entered the filename 'sample.txt'.

Exercise #2: Next, we will add code to open the file selected by the user. Add code to your  main method to open the user-specified file and check to see if the “open” worked. If it did not, inform the user. If the “open” worked, output a simple message to the user indicating that the file is now open. As a final step, close the file and inform the user it is closed.

Make sure that everything compiles and builds. Run the program. Make sure your output matches that shown in the following test case; please note that it assumes a simple file named sample.txt exists in the same folder:

Test Case #2

Please enter the name of a file: sample.txt 
You entered the filename 'sample.txt'.

File 'sample.txt' is now open.
File 'sample.txt' is now closed.

Assuming the sample.txt file does NOT exist in the folder, you should see the following output:

Test Case #3

Please enter the name of a file: sample.txt 
You entered the filename 'sample.txt'.

ERROR: File 'sample.txt' is NOT open.

Make sure your program works for both of these tests.

Exercise #3: Now we will read a file of data records into our program. The data file we will read consists of the following fields, in this order:

Field Type Meaning
State String The state abbreviation, in caps
Total Women int The total number of women in the state legislature
Total Legislators int The total number of people in the state legislature

Add some code to the main method to create three one-dimensional arrays (one String, two int, all of size 50). These arrays will store the data read from the data file. They will be parallel arrays, meaning the first element in each array is for the first record, the second element in each array is for the second record, and so on.

Create another method named readFile to read the user-specified data file,  one field at a time, until the end-of-file (EOF) has been encountered. The user-specified file is your data file for the program; it includes three values per record (state, total women in the legislature, total number of legislators). Each record is one a single line, with the three values separated by spaces. Store each field of the three-part “record” into the appropriate array. Once the EOF has been encountered, return the number of “records” input to the calling method. Add code to call readFile from your main method, and output the value returned to the screen.

For testing, download the file named gender_data.txt from Canvas, placing it into the same folder as your code. Make sure that everything compiles and builds. Run the application, and test your code against the following test case:

Test Case #4

Please enter the name of a file: gender_data.txt 
You entered the filename 'gender_data.txt'.

File 'gender_data.txt' is now open.
50 record(s) have been read from the file.
File 'gender_data.txt' is now closed.

Once you see the output above, continue on to the next exercise.

Exercise #4: Create a fourth array of size 50 (type: double) in your main method. Add a new method named computePercentage to fill this array with the percent of women in each state legislature, using the concept of parallel arrays. Add code to call computePercentage from your main method

Exercise #5: Add a method named outputReport to output the contents of your arrays as a table, complete with headers. For purposes of the table, you will have four columns – state, total women in the legislature, total number of legislators, percent of women in the legislature.  Add code to call outputReport from your main method. Make sure that everything compiles and builds. Run the program, and test your code against the following abbreviated test case:

Test Case #4

Please enter the name of a file: gender_data.txt
You entered the filename 'gender_data.txt'.

File 'gender_data.txt' is now open.
50 record(s) have been read from the file.

STATE      LEGISLATORS    WOMEN   PERCENT WOMEN
-----      -----------    -----   -------------
 AL           140           22       15.71
 AK            60           23       38.33
 AZ            90           35       38.89
 AR           135           32       23.70
 CA           120           37       30.83
 ...
 WI           132           36       27.27
 WY            90           14       15.56

File 'gender_data.txt' is now closed.

Once you see the output above, continue on to the next exercise.

Exercise #6: As a final step, we will add code to learn some simple information from the file input data. Add one or more methods to compute….

  • The state with the largest percentage of women legislators
  • The state with the smallest percentage of women legislators

Add code to call these method(s) from your main method. Make sure that everything compiles and builds. Run the program, and test your code against the following test case; your prompts and error messages should appear exactly as shown here:

Test Case #5

Please enter the name of a file: gender_data.txt
You entered the filename 'gender_data.txt'.

File 'gender_data.txt' is now open.
50 record(s) have been read from the file.

STATE      LEGISLATORS    WOMEN   PERCENT WOMEN
-----      -----------    -----   -------------
 AL           140           22       15.71
 AK            60           23       38.33
 AZ            90           35       38.89
 AR           135           32       23.70
 CA           120           37       30.83
 ...
 WI           132           36       27.27
 WY            90           14       15.56

State with largest percentage: NV
State with smallest percentage: MS

File 'gender_data.txt' is now closed.

Your program is now complete.

Deliverables

See the instructor for submission instructions and due date(s).

Data File Source: Center for American Women and Politics, Eagleton Institute of Politics, Rutgers University.

Powered by WordPress. Designed by WooThemes

Skip to toolbar