Okay so basically I'm studying Introductory programming using the 'BlueJ' Java program on Mac. I'm trying to create a 'Dynamic Billboard' program that asks a user to enter a five letter word using the letters;
' S, P, A, R, E', then displays it in white on a black screen (or billboard).
Here is my coding below, for some reason the letters won't display on the console. Can anyone please provide some advice? I've googled it, talked to lecturers and read books on java.
import java.util.Scanner;
import billboard.BillboardInterface;
import billboard.DigitalBillboardFrame;
/**
* My Partial solution for Stage 3 of the digital billboard. It doesn't work properly.
* I tried getting help from the lecturer and also looking online and in the book.
* it compiles fine and loops properly but does not display the letters on scree.
*
* @author phi of Edith Cowan University, Edited by Zena Axon
* @version 2011 2
*/
public class Methodbillboard
{
private static final int LETTER_WIDTH = 5;
private static final int LETTER_HEIGHT = 12;
private static final int GAP = 1;
static Scanner USER_INPUT = new Scanner(System.in);
private static final int START_X = 2;
private static final int START_Y = 1;
private static String inputString;
public static void main(String[] args)
{
// initial size of the display in pixels
final int WINDOW_WIDTH = 300;
final int WINDOW_HEIGHT = 120;
// size of the grid for the digital billboard
final int BB_WIDTH = 50;
final int BB_HEIGHT = 30;
// create a billboard
BillboardInterface billboard = new DigitalBillboardFrame(
"SCSS",
WINDOW_WIDTH, WINDOW_HEIGHT,
BB_WIDTH, BB_HEIGHT);
billboard.allOff();
for(;;)
{
USER_INPUT = new Scanner(System.in);
System.out.println("Enter a 5 letter word made up of the letters ‘p’, ‘a’, ‘r’, ‘s’ and ‘e’ ");
String input = USER_INPUT.nextLine();
// first make sure the display is blank
}
}
private static void writeText(BillboardInterface billboard, int x, int y, char c)
{
writeLetter(billboard, x, y);
// OK - ready to update the display
billboard.redisplay(0);
}
private static void writeLetter(BillboardInterface billboard, int x, int y)
{
for(int i = 0; i < 5; i++)
{
// display the i_th letter
switch((inputString).charAt(i))
{
case 's':
write_s(billboard, x, y);
break;
case 'p':
write_p(billboard, x, y);
break;
case 'a':
write_a(billboard, x, y);
break;
case 'r':
write_r(billboard, x, y);
break;
case 'e':
write_e(billboard, x, y);
break;
default:
}
writeLetter(billboard, x, y);
x += LETTER_WIDTH + GAP;
// display the letter
}
}
private static void write_s(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(START_X+1, START_Y+2);
billboard.turnOn(START_X+2, START_Y+2);
billboard.turnOn(START_X+3, START_Y+2);
billboard.turnOn(START_X+4, START_Y+2);
billboard.turnOn(START_X, START_Y+3);
billboard.turnOn(START_X, START_Y+4);
billboard.turnOn(START_X+1, START_Y+5);
billboard.turnOn(START_X+2, START_Y+5);
billboard.turnOn(START_X+3, START_Y+5);
billboard.turnOn(START_X+4, START_Y+6);
billboard.turnOn(START_X+4, START_Y+7);
billboard.turnOn(START_X, START_Y+8);
billboard.turnOn(START_X+1, START_Y+8);
billboard.turnOn(START_X+2, START_Y+8);
billboard.turnOn(START_X+3, START_Y+8);
}
private static void write_p(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+1, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+2, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+3, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+4, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+4, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+4, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+4, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+4, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+1, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+2, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+GAP+3, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+9);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+10);
billboard.turnOn(START_X+LETTER_WIDTH+GAP, START_Y+11);
}
private static void write_a(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+2, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+1, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+1, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+1, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+1, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+1, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+2, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+GAP+5, START_Y+8);
}
private static void write_r(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+2, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+5, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+6, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+8);
}
private static void write_e(BillboardInterface billboard, int x, int y)
{
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+5, START_Y+2);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+6, START_Y+3);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+6, START_Y+4);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+5, START_Y+5);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+6);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+3, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+6, START_Y+7);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+4, START_Y+8);
billboard.turnOn(START_X+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+LETTER_WIDTH+GAP+5, START_Y+8);
}
}