Hey i have a assignment in which i have a digital billboard its almost complete but i just have 1 line that is stopping my program from doing what its suppose to do.
Im suppose to have a program that can display block letters when the user enters a word or character. the program reads ASCII code from a file.
This is the last step i need to do
*Rewrite the writeLetter method to use this idea instead of using a switch
statement, and then call writeArray, passing in the correct sheet of the letter
array*. i have erased the switch statement and put the next step but i just need the call from writeLetter to writeArray.
i sumbitted the program so far for feedback and got this comment back.
You are missing a critical call (the one that draws a letter) in your writeText method.
Can anyone help me the code is below
import java.util.Scanner; //needed for Scanner
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
import java.io.File;
import java.io.FileNotFoundException;
public class FilesBillboard
{
// initial size of the display in pixels
static final int WINDOW_WIDTH = 300;
static final int WINDOW_HEIGHT = 120;
// size of the grid for the digital billboard
static final int BB_WIDTH = 50;
static final int BB_HEIGHT = 30;
// we will make letters 5 cells wide and 12 high
static final int LETTER_WIDTH = 8;
static final int LETTER_HEIGHT = 12;
// and leave a 1 cell gap between letters
static final int GAP = 0;
//number of characters in file
static final int NUM_LETTERS = 95;
//name for the textfile
static final String LETTER_PATH = "letters.txt";
// the top left of the first letter in the word will be 2 cells from the left and 1 down
static final int START_X = 2;
static final int START_Y = 1;
private static final int[][] _s =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _p =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0}
};
private static final int[][] _a =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 0, 1},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _r =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 0, 1, 1, 0},
{0, 1, 0, 0, 1},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
private static final int[][] _e =
{
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 1},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}
};
public static void main(String[] args)
{
//Call on readletters
try
{
readLetters(); //method that throws exception
}
catch (FileNotFoundException fnfe)
{
//print error message
return; //leave
}
// create a billboard
BillboardInterface billboard = new DigitalBillboardFrame(
"SCSS",
WINDOW_WIDTH, WINDOW_HEIGHT,
BB_WIDTH, BB_HEIGHT);
// first make sure the display is blank
billboard.allOff();
//forever
for(;;)
{
//get a message from the user
String word;
Scanner userInput = new Scanner (System.in); //Create Scanner Object
System.out.print("Enter a 5 letter word using the letters s, p, a, r, e! \n>>> ");
word = userInput.nextLine();
billboard.allOff();
//for each letter in the message
//for each letter in the message
int x = START_X; //keep track of where each letter should go
int y = START_Y;
//display the letter
writeText(billboard, x, y, word);
}
}
private static void writeLetter(BillboardInterface billboard, int x, int y, char c) // Displaying appropriate letters
{
int code =(int)(c - ' ');
}
private static void writeText(BillboardInterface billboard, int x, int y, String text) // Getting word from user
{
int length = text.length(); // Defining length
for(int i = 0; i < 5 && i < length; i++)
{
//display the i_th letter
char charAt = text.charAt(i);
x += LETTER_WIDTH + GAP;
billboard.redisplay(0);
}
}
private static void writeArray(BillboardInterface billboard, int x, int y, int[][] pixels) //method for array
{
for(int row = 0; row < pixels.length; row++)
{
for(int col = 0; col < pixels[row].length; col ++)
{
if (pixels[row][col] == 1) //checking if the pixel is a 1
{
billboard.turnOn(x+col, y+row); //using a turnOn to turn on the grid at a specific pixel
}
}
}
}
//declare a static field for the 3 dimensional array
private static int [][][] letters;
//read from file and display in array
private static void readLetters() throws FileNotFoundException
{
//created the letters array
letters = new int [NUM_LETTERS][LETTER_HEIGHT][LETTER_WIDTH];
//Using scanner object to open file
File letterFile = new File(LETTER_PATH);
Scanner input = new Scanner(letterFile);
//Nested Loops to read data from file
for (int i = 0; i < NUM_LETTERS; ++i){
for (int j = 0; j < LETTER_HEIGHT; ++j){
for (int k = 0; k < LETTER_WIDTH; ++k) {
letters[i][j][k] = input.nextInt();
}
}
}
}
}