Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 3.27 KB

File metadata and controls

95 lines (69 loc) · 3.27 KB

In this section you'll create a basic Java console app.

  1. Open your command-line interface (CLI) in a directory where you want to create the project. Run the following command to create a new Gradle project.

    gradle init --dsl groovy --test-framework junit --type java-application --project-name graphtutorial --package graphtutorial
  2. Once the project is created, verify that it works by running the following command to run the app in your CLI.

    ./gradlew --console plain run

    If it works, the app should output Hello World..

Install dependencies

Before moving on, add some additional dependencies that you will use later.

  1. Open ./build.gradle. Update the dependencies section to add those dependencies.

    :::code language="gradle" source="../demo/graphtutorial/build.gradle" id="DependenciesSnippet" highlight="7-9":::

  2. Add the following to the end of ./build.gradle.

    :::code language="gradle" source="../demo/graphtutorial/build.gradle" id="StandardInputSnippet":::

The next time you build the project, Gradle will download those dependencies.

Design the app

  1. Open the ./src/main/java/graphtutorial/App.java file and replace its contents with the following.

    package graphtutorial;
    
    import java.util.InputMismatchException;
    import java.util.Scanner;
    
    /**
     * Graph Tutorial
     *
     */
    public class App {
        public static void main(String[] args) {
            System.out.println("Java Graph Tutorial");
            System.out.println();
    
            Scanner input = new Scanner(System.in);
    
            int choice = -1;
    
            while (choice != 0) {
                System.out.println("Please choose one of the following options:");
                System.out.println("0. Exit");
                System.out.println("1. Display access token");
                System.out.println("2. List calendar events");
    
                try {
                    choice = input.nextInt();
                } catch (InputMismatchException ex) {
                    // Skip over non-integer input
                    input.nextLine();
                }
    
                // Process user choice
                switch(choice) {
                    case 0:
                        // Exit the program
                        System.out.println("Goodbye...");
                        break;
                    case 1:
                        // Display access token
                        break;
                    case 2:
                        // List the calendar
                        break;
                    default:
                        System.out.println("Invalid choice");
                }
            }
    
            input.close();
        }
    }

    This implements a basic menu and reads the user's choice from the command line.