The objective of these code is to create a very basic advertisement that prints every second. You get to enter a new message if you press enter at any time while it's blinking, and you exit the program if you input
"n" or "N".
The program works fine the first round, but in the subsequent loops for some FRACKIN reason
1. it knocks off the first letter of any input
(ex. input "announcement" prints as "nnouncement.. nnouncement..")
2. it prints the "Please enter..." statement AGAIN before it starts the Advertisement loops
Tis my first time here but any and all help would be soooo appreciated...
Here is the code:
// -------- Begin: Advertisement.java ------------
class Advertisement extends Thread
{
String msg = "";
public Advertisement(String str) {msg = str;}
public void run()
{
boolean cont = false;
if (!msg.equals("")) cont = true;
while(cont)
{
try
{
System.out.print(msg + ".. ");
sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
}
}
// --------End: Advertisement.java ------------
// -------- Begin: TestAdvt.java ------------
import java.io.*;
class TestAdvt
{
public static void main (String[] args)
{
try
{
String str = null;
do
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the advertisement message to be displayed (enter 'n' to exit):");
str = br.readLine();
if (str.equalsIgnoreCase("n")||str.equalsIgnoreCase("N")) break;
else{
Advertisement advt = new Advertisement(str);
advt.setDaemon(true);
advt.start();
System.in.read();
advt.interrupt();
}
} while(true);
}
catch (IOException e)
{
System.out.println("error: " + e.getMessage());
}
}
}
// --------End: TestAdvt.java ------------
"n" or "N".
The program works fine the first round, but in the subsequent loops for some FRACKIN reason
1. it knocks off the first letter of any input
(ex. input "announcement" prints as "nnouncement.. nnouncement..")
2. it prints the "Please enter..." statement AGAIN before it starts the Advertisement loops
Tis my first time here but any and all help would be soooo appreciated...
Here is the code:
// -------- Begin: Advertisement.java ------------
class Advertisement extends Thread
{
String msg = "";
public Advertisement(String str) {msg = str;}
public void run()
{
boolean cont = false;
if (!msg.equals("")) cont = true;
while(cont)
{
try
{
System.out.print(msg + ".. ");
sleep(1000);
}
catch (InterruptedException e)
{
break;
}
}
}
}
// --------End: Advertisement.java ------------
// -------- Begin: TestAdvt.java ------------
import java.io.*;
class TestAdvt
{
public static void main (String[] args)
{
try
{
String str = null;
do
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the advertisement message to be displayed (enter 'n' to exit):");
str = br.readLine();
if (str.equalsIgnoreCase("n")||str.equalsIgnoreCase("N")) break;
else{
Advertisement advt = new Advertisement(str);
advt.setDaemon(true);
advt.start();
System.in.read();
advt.interrupt();
}
} while(true);
}
catch (IOException e)
{
System.out.println("error: " + e.getMessage());
}
}
}
// --------End: TestAdvt.java ------------