/*
Craig Persiko
CS 111A
Solution to Practice Problem 3 - Muni Ridership Calculator
Asks the user for survey data about Muni riders,
and outputs a summary of that data.
*/
import java.util.Scanner;
class PP3
{
public static void main(String args[])
{
String muni_name;
int number_riders, num_days;
double average_riders;
Scanner keyIn = new Scanner (System.in);
System.out.println("Welcome to the Muni Ridership Calculator.");
System.out.print("Which Muni line did you survey? ");
muni_name = keyIn.nextLine();
System.out.print("How many days did you survey ridership? ");
num_days = keyIn.nextInt();
System.out.print("How many riders did you count? ");
number_riders = keyIn.nextInt();
average_riders = number_riders/(double)num_days;
// The cast to double above is necessary to get a decimal answer
// (not one with the fractional part cut off)
System.out.printf("According to your survey, an average of %,.2f"
+ " people\nrode the %s per day.\n", average_riders, muni_name);
}
}
/*
Compilation and Sample Output on Fog Linux (just like Hills):
[cpersiko@fog cs111a]$ java PP3
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 PP3
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]$
*/
syntax highlighted by Code2HTML, v. 0.9