Homework 3: Muni ridership calculator
Objective: To perform a simple calculation based on user input
Write a program that asks the user for survey data about Muni riders, and outputs a summary of that data.
Your program should first ask the user which Muni line was surveyed. Then the program asks the user how
many days the survey was conducted, storing an integer answer, and then enter the number of riders that were
counted (also an int). Your program divides the number of riders by the number of days and outputs the
resulting average daily ridership. If that average is not a whole number, make sure you show the decimal
value (such as in the examples below). You should use a typecast to make this work. Please use "printf" to display
the result with 2 digits after the decimal point (rounded to the nearest hundredth).
Your program should behave like shown below (remember that "[cpersiko@fog cs111a]$" is the Linux prompt; your program
does not output this)
Sample Input/Output on Linux:
[cpersiko@fog cs111a]$ java HW3
Welcome to the Muni Ridership Calculator.
Which Muni line did you survey? K-Ingleside
How many days did you survey ridership? 5
How many riders did you count? 123456
According to your survey, an average of 24,691.20 people
rode the K-Ingleside per day.
[cpersiko@fog cs111a]$ java HW3
Welcome to the Muni Ridership Calculator.
Which Muni line did you survey? N-Judah
How many days did you survey ridership? 30
How many riders did you count? 25000
According to your survey, an average of 833.33 people
rode the N-Judah per day.
[cpersiko@fog cs111a]$
Rules
- Like with Homework 2, you must turn in the text of both the source code and the
sample output. For this assignment I want to see both of the test cases shown above.
- Make sure to put a comment at the top of your program with your name, the name of your Java source
file, the name of this assignment and class (111A Homework 3), and a brief description of what
the program does.
- Please follow the standard conventions for indentation, meaningful variable names, etc. like the
examples in class and in the textbook.
- Make sure to submit your homework using Canvas.
Return to main CS 111A page