联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> Java程序Java程序

日期:2020-11-24 08:58

PA10-B: Broadway Show Data File (20 pts)
Students:
This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns
about this content to your instructor. If you have any technical issues with the zyLab submission system,
use the Trouble with lab button at the bottom of the lab.
You have unveried
email(s). Please click on your name in the
top right corner and browse to your prole
to send another
verication
email.
14.32 PA10-B: Broadway Show Data File (20
pts)
Honor Code
THE ACADEMIC HONOR POLICY AS DISCUSSED IN CLASS AND POSTED
ON BRIGHTSPACE IS APPLICABLE TO ALL WORK YOU DO THIS FALL 2020
SEMESTER IN CS 1104.
Points and Submission
This exercise is worth 20 points. You have 10 submission attempts, so use them wisely and try
to pass all test cases before running out of submissions. Note also that you have to wait for at
least one minute before you can submit again.
Keep in mind that the score you get from zyLabs tells us how many test cases passed. The TA will
take this into account and then will manually look at your submission. They will look for any
possible deductions and incorrect style based on the grading rubric before entering your nal
score on codePost.
Problem Description
Write a program that will calculate and display statistics of Broadway shows where the data
comes from a comma-separated values (CSV) le.
We will use the reader function from the
csv module as seen in class that places the data from the CSV le
into a list that can then be
processed.
The CSV le
that will be used for this exercise is called boardway.csv and can be downloaded
below. The rst
line of the le
contains the names for each type of data stored in the subsequent
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 2/8
lines. Each of the remaining lines represents a week's worth of data for a specic
Broadway
show. The date range of the data is from 2010 to 2016. The CSV le
contains more than 10,000
lines, so it is a fairly large dataset. We will not be using all of the data available, but rather we will
be specically
interested in the following data items: month, year, name of show, attendance
totals, revenue totals, and performance totals.
For this exercise, the program should ask three things from the user: 1) what type of stats does
the user want to view, 2) the name of the show of interest, and 3) the year of interest. The type
of stats include attendance, revenue, and number of performances. Once this information is
obtained, the program should calculate the stats for the show and year of interest. This will
include stats that are separated by each month of the year and then at the end the sum of the
totals of each of the months. Once the stats has been printed, the program should terminate.
As seen in class, after the reader function in the csv module has been called and the result
stored in a variable, a loop can be used to iterate over the CSV object stored in that variable.
Also, as seen in class, in one iteration of the loop, the loop variable will contain a list representing
one of the lines of the CSV le,
where each element of the list represents the data that was
separated by commas. For example, consider the second line in the le:
"3","1/3/2010","1","2010","A Little Night Music","Walter
Kerr","Musical","7527","101","1031543","112","8"
The list that will be generated for this line will look something like the following. This represents
one line in the CSV le.
["3", "1/3/2010", "1", "2010", "A Little Night Music", "Walter
Kerr", "Musical", "7527", "101", "1031543", "112", "8"]
To access any element in the list, you can use regular numeric indices. The following are the
index values and data description in each line of the CSV le.
The ones that are bolded are of
interest in this exercise. Remember that each line represents one show's data for a particular
week.
Index Data
0 Day
1 Full date
2 Month
3 Year
4 Show name
5 Theater name
6 Show type
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 3/8
Index Data
7 Attendance
8 Percentage of capacity reached
9 Gross income (i.e., revenue)
10 Percentage potential of revenue
11 Number of performances
The example code below shows how to open the CSV le
and create the CSV object. It also uses
some of these indices listed above to access certain values. In this case, the code will print the
show names (index 4) associated to each line in broadway.csv le
that represent data for 2016
(index 3).
with open('broadway.csv') as file: # The CSV file name can be
hard-coded.
shows = csv.reader(file)
for show in shows:
# Code to skip the first line omitted.
if int(show[3]) == 2016:
print(show[4]) # Prints the show name of each line
of data.
Additional details:
You will need to search for shows that contain the text inputted by the user. That is, you
shouldn't search for an exact match. For example, as long as the show name contains
"lion king" (i.e., the text inputted by the user), include it in the stats calculation.
Note in the example code that the you will need to write the code to skip the rst
line,
because as previously stated, the rst
line contains the headers of each data element on
the subsequent lines. There are different ways to skip the rst
line, for example, you can
create a variable that you change the value of once you've reached the rst
line.
Another observation about example code: the value of show[3] had to be converted into
an integer. This is because every element of the list show will be of type string. You will
need to convert values to numeric values when needed.
As stated above, each line in the CSV le
represents weekly show data. However, you are
concerned with monthly totals. This will require adding up the data of the weeks in a
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 4/8
particular month.
As seen in the sample runs below, the rst
prompt to the user is to pick a stat type or zero
to quit. You can assume that the number that the user will enter will be an integer, but
make sure it is a number between zero and three. Continue prompting until such a value is
entered. If the user selects zero, then the program should terminate without doing any
processing.
You can expect that the user will enter a show name. Also, the year value that the user will
enter will be an integer. If no data was found for the show name and/or year inputted by
the user, the program should print No data found.
When you are developing your program, it might be better to work on a smaller sized CSV
le.
An additional CSV le
called boardway-small.csv is also available to download the
contains data for only the months of June, July, and August of 2016. This le
is provided if
you want to test using a smaller le.
None of the test cases below requires broadwaysmall.csv.
That is why in the example code above, the le
broadway.csv can be hardcoded
in your solution.
Make sure you are decomposing parts of the code that are can be used for multiple tasks
into functions. For example, the process of tabulating the totals for attendance, revenue,
and number of performances, can be done by one function. The only difference is which
element in the list will be observed. That information can be passed into the function via a
parameter. We will deduct points if your code contains redundant code that could have
been decomposed into a function. That is, if we see a section of code that is highly similar
to another section of code, then you may be deducted points for redundant code. Also, if
the user only wants attendance totals, don't calculate the totals of the other two (i.e., only
calculate the stats that the user wants).
In the printout, the text that is printed after the "Show:" word should be exactly what the
user inputted. This text should be printed in all uppercase letters. For example, if the user
inputted "lion king", then the text to be printed is LION KING,
One more important note: The object returned by the reader function will only be
available within the call of with. This means any code that uses the CSV object that is
generated must be within (i.e., indented) the call of with. When you decompose your
solution, make sure the function calls are within the call of with.
Sample run 1
Input:
1
lion king
2015
Run:
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 5/8
1 - Attendance stats
2 - Revenue stats
3 - Performance stats
Please select an option (0 to exit): 1
Enter show name: lion king
Enter year: 2015
Show: LION KING
Year: 2015
Stat: Attendance
----------------------
| Month | Total |
|-------|------------|
| 1 | 53198 |
| 2 | 52043 |
| 3 | 66667 |
| 4 | 55475 |
| 5 | 65104 |
| 6 | 54260 |
| 7 | 55829 |
| 8 | 68188 |
| 9 | 54277 |
| 10 | 54277 |
| 11 | 67035 |
| 12 | 53271 |
----------------------
TOTAL 699624
Sample run 2
Input:
2
aladdin
2014
Run:
1 - Attendance stats
2 - Revenue stats
3 - Performance stats
Please select an option (0 to exit): 2
Enter show name: aladdin
Enter year: 2014
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 6/8
Show: ALADDIN
Year: 2014
Stat: Revenue
----------------------
| Month | Total |
|-------|------------|
| 1 | 0 |
| 2 | 0 |
| 3 | 4453795 |
| 4 | 4767852 |
| 5 | 4693799 |
| 6 | 6644493 |
| 7 | 6071438 |
| 8 | 7690693 |
| 9 | 5181685 |
| 10 | 5754217 |
| 11 | 7152638 |
| 12 | 6639552 |
----------------------
TOTAL 59050162
Sample run 3
Input:
1
lion queen
2010
Run:
1 - Attendance stats
2 - Revenue stats
3 - Performance stats
Please select an option (0 to exit): 1
Enter show name: lion queen
Enter year: 2010
No data found.
Sample run 4
Input:
2020/11/20 14.32. PA10-B: Broadway Show Data File (20 pts)
https://learn.zybooks.com/zybook/VANDERBILTCS1104Fall2020/chapter/14/section/32 7/8
4
-1
0
Run:
1 - Attendance stats
2 - Revenue stats
3 - Performance stats
Please select an option (0 to exit): 4
Invalid option. Try again: -1
Invalid option. Try again: 0
Required program decomposition
For this exercise, the size of any function in terms of the number of lines used will be restricted.
One of the test cases will check that each function you implemented (including the main
function) contains at most 20 lines of code. This line limit includes the function denition
line.
Comment lines or empty lines don't count toward the line limit.
You are prohibited from using a semicolon (;) to place multiple statements in one line. The last
test case will check for this. The test case scans the entire source code looking for a semicolon.
To ensure that you are not agged
for using a semicolon, don't use a semicolon at all in the
code, including in any of the comments.
Notes
If you are working in PyCharm, make sure to download the CSV les
and place them in the
same folder where your Python le
is located.
All statements must be part of a function denition.
You must only use features of Python that have been described in class.
Style guidelines
Be sure you are following to the programming style guidelines as outlined in the CS 1104 Style
Guide document, which can be found on Brightspace under Content | Course Documents.
Courtesy of CORGIS
268376.1514804
LAB
ACTIVITY
14.32.1: PA10-B: Broadway Show Data File (20 pts) 0 / 14
Downloadable les

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。