Hey guys basically I'm studying programming using the 'BlueJ' Java program on windows. I'm trying to create a 'Dynamic Billboard' program that asks a user to enter a 5 letter word than the characters are displayed on a billboard, the program uses a text file imported for the charcters).

Ive almost completed it but im having 1 diffuculty with calling on a method here is my codding
i need to insert this writeLetter(billboard, x, y, code); somewhere and im 100% certain that code wont work if i put it somewhere any advice?


where should i put writeLetter(billboard, x, y, code); and what should i change the variable "code" too?

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 - ' ');
        writeLetter(billboard, x, y, code); //THIS PART

    }

    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;
            writeLetter(billboard, x, y, charAt); //calling on writeletter


            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(); 

                }
            }
        }
        
    }
    
}

Please edit your post, select the code and press the [code] icon above the input box to wrap code tags around your code. Unformatted code is hard to read.

It looks like the writeLetter method calls itself? Is that right?
That is recursion and you probably do NOT want to do it in your program.
Is there another version of the method with different parameters that you want to call?

Next time please use the code tag around your code. It is very difficult to read without it. :(

When you are talking about writeLetter(), does it mean that the method will display only 1 letter at a time? If so, what you are doing inside the method is incorrect because you are doing recursive. When a method calls itself inside its definition, you create a loop which is a part of recursive. If you do not have a base case, a condition when the loop can be exited, you will get an infinite loop. In your case, you have no base case and will end up with an infinite loop. I'm not sure what the method should be because you need to use the Billboard class to display each letter.

Edit: Ah! I didn't click submit and left the screen on for too long. NormR1 replied before I did. :P

ohk im sorry first time

and im really sorry i forgot what the question was suppose to ask basically this is what its asking

12. Now the last thing to do is to change the way the writeLetter method works.
Presently, a switch statement is used to select the right two-dimensional
array to use for the letter we want to draw.
But now the two dimensional arrays are all part of one three-dimensional
array. So instead of a switch statement, we will now just index into the three
dimensional array to get the right “sheet” of data.
But how can we figure out which sheet to use for each letter?
This can be done using the fact that a char in Java can be converted into an
int (it is converted to the Unicode value of that char). One way to make Java
do this conversion is to use the character to be converted in an expression. If
c is a char, then
c – ‘ ‘
is an expression that calculates how far the character c is from the character
‘ ‘ in the Unicode character set. For example
‘ ‘ – ‘ ‘
is 0, while
‘!’ – ‘ ‘
is 1. In fact, c – ‘ ‘ gives us the index of the sheet that contains the data for
the character c. In other words
letters[c – ‘ ‘]
is a two dimensional array that contains the right data to draw the character
c, when it is passed to the writeArray method as the final parameter.

Rewrite the writeLetter method to use this idea instead of using a switch
statement, and then calls writeLetter, passing in the correct sheet of the
letter array.


* now i did the writeLetter method and deleted the switch statement but now i need to call on write letter?

Please edit your post, select the code and press the [code] icon above the input box to wrap code tags around your code. Unformatted code is hard to read.

Can you explain what your problem is with doing step 12 in your assignment?

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 - ' ');
writeLetter(billboard, x, y, code); //THIS PART

}

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;
writeLetter(billboard, x, y, charAt); //calling on writeletter


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(); 

}
}
}

}

}

there we go for the code text

my problem is im suppose to use a method to call onto writeLetter to pass the information from the text to the other methods so my program works but i dont know why my call on writeLetter which is writeLetter(billboard, x, y, code); wont work?

i dont know why my call on writeLetter which is writeLetter(billboard, x, y, code); wont work?

Are there compiler errors? Please post them here.
Where is there a definition of the method you are trying to call? At what line in your posted code? The args to the method must MATCH EXACTLY.

Or is there a problem at execution time? Please post error message or explain.

Your code uses a third party package: billboards so I can't compile and test the code.

there are no errors yet because i dont know where to put the call on writeLetter so when i put it in random places i think it should go... it errors and various errors like "cannot find varible code" or "writeLetter(billboard.BillboardInterface,int,int,char) in FilesBillboard cannot be applied to (billboard.BillboardInterface,int,int,int)" appear

"writeLetter(billboard.BillboardInterface,int,int,char) in FilesBillboard cannot be applied to (billboard.BillboardInterface,int,int,int)" appear

You need to have the types of the arguments to the method match.
Look at the above. The last argument of the first is a char and the second is an int.
Either make a new method with that matches the arguments in the call, or change the arguments in the call to match the existing method.

i dont know where to put the call on writeLetter

You need to decide when you want that method to be called so that your code does what you want it to do. Putting the call to the method in random places doesn't make any sense.
Do you know what you want the program to do? Then where in the idea is the place to call the method?

i want the program to display words onto a black billboard, the user types a word and it is displayed in block letters.

i know im doing it wrong but im really lost on the method for writeLetter and the call any ideas?

lost on the method for writeLetter and the call any ideas

I gave you two choices: change the call to use the current method or add a new method that takes the args you are using in the method call with the problem.

i want the program to display words onto a black billboard, the user types a word and it is displayed in block letters.

To do that, where do you need to have the call to writeLetter?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.