Using Netbeans One of the most useful features of any programming language is re
ID: 3861993 • Letter: U
Question
Using Netbeans One of the most useful features of any programming language is recursion and control structures, decisions and loops. Recursion and loop structures allow programs to repeat actions without duplicating code. This console application focuses on your understanding of object oriented programming, control structures, and arrays. Create an application that manipulates a billboard sign. Use the following guidelines: The program must include a Billboard class (separate from the main program class) that is capable of storing the text to display. The class must include data fields The Billboard class must include methods to manipulate the text (get, set, reverse, replace substring) as well as the capability to check the text (eg. test if the text is empty). The Billboard includes a list of predefined messages that can be set as the message in the billboard. The set method allows user to select a predefined message. Also, user can create his message Add one extra method that can be used for the Billboard The main program must create an object of Billboard class. The main program must include a menu to allow a user to select a function of the Billboard object. The application must exit upon user request. For this project, do the following: Create an application that manipulates a billboard sign based on the above guidelines
Explanation / Answer
Answer
import java.util.*;
import java.util.Scanner;
class UseBillBoard
{
public static void main (String[] args) throws java.lang.Exception
{
int choice=0;
BillBoard BBobj=new BillBoard();
Scanner in;
do
{
in=new Scanner(System.in);
System.out.println("----------BillBoard MENU--------------");
System.out.println("1. SET PREDEFINED BillBoard MESSAGE");
System.out.println("2. SET User DEFINED BillBoard MESSAGE");
System.out.println("3. GET BillBoard MESSAGE");
System.out.println("4. GET Reversed BillBoard MESSAGE");
System.out.println("5. REPLACE substring from BillBoard MESSAGE");
System.out.println("6. GET BillBoard MESSAGE STATUS");
System.out.println("7. EXIT");
System.out.println("-> Enter Your Choice : ");
choice = in.nextInt();
if(choice==1)
{
System.out.println("1. Welocme To Fun City");
System.out.println("2. Welocme To Fun Park");
System.out.println("3. Welocme To The Beach");
System.out.println("-> Enter Your Choice : ");
int ch = in.nextInt();
if(ch==1)
BBobj.set("Welocme To Fun City");
else if(ch==2)
BBobj.set("Welocme To Fun Park");
else
BBobj.set("Welocme To The Beach");
}
else if(choice==2)
{
System.out.println("Enter Your Message : ");
String mst=in.nextLine();
BBobj.set(mst);
}
else if(choice==3)
{
System.out.println("----------BillBoard Message of The Day--------------");
System.out.println(BBobj.get());
}
else if(choice==4)
{
System.out.println("----------Reversed BillBoard Message of The Day--------------");
System.out.println(BBobj.reverse());
}
else if(choice==5)
{
System.out.println("Enter old String from Message to be Change : ");
String old=in.next();
System.out.println("Enter New String to be Changed in Message : ");
String newm=in.next();
System.out.println("----------BillBoard New Message of The Day--------------");
System.out.println(BBobj.replaceSt(old,newm));
}
else if(choice==6)
{
if(BBobj.checkText()==true)
System.out.println(" BillBoard Messgae Empty");
else
{
System.out.println(" BillBoard Messgae Not Empty");
System.out.println("----------BillBoard Message of The Day--------------");
System.out.println(BBobj.get());
}
}
else if(choice==7)
{
System.out.println("Exiting from Program..!!");
break;
}
else
{
System.out.println(" Wrong Choice Input..!! Try Again");
}
}while(choice!=7);
}
}
class BillBoard
{
String text;
BillBoard()
{
text="";
}
String get()
{
return text;
}
void set(String st)
{
text=st;
}
String reverse()
{
String reverse = new StringBuffer(text).reverse().toString();
return reverse;
}
String replaceSt(String old,String newm)
{
return (text.replace(old,newm));
}
boolean checkText()
{
if(text==""||text==null)
return true;
else
return false;
}
}