我应该如何在EclipseIDE中折射写得不好的反向波兰符号java代码
在Eclipse中重构以下写得很糟糕的反向波兰符号时,我很难知道从哪里开始。并且想知道在尝试重构代码时从哪里开始我应该如何在EclipseIDE中折射写得不好的反向波兰符号java代码,java,eclipse,refactoring,Java,Eclipse,Refactoring,在Eclipse中重构以下写得很糟糕的反向波兰符号时,我很难知道从哪里开始。并且想知道在尝试重构代码时从哪里开始 import java.util.Scanner; class StackNode { public StackNode(double data, StackNode underneath) { this.data = data; this.underneath = underneath; } public St
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);
} else if(command.charAt(i) == '/') {
b = outof( );
a = outof( );
into(a / b);
} else if(command.charAt(i) == '^') {
b = outof( );
a = outof( );
into(Math.pow(a, b));
} else if(command.charAt(i) != ' ') {
throw new IllegalArgumentException( );
}
}
double val = outof( );
if(top != null)
{
throw new IllegalArgumentException( );
}
return val;
}
private String command;
private StackNode top;
/* main method */
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
while(true)
{
System.out.println("Enter RPN expression or \"quit\".");
String line = input.nextLine( );
if(line.equals("quit"))
{
input.close();
break;
} else {
RPN calc = new RPN(line);
System.out.printf("Answer is %f\n", calc.get( ));
}
}
}
}
import java.util.Scanner;
类堆栈节点
{
公共StackNode(双数据,下面是StackNode)
{
这个数据=数据;
下面,下面;
}
下面是公共StackNode;
公开双重数据;
}
类RPN
{
公共作废到(双新_数据)
{
StackNode new_node=新StackNode(新_数据,顶部);
top=新的_节点;
}
公共双出()
{
双顶端数据=顶端数据;
顶部=顶部。底部;
返回top_数据;
}
公共RPN(字符串命令)
{
top=null;
this.command=命令;
}
公共双get()
{
双a,b;
int j;
for(inti=0;i
什么都行,谢谢。
另外,很抱歉代码太长,我无法将其缩短。
您可以使用它来帮助您在编写代码时检测和解决质量问题。您可以从下载。
改进问题,否则工作代码可能更适合,但一定要遵循他们可接受的内容指南。从您认为“写得不好”的部分开始。