Here's what I have so far..
// The "AddingPrefixes" class.
import hsa.*;
import javax.swing.JOptionPane;
public class AddingPrefixes
{
static Console c; // The output console
static char proc;
static String prefix;
static String word;
static String sentences;
private void title ()
{
c.print (' ', 32);
c.println ("Adding a Prefix");
c.println ();
}
public void intro ()
{
c = new Console ();
title ();
c.println ("This program allows you to add a prefix of your choice to a word in a sentence that you input.");
c.println ();
c.print ("To continue input 'p'");
while (true)
{
try
{
proc = c.readChar ();
if (proc == 'p')
c.print ("lol");
else
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
catch (Exception e)
{
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
}
}
public void mainmenu ()
{
c = new Console ();
title ();
c.print (' ', 18);
c.println ("The following are the choices for the program: ");
c.println ();
c.print (' ', 18);
c.println ("To continue : 'p'");
c.print (' ', 18);
c.println ("To go through the introduction : 'i'");
c.print (' ', 18);
c.println ("To exit the program : 'x'");
c.println ();
c.print (' ', 18);
c.print ("Enter your choice: ");
while (true)
{
try
{
proc = c.readChar ();
if (proc == 'p')
askData ();
if (proc == 'i')
intro ();
if (proc == 'x')
goodbye ();
else
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
catch (Exception e)
{
}
}
}
public void askData ()
{
c = new Console ();
title ();
c.print (' ', 18);
c.print ("Enter the prefix: ");
while (true)
{
try
{
prefix = c.readLine ();
break;
}
catch (Exception e)
{
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
}
c.print (' ', 18);
c.print ("Enter the word: ");
while (true)
{
try
{
word = c.readLine ();
break;
}
catch (Exception e)
{
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
}
c.print (' ', 18);
c.print ("Enter the sentence: ");
while (true)
{
try
{
sentences = c.readLine ();
displayData();
}
catch (Exception e)
{
JOptionPane.showMessageDialog (null, "That's not one of the options. Please Try Again");
}
}
}
private String prefix (String newS, int i)
{
String[] arraystr = sentences.split (" ");
for (i = 0 ; i < arraystr.length ; i++)
{
if (arraystr [i].equals (word))
c.print (prefix);
c.print (prefix + arraystr [i] + " ");
}
newS = (prefix) + (arraystr [i] + " ");
return (newS);
}
public void displayData ()
{
c = new Console ();
title ();
c.print ("The sentence(s) you typed in is/are " + sentences + " is/are converted to" + prefix ("null", 0));
}
public void goodbye ()
{
c = new Console ();
title ();
c.print ("This is the end of the program. Thank you for using it!");
}
public static void main (String[] args)
{
AddingPrefixes d;
d = new AddingPrefixes ();
d.mainmenu ();
} // main method
} // AddingPrefixes class
My problem is at the prefix method. I got mixed up there and got stucked. I don't know how to return the new arrays with the prefix.