我很难知道从哪里开始重构Eclipse中以下写得很糟糕的反向波兰语符号。并且想知道在尝试重构代码时通常从哪里开始。
import java.util.Scanner;
class StackNode
{
public StackNode(double data, StackNode underneath)
{
this.data = data;
this.underneath = underneath;
}
public StackNode underneath;
public double data;
}
class RPN
{
public void into(double new_data)
{
StackNode new_node = new StackNode(new_data, top);
top = new_node;
}
public double outof( )
{
double top_data = top.data;
top = top.underneath;
return top_data;
}
public RPN(String command)
{
top = null;
this.command = command;
}
public double get( )
{
double a, b;
int j;
for(int i = 0; i < command.length( ); i++)
{
// if it's a digit
if(Character.isDigit(command.charAt(i)))
{
double number;
// get a string of the number
String temp = "";
for(j = 0; (j < 100) && (Character.isDigit(command.charAt(i)) || (command.charAt(i) == '.')); j++, i++)
{
temp = temp + String.valueOf(command.charAt(i));
}
// convert to double and add to the stack
number = Double.parseDouble(temp);
into(number);
} else if(command.charAt(i) == '+') {
b = outof( );
a = outof( );
into(a + b);
} else if(command.charAt(i) == '-') {
b = outof( );
a = outof( );
into(a - b);
} else if(command.charAt(i) == '*') {
b = outof( );
a = outof( );
into(a * b);
}
任何事情都会有帮助,谢谢。P.S. 很抱歉,我无法使它更短的长代码。
www说
相关分类