📜  哪个城市是 94609 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:27.638000             🧑  作者: Mango

代码示例3
import java.util.Date;import java.util.Scanner;public class USCrimeTest {    private Scanner scanner = new Scanner(System.in);    private void printWelcomeMessage() {        print("-- Welcome to the US USCrime Statistical Application --");    }    private void showOptions() {        print("1. What were the percentages in population growth for each consecutive year from 1994 ? 2013?");        print("2. What year was the Murder rate the highest?");        print("3. What year was the Murder rate the lowest?");        print("4. What year was the Robbery rate the highest?");        print("5. What year was the Robbery rate the lowest?");        print("6. What was the total percentage change in Motor Vehicle Theft between 1998 and 2012?");        print("7. What was the total percentage change in aggravated assault between 1995 and 2011?");        print("8. What was the total percentage change in Property crime between 1995 and 2009?");        print("Q. Quit the program");    }    private void print(String message) {        System.out.println(message);    }    private void showMenu(CrimeParser stats) {        Statistics statistics = new StatisticsImpl(stats.getCrimesData());        // Continue displaying the menu as long as the user has not entered "Q"            showOptions();        print("");        System.out.print("Enter your selection: ");        String selection = scanner.nextLine().trim();        switch (selection) {            case "1":                statistics.calculatePopulationGrowth(1994, 2013);                showMenu(stats);                break;            case "2":                print(statistics.calculateMaxMurderYear());                showMenu(stats);                break;            case "3":                print(statistics.calculateMinMurderYear());                showMenu(stats);                break;            case "4":                print(statistics.calculateMaxRobberyYear());                showMenu(stats);                break;            case "5":                print(statistics.calculateMinRobberyYear());                showMenu(stats);                break;            case "6":                print(statistics.calculateMotorVehicleTheftChange(1998, 2012));                showMenu(stats);                break;            case "7":                print(statistics.calculateAggravatedAssaultChange(1995, 2011));                showMenu(stats);                break;            case "8":                print(statistics.calculatePropertyChange(1995, 2009));                showMenu(stats);                break;            case "Q":                break;            default:                print("You entered a bad choice. Please try again!");                showMenu(stats);        }    }    public static void main(String[] args) {        CrimeParser crimeParser = new CrimeParser(args[0]);        USCrimeTest test = new USCrimeTest();        test.printWelcomeMessage();        long start = System.currentTimeMillis();        test.showMenu(crimeParser);        long end = System.currentTimeMillis();        long duration = new Date(end - start).getSeconds();        System.out.println("Thank you for trying the US Crimes Statistics Program.");        System.out.format("Elapsed time in seconds was: %d%n", duration);    }}