Entry
Java: Borland: JBuilder: X: Stand alone: Create: How to create from existing other console program?
Jan 10th, 2004 22:20
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 11 January 2004 - 06:37 am --------------------
Java: Borland: JBuilder: X: Stand alone: Create: How to create from
existing other console program?
---
Steps: Overview:
1. Suppose you have an already Java program which you e.g.
created outside of JBuilder, and now want to run and
or debug in JBuilder
2. Here an example of such a program
--- cut here ---------------------------------------------------------
import java.io.*;
//
class CLASSStringConvertInfixToSuffix {
private String expressionS;
private String tabletokenS;
private String tableinputS;
private String tablestackS;
private String stackS;
private String kexpressionS;
private String kstackS;
private String resultS;
private int expressionI;
private int stackI;
private int posI;
private int priorityinputI;
private int prioritystackI;
private int I;
// constructor for this class
public CLASSStringConvertInfixToSuffix( String expressionS )
{
this.expressionS = expressionS;
tabletokenS = "#-+/*^abcdefghijklmnopqrstuvwxyz0123456789()";
tableinputS = "03344599999999999999999999999999999999999992";
tablestackS = "03344599999999999999999999999999999999999929";
stackS = "";
kexpressionS = "";
kstackS = "";
resultS = "";
expressionI = 0 - 1;
stackI = 0 - 1;
posI = -1;
priorityinputI = -1;
prioritystackI = -1;
I = 0;
stackI = stackI + 1;
stackS = "#";
}
// destructor for this class
protected void finalize() {
}
//
public String FNStringConvertInfixToPrefixS() {
do
{
expressionI = expressionI + 1;
kexpressionS = expressionS.substring( expressionI, expressionI +
1 );
posI = tabletokenS.indexOf( kexpressionS, 0 );
if ( posI == -1 ) {
System.out.println( kexpressionS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
priorityinputI = Integer.valueOf( tableinputS.substring( posI, posI
+ 1 ) ).intValue();
kstackS = stackS.substring( 0, 1 );
posI = tabletokenS.indexOf( kstackS, 0 );
if ( posI < 0 ) {
System.out.println( kstackS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
prioritystackI = Integer.valueOf( tablestackS.substring( posI, posI
+ 1 ) ).intValue();
if ( priorityinputI > prioritystackI ) {
stackS = kexpressionS + stackS;
}
else {
do {
if ( ( kstackS.charAt( 0 ) != '(' ) && ( kstackS.charAt( 0 ) !
= ')' ) ) {
resultS = resultS + kstackS;
}
stackS = stackS.substring( 1, stackS.length() );
kstackS = stackS.substring( 0, 1 );
posI = tabletokenS.indexOf( kstackS, 0 );
if ( posI < 0 ) {
System.out.println( kstackS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
prioritystackI = Integer.valueOf( tablestackS.substring( posI,
posI + 1 ) ).intValue();
} while ( priorityinputI <= prioritystackI );
stackS = kexpressionS + stackS;
}
} while ( expressionI < ( expressionS.length() - 1 ) );
I = 0 - 1;
do {
I = I + 1;
kstackS = stackS.substring( I, I + 1 );
if ( ( !kstackS.equals( "#" ) ) && ( !kstackS.equals( "(" ) ) && ( !
kstackS.equals( ")" ) ) ) {
resultS = resultS + kstackS;
}
} while ( I < ( stackS.length() - 1 ) );
return( resultS );
}
}
//
class CLASSStringConvertInfixToSuffixMain {
public static void main( String args[] ) throws IOException {
String infixS = "((2*3)^6+(4*5)+(6*7))^7";
BufferedReader kbd = new BufferedReader( new InputStreamReader(
System.in ) );
do {
CLASSStringConvertInfixToSuffix OBJECTrpn = new
CLASSStringConvertInfixToSuffix( infixS );
System.out.println( "infix = " + infixS );
System.out.println( "suffix = " +
OBJECTrpn.FNStringConvertInfixToPrefixS() );
System.out.println( "Type in a new infix String (type Q to quit),
for example (3+4)*5+6-7 ");
try {
infixS = kbd.readLine();
}
catch ( Exception e ) {
System.out.println( "an input error occurred" );
}
if ( infixS.equals( "" ) ) {
infixS = "(3+4)*5+6-7";
}
} while ( !infixS.toLowerCase().equals( "q" ) );
}
}
--- cut here ---------------------------------------------------------
3. -possibly start JBuilder X
4. -possibly close any projects which are open
1. -select from menu option 'File'
2. -select from list 'Close Projects...'
3. -enable the checkbox for the projects you want to close
4. -click button 'OK'
5. -Open a new project
1. -select from menu option 'File'
2. -select from list 'New Project'
3. -click button 'Finish'
6. -Create a new class
1. -select from menu option 'File'
2. -select from list 'New Class...'
3. -a dialog box 'Class Wizard' will
now open
4. -what is important here that you
change the
'Class name:'
to that class in your ready program
which contains the 'main()' method
So here, in this becomes:
CLASSStringConvertInfixToSuffixMain
5. -disable all other checkboxes
as you have already some ready
made Java console program,
so nothing has to be automatically
generated by JBuilder
6. -click button 'OK'
7. -This will automatically generate some source code
for you
--- cut here ---------------------------------------------------------
package untitled11;
class CLASSStringConvertInfixToSuffixMain {
}
--- cut here ---------------------------------------------------------
8. -Delete everything except the 'package' line
--- cut here ---------------------------------------------------------
package untitled1;
--- cut here ---------------------------------------------------------
9. -Paste your program inside
--- cut here ---------------------------------------------------------
package untitled1;
import java.io.*;
//
class CLASSStringConvertInfixToSuffix {
private String expressionS;
private String tabletokenS;
private String tableinputS;
private String tablestackS;
private String stackS;
private String kexpressionS;
private String kstackS;
private String resultS;
private int expressionI;
private int stackI;
private int posI;
private int priorityinputI;
private int prioritystackI;
private int I;
// constructor for this class
public CLASSStringConvertInfixToSuffix( String expressionS )
{
this.expressionS = expressionS;
tabletokenS = "#-+/*^abcdefghijklmnopqrstuvwxyz0123456789()";
tableinputS = "03344599999999999999999999999999999999999992";
tablestackS = "03344599999999999999999999999999999999999929";
stackS = "";
kexpressionS = "";
kstackS = "";
resultS = "";
expressionI = 0 - 1;
stackI = 0 - 1;
posI = -1;
priorityinputI = -1;
prioritystackI = -1;
I = 0;
stackI = stackI + 1;
stackS = "#";
}
// destructor for this class
protected void finalize() {
}
//
public String FNStringConvertInfixToPrefixS() {
do
{
expressionI = expressionI + 1;
kexpressionS = expressionS.substring( expressionI, expressionI +
1 );
posI = tabletokenS.indexOf( kexpressionS, 0 );
if ( posI == -1 ) {
System.out.println( kexpressionS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
priorityinputI = Integer.valueOf( tableinputS.substring( posI, posI
+ 1 ) ).intValue();
kstackS = stackS.substring( 0, 1 );
posI = tabletokenS.indexOf( kstackS, 0 );
if ( posI < 0 ) {
System.out.println( kstackS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
prioritystackI = Integer.valueOf( tablestackS.substring( posI, posI
+ 1 ) ).intValue();
if ( priorityinputI > prioritystackI ) {
stackS = kexpressionS + stackS;
}
else {
do {
if ( ( kstackS.charAt( 0 ) != '(' ) && ( kstackS.charAt( 0 ) !
= ')' ) ) {
resultS = resultS + kstackS;
}
stackS = stackS.substring( 1, stackS.length() );
kstackS = stackS.substring( 0, 1 );
posI = tabletokenS.indexOf( kstackS, 0 );
if ( posI < 0 ) {
System.out.println( kstackS + " not found in tabletokenS " +
tabletokenS );
return( "error" );
}
prioritystackI = Integer.valueOf( tablestackS.substring( posI,
posI + 1 ) ).intValue();
} while ( priorityinputI <= prioritystackI );
stackS = kexpressionS + stackS;
}
} while ( expressionI < ( expressionS.length() - 1 ) );
I = 0 - 1;
do {
I = I + 1;
kstackS = stackS.substring( I, I + 1 );
if ( ( !kstackS.equals( "#" ) ) && ( !kstackS.equals( "(" ) ) && ( !
kstackS.equals( ")" ) ) ) {
resultS = resultS + kstackS;
}
} while ( I < ( stackS.length() - 1 ) );
return( resultS );
}
}
//
class CLASSStringConvertInfixToSuffixMain {
public static void main( String args[] ) throws IOException {
String infixS = "((2*3)^6+(4*5)+(6*7))^7";
BufferedReader kbd = new BufferedReader( new InputStreamReader(
System.in ) );
do {
CLASSStringConvertInfixToSuffix OBJECTrpn = new
CLASSStringConvertInfixToSuffix( infixS );
System.out.println( "infix = " + infixS );
System.out.println( "suffix = " +
OBJECTrpn.FNStringConvertInfixToPrefixS() );
System.out.println( "Type in a new infix String (type Q to quit),
for example (3+4)*5+6-7 ");
try {
infixS = kbd.readLine();
}
catch ( Exception e ) {
System.out.println( "an input error occurred" );
}
if ( infixS.equals( "" ) ) {
infixS = "(3+4)*5+6-7";
}
} while ( !infixS.toLowerCase().equals( "q" ) );
}
}
--- cut here ---------------------------------------------------------
10. -Run your application
1. Press <F9>
- or -
1. In the menu click on the green '>'
icon
11. That will open the dialog box
'Runtime Configurations'
12. -click button 'New'
13. -Now indicate the name of that class
in your program which contains
the 'main()' method
1. click button '...'
on the right of 'Main class'
2. this shows a large list of
classes
1. -browse down to the name of your
current program
(e.g. 'Untitled1')
2. -Click on the '+' to expand
3. -Select the name of that class
(e.g. 'CLASSStringConvertInfixToSuffixMain')
4. -click button 'OK'
5. -Your class name will now show as:
untitled1.CLASSStringConvertInfixToSuffixMain
3. -click button 'OK'
4. -click button 'OK'
---
Note: if you run your application and
JBuilder informs that it can not find
your main method, then almost for sure
you have to repeat this steps here
to indicate exactly that name of that
class in which your 'main()' method
can be found.
If there are more classes in the program,
then there is or should be only one class which
contains the main() method.
14. -Run your application again
1. Press <F9>
- or -
1. In the menu click on the green '>'
icon
15. -That should show e.g.
+--------------------------------------------------------------------+
|infix = ((2*3)^6+(4*5)+(6*7))^7 |
|suffix = 23*6^45*+67*+7^ |
|Type in a new infix String (type Q to quit), for example (3+4)*5+6-7|
+--------------------------------------------------------------------+
in the messages window
---
---
Internet: see also:
---
Java: Borland: JBuilder: X: Stand alone: Create: How to create 'Hello
World' console program?
http://www.faqts.com/knowledge_base/view.phtml/aid/28228/fid/165
---
Algorithm: Expression: Infix: Convert: Postfix: Overview: How convert
infix to postfix expression?
http://www.faqts.com/knowledge_base/view.phtml/aid/26071/fid/585
----------------------------------------------------------------------