Java代写:ITP265 Accomplishment

使用Kaggle平台的数据集,实现一个简单的问答查询类的应用程序。

Kaggle

Assignment Specification

In this assignment, we will be practicing with arrays, enums, and object oriented programming while exploring a dataset with 479 records of African-Americans breaking the color barrier across a wide range of topics.

This data is from Kaggle’s Tidy Tuesday Week 24 and is compiled from this Wikipedia page. It is a celebration of Black Lives, their achievements, and many of their battles against racism across their lives. This is in emphasis that Black Lives Matter and we’re focusing on a celebration of these lives.

See also https://www.kaggle.com/jessemostipak/african-american-achievements/data?select=firsts.csv

Setup new Eclipse Java project 04HW_itp265_username

Instructions

In this assignment you will create an Accomplishment class that will represent one piece of data from the dataset, and all the Accomplishment data will be stored in an array of data inside AccomplishmentProgram . I will provide the code to read data from the file into an array of Strings, but in this assignment, it will be your responsibility to parse each String from the array into the components needed to form an Accomplishment. To ensure ease of data access and consistent representation, we will use an enum to represent the Category attribute.

Once the dataset is successfully entered into the program, we will build an enum of Menu options to allow a user of the program to explore (and learn from) the data.

Details

Step 0

Put the new version of Helper and the tabbed-delimited txt data file into your Java project.

The new attached version of Helper adds two functions (hence they are static) for this assignment, printLongTextWithBreaks, and readFile to help print long strings nicely to console, and to read the contents of a file into a string array.

Step 1: Category enum

For each category that appears in the data set (Social & Jobs, Arts & Entertainment, Religion, Military, Education & Science, Law, Politics, Sports) we will create a corresponding enum value with a String description.

In addition, add some static helper functions that will allow us to manipulate the enum values more easily within our program:

  • getCategoryFromDescription: given the String description, return the matching Category enum;
  • getCategoryByNum: given the corresponding index of enum value, return the matching Category
  • getCategoryOptions: return a String that represents a “menu” of each descriptions in the enum
  • getNumOptions: get the total number of enum values stored (the length of the array)
  • toString(): return the description instead of the enum value.

Step 2: Accomplishment class

Plain Old Java Object (POJO) to group together all the data that make up one accomplishment from the dataset. We will have a constructor, getters, and a toString for this class. the toString should return a nicely formatted String and not just be auto-generated.

Step 3: AccomplishmentProgram and Menu enum

This is the heart of the assignment, and will be used to help explore the dataset, but also practice OOP skills of breaking up code and using an enum to allow flexibility for dealing with menus of options. This class will maintain an instance variable of its “database” (array of Accomplishments).

First, you will use Helper to initialize the database (array of Accomplishments) within your program. I recommend calling a helper method from the constructor called initializeData().

More details about initializing data:

Please note that the array of Strings returned from Helper will include the header in spot 0, which your program will ignore.

Each String in the array will have tab-separated data in this order:

year\\taccomplishment\\tperson\\tgender\\tcategory

You will use a Scanner object to parse each String into the components and convert the data as needed to create the Accomplishment which you will place in your “database” (the array of Accomplishments) (Note: year will be an int, gender will need to be converted to a boolean based on the presence of the word “female” in the gender field, and Category will be set to the corresponding enum based on matching the description.)

Once the data has been read in, I recommend printing out the entire array and making sure your data is as expected before moving on.

Your program must have a Menu of options (an enum). Your options do not have to be the same as mine, but you should at least include the choice to print all facts, a quiz feature, and some way to explore subsets of the data (view/print or make additional arrays).
sample menu

***** Menu *****
0: Print all 479 facts
1: Quiz Game: Guess the year this first happened
2: Print all female accomplishments
3: Print all male accomplishments
4: Print accomplishments by category
5: Quit
**********************************************

Quiz Feature

Randomly pick 10 different accomplishments and quiz the user to guess the year (within 5 years either direction) that the accomplishment occurred. My question was in the form “In what year did “ + accomplishment.getPerson() + “ become the “ + accomplishment.getAccomplishment(); and got the year answer from the user, feedback and points were given for perfect and close answers, and just feedback for incorrect answers. When the quiz finished, the score (num correct / 10) is displayed for the user.

Data exploration

Pick at least 2 different ways of exploring the data based on how the data is stored (by gender, by category, by year range, by a certain name or keyword, etc). Include a menu option to select the exploration of data and print the results of exploration. Use may want to use helper methods to filter and print the data to a smaller array based on the filter selected.

Optional Ideas (You can get credit for one of the two, up to 5 bonus points)

  1. Instead of having the quiz pull from all 479 pieces of data, allow the user to do a quiz based on a subset of data. (For example, quiz on only females, only certain categories, or events in a limited set of years.) Try to do this in a way that minimizes duplication of code across the entire program, which probably involves creating partially filled arrays of data that can be used in the program.
  2. Do a popup version of the quiz using JOptionPane

Style Notes for all Assignments

  • Be sure to comment and properly indent your code.You should have the beginning program comment that appears on all code in this class as well as comments before public methods.
  • If you submit a code file that is not reasonably indented, you will have points deducted. Likewise, you will lose points if your variable names are not meaningful. Make sure you use variable names that correspond to what you are actually storing in the variables.
  • Keep your methods short. Have well-structured methods that are no longer than a normal screen’s length.

Sample Output

Intro + print all facts

INTRO:
This data is from Kaggle's Tidy Tuesday Week 24 and comes from Wikipedia. It is a celebration of Black Lives, their achievements, and many of their battles against racism across their lives.
This is in emphasis that Black Lives Matter and we're focusing on a celebration of these lives.

INFO

The firsts.csv dataset has 479 records of African-Americans breaking the color barrier across a wide range of topics. The raw text has been adapted from Wikipedia to highlight:
** The year of the event
** The role/action/topic
** The person or people involved
** Addition of gender
** A category of topics
Original data set can be found here: [https://www.kaggle.com/jessemostipak/african-american-achievements/]

***** Menu *****
0: Print all 479 facts
1: Quiz Game: Guess the year this first happened
2: Print all female accomplishments
3: Print all male accomplishments
4: Print accomplishments by category
5: Quit
**********************************************
>
0
1 : 1738 was the year of the First free African-American community By: Gracia Real de Santa Teresa de Mose (later named Fort Mose) in Florida
2 : 1760 was the year of the First known African-American published author By: Jupiter Hammon (poem An Evening Thought(Female)
3 : 1768 was the year of the First known African-American to be elected to public office By: "Wentworth Cheswell, town constable in Newmarket, New Hampshire.[5]"
... lots of lines missing ...
479 : 2019 was the year of the First African-American full-time curator at the Guggenheim By: Ashley James.[255]
***** Menu *****
0: Print all 479 facts
1: Quiz Game: Guess the year this first happened
2: Print all female accomplishments
3: Print all male accomplishments
4: Print accomplishments by category
5: Quit
**********************************************
***** Menu *****
0: Print all 479 facts
1: Quiz Game: Guess the year this first happened
2: Print all female accomplishments
3: Print all male accomplishments
4: Print accomplishments by category
5: Quit
**********************************************
>
Choose the category you want to explore:
  0: Social & Jobs
  1: Arts & Entertainment
  2: Religion
  3: Military
  4: Education & Science
  5: Law
  6: Politics
  7: Sports
  8: Unknown
>
2
1 : 1773 was the year of the First separate African-American church By: "Silver Bluff Baptist Church, Aiken County, South Carolina[7][8][Note 1]"
2 : 1785 was the year of the First African-American ordained as a Christian minister in the United States By: "Rev. Lemuel Haynes. He was ordained in the Congregational Church, which became the United Church of Christ[11]"
3 : 1793 was the year of the First African Methodist Episcopal (AME) Church founded By: "Mother Bethel A.M.E. Church, Philadelphia, Pennsylvania was founded by Richard Allen"
4 : 1794 was the year of the First African Episcopal Church established By: "Absalom Jones founded African Episcopal Church of St. Thomas, Philadelphia, Pennsylvania"(Female)
5 : 1804 was the year of the First African-American ordained as an Episcopal priest By: "Absalom Jones in Philadelphia, Pennsylvania[12]"
6 : 1807 was the year of the First African-American Presbyterian Church in America By: "First African Presbyterian Church founded in Philadelphia, Pennsylvania by John Gloucester a former slave."
7 : 1816 was the year of the First fully independent African-American denomination By: "African Methodist Episcopal Church (AME), based in Philadelphia, Pennsylvania and mid-Atlantic states"
8 : 1851 was the year of the First African-American member of the Society of Jesus (Jesuits) By: Patrick Francis Healy[21] (See also
9 : 1854 was the year of the First African-American Roman Catholic priest By: James Augustine Healy[24] (see 1875 and 1886)
10 : 1875 was the year of the First African-American Roman Catholic bishop By: "Bishop James Augustine Healy, of Portland, Maine.[24] (See also"
11 : 1920 was the year of the First African-American bishops of the Methodist Episcopal Church By: Robert Elijah Jones and Matthew Wesley Clair.[94]
12 : 1944 was the year of the First African-American to co-pastor with a white minister at the first interracial church By: "Dr. Howard Thurman with Dr. Alfred Fisk, Church for the Fellowship of All Peoples, San Francisco[relevant? - discuss]"
13 : 1970 was the year of the First African-American to head an Episcopal diocese By: "John Melville Burgess, diocesan bishop of Massachusetts[192]"
14 : 1977 was the year of the First African-American woman to be ordained as an Episcopal priest By: Pauli Murray.[205](Female)
15 : 1979 was the year of the "First African-American woman ordained in the Lutheran Church in America (LCA), the largest of three denominations that later combined to form the Evangelical Lutheran Church in America" By: Earlean Miller[207](Female)
16 : 1989 was the year of the "First African-American woman, and first woman, ordained bishop in the Episcopal Church" By: Barbara Clementine Harris(Female)
17 : 2001 was the year of the First African-American president of the United States Conference of Catholic Bishops By: The Most Reverend Wilton Daniel Gregory
18 : 2006 was the year of the First African-American woman to receive Dharma transmission in Zen Buddhism By: Merle Kodo Boyd[222](Female)
19 : 2009 was the year of the First African-American woman rabbi By: Alysa Stanton(Female)
20 : 2011 was the year of the First African-American admitted to the Reconstructionist Rabbinical College By: Sandra Lawson[230][231]
21 : 2015 was the year of the First African-American elected as presiding bishop of the Episcopal Church By: Bishop Michael Curry[246]
***** Menu *****
0: Print all 479 facts
1: Quiz Game: Guess the year this first happened
2: Print all female accomplishments
3: Print all male accomplishments
4: Print accomplishments by category
5: Quit
**********************************************

quiz game

***********************************************************************************************
Welcome to my quiz. I tell you 10 accomplishments by an African-American person and you guess the year it occurred
***********************************************************************************************
Question 1: In what year did Kehinde Wiley become the First African-American artist commissioned for US president portrait to be displayed in the Smithsonian?
>
1933
--> Sorry, First African-American artist commissioned for US president portrait to be displayed in the Smithsonian happened in 2018
Question 2: In what year did Lloyd Austin[233] become the First African-American Combatant Commander of United States Central Command?
>
1967
--> Sorry, First African-American Combatant Commander of United States Central Command happened in 2012
Question 3: In what year did Michelle Obama become the First African-American First Lady of the United States?
>
2008
--> Good job (you were within 5 years of the answer)!
First African-American First Lady of the United States happened in 2009
... questions omitted here ...
Question 10: In what year did Bishop Daniel Payne (Wilberforce University)[30] become the First African-American president of a college?
>
1944
--> Sorry, First African-American president of a college happened in 1863
Thanks for taking the quiz, you got: 3/10