Spring_-_Project_2_RleProgram - import java.util.Scanner...

This preview shows page 1 - 3 out of 10 pages.

import java.util.Scanner; // import Scanner to allow user's input.import java.util.Arrays; // import Arrays class.public class RleProgram {// When run as the program driver via the main() method, the program should:// 1)Display welcome message// 2)Display color test (ConsoleGfx.testRainbow)// 3)Display the menu// 4)Prompt for inputpublic static byte[] currentLoadedImage;static Scanner userInput;public static void main(String[] args) {System.out.println("Welcome to the RLE image encoder!\n"); // display message with new line.System.out.println("Displaying Spectrum Image: ");ConsoleGfx.displayImage(ConsoleGfx.testRainbow); // Display spectrum image.boolean programTerminate = false; // Use boolean to terminate the project when true.userInput = new Scanner(System.in); // declare scanner named userInputdisplayMenu(); // Call on method to display menu.while (!programTerminate) { // While not true continue running program.int userOption = userInput.nextInt(); // declare integer userOption variable and allow users input in scanner.handleUserInput(userOption);displayMenu(); // re-display menu.}}// Use method to call on for the menu to be displayed.public static void displayMenu() {// Print Menu to screen.System.out.println("RLE Menu\n" +"--------\n " +"0. Exit\n " +"1. Load File\n " +"2. Load Test Image\n " +"3. Read RLE String\n " +"4. Read RLE Hex String\n " +"5. Read Data Hex String\n " +"6. Display Image\n " +"7. Display RLE String\n " +"8. Display Hex RLE Data\n " +"9. Display Hex Flat Data\n\n " +"Select a Menu Option: ");} // Close displayMenu.public static void handleUserInput(int userOption) {// Use switch statement to handle user's inputs for menu options.switch (userOption) {case 0:
System.exit(0);case 1:promptAndLoadFile(); // Call on method.break;case 2:System.out.println("Test image data loaded."); // Print to screen.currentLoadedImage = ConsoleGfx.testImage;break;case 3:loadAndTranslateRleString();break;case 4:loadAndTranslateHexString();break;case 5:loadAndTranslateString();break;case 6:System.out.println("Displaying image...");ConsoleGfx.displayImage(currentLoadedImage);break;case 7:System.out.println(Arrays.toString(encodeRle(currentLoadedImage)));break;case 8:System.out.println(toRleString(encodeRle(currentLoadedImage)));break;case 9:System.out.println(toHexString(currentLoadedImage)); // Prints the toHexString method results.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture