Skip to content
Snippets Groups Projects
Main.java 2.78 KiB
Newer Older
Christopher Bohn's avatar
Christopher Bohn committed
package edu.unl.cse.soft160;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
    static int numberOfProblems = 4;

    private static int getProblemNumber(Scanner scanner) {
        int choice = -1;
        while (choice < 1 || choice > numberOfProblems) {
            System.out.print("Please enter the problem you're working on (1..4): ");
            try {
                choice = scanner.nextInt();
                if (choice < 1 || choice > numberOfProblems) {
                    System.out.println("Your selection must be between 1 and " + numberOfProblems + ".");
                }
            } catch (InputMismatchException ignored) {
                System.out.println("Your selection must be an integer between 1 and " + numberOfProblems + ".");
            } finally {
                scanner.nextLine();     // consume the newline
            }
        }
        return choice;
    }

    public static void printExpressionValues(int foo, int bar, int baz) {
        int[] numbers = {6, 9, 21, 22, 14, 3};
        String fooExpression = "numbers[2] == foo";
        String barExpression = "numbers[bar + 2] == 22";
        String bazExpression = "numbers[numbers[1] - baz] == 9";
        System.out.println(fooExpression + " evaluates to " + (numbers[2] == foo));
        System.out.println(barExpression + " evaluates to " + (numbers[bar + 2] == 22));
        System.out.println(bazExpression + " evaluates to " + (numbers[numbers[1] - baz] == 9));
    }

    /* WRITE convertToBoolean HERE */


    /* WRITE THE METHOD FOR PROBLEM 3 HERE */


    /* WRITE THE METHOD FOR PROBLEM 3 HERE */


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int choice = getProblemNumber(scanner);
        switch (choice) {
            case 1:
                int foo = Integer.MIN_VALUE;
                int bar = Integer.MIN_VALUE;
                int baz = Integer.MIN_VALUE;
                printExpressionValues(foo, bar, baz);
                break;
            case 2:
                // UNCOMMENT THIS CODE, AND ADD THE CALL TO convertToBoolean
//                int[] values = {3, 4, 5};
//                System.out.println(Arrays.toString(values));
//                boolean[] convertedValues = ...
//                System.out.println(Arrays.toString(convertedValues));
//                break;
            case 3:
                // WRITE CODE TO CALL YOUR PROBLEM 3 METHOD HERE. BE SURE TO ADD A break STATEMENT AT THE END OF THIS CASE.
            case 4:
                // WRITE CODE TO CALL YOUR PROBLEM 4 METHOD HERE. BE SURE TO ADD A break STATEMENT AT THE END OF THIS CASE.
            default:
                System.out.println("Not ready for problem " + choice);
        }
        scanner.close();
    }
}