RleProgram.java - import java.util.Scanner import...

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

import java.util.Scanner; import java.lang.reflect.Array; public class RleProgram { public static void main(String[] args) { //Declare Scanner for user input Scanner scnr = new Scanner(System.in); int exitProgram = 0; int userSelection; String userInput; // 1 Display welcome message System.out.println("Welcome to the RLE image encoder!\n"); // 2 Display Color test System.out.println("Displaying Spectrum Image: "); ConsoleGfx.displayImage(ConsoleGfx.testRainbow); System.out.println("\n"); byte[] imageData = null; // 3 display menu while (exitProgram == 0) { //Present Menu System.out.println("\nRLE 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"); // Receive user's input (Enter Menu Selection) System.out.print("Select a Menu Option: "); userSelection = scnr.nextInt(); switch(userSelection) { case 0: exitProgram = 1; return; case 1: System.out.print("Enter name of file to load: "); userInput = scnr.next(); imageData = ConsoleGfx.loadFile(userInput); break; case 2: imageData = ConsoleGfx.testImage; System.out.println("Test image data loaded."); break; case 3: break; case 4:
System.out.print("Enter the hex string holding RLE data: "); userInput = scnr.next(); break; case 5: break; case 6: System.out.println("Displaying image..."); ConsoleGfx.displayImage(imageData); break; case 7: break; case 8: break; case 9: break; } } } // 1 Modified for function 7 public static String toHexStringMod(byte data) { String result = ""; // Returns as a String String byteToString = String.valueOf(data); // Converting 10-15 into a-f if (byteToString.equals("10")) { byteToString = "a"; } if (byteToString.equals("11")) { byteToString = "b"; } if (byteToString.equals("12")) {

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture