Fall_-_RleProgram.java - import java.util.Scanner public...

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

import java.util.Scanner; public class RleProgram { public static void main(String args[]) { //Variable Initialization int option = 10; String filename; String rleString; String rleHexString; String hexStringFlat; byte[] flatData = null; Scanner scanner1 = new Scanner(System. in ); //Initial output and spectrum image System. out .println("Welcome to the RLE image encoder!"); System. out .println(); System. out .println("Displaying Spectrum Image:"); ConsoleGfx. displayImage (ConsoleGfx. testRainbow ); System. out .println(); //This while loop prints the menu after every input while (option != 0) { System. out .println(); System. out .println("RLE Menu"); System. out .println("--------"); System. out .println("0. Exit"); System. out .println("1. Load File"); System. out .println("2. Load Test Image"); System. out .println("3. Read RLE String"); System. out .println("4. Read RLE Hex String"); System. out .println("5. Read Data Hex String"); System. out .println("6. Display Image"); System. out .println("7. Display RLE String"); System. out .println("8. Display Hex RLE Data"); System. out .println("9. Display Hex Flat Data"); System. out .println(); System. out .print("Select a Menu Option: "); option = scanner1.nextInt(); //This collection of if statements calls the appropriate methods if (option == 1) { System. out .print("Enter name of file to load: "); filename = scanner1.next(); flatData = ConsoleGfx. loadFile (filename); } if (option == 2) { System. out .println("Test image data loaded."); flatData = ConsoleGfx. testImage ; } if (option == 3) { System. out .print("Enter an RLE string to be decoded: "); rleString = scanner1.next();
flatData = decodeRle ( stringToRle (rleString)); } if (option == 4) { System. out .print("Enter the hex string holding RLE data: "); rleHexString = scanner1.next(); flatData = decodeRle ( stringToData (rleHexString)); } if (option == 5) { System. out .print("Enter the hex string holding flat data: "); hexStringFlat = scanner1.next(); flatData = stringToData (hexStringFlat); } if (option == 6) { System. out .println("Displaying image..."); ConsoleGfx. displayImage (flatData); } if (option == 7) { System. out .println("RLE representation:" + toRleString ( encodeRle (flatData))); } if (option == 8) { System. out .println("RLE hex values: " + toHexString ( encodeRle ((flatData)))); } if (option == 9) { System. out .println("Flat hex values: " + toHexString (flatData)); }

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture