⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.java

📁 超级多项式计算器
💻 JAVA
字号:

import java.util.Vector;

/**Class Fuction<br/>
  *Data structure to save a function.
  *It has several attributes such as name,arguments and the calculated expression of the fuction express.
  *Also it contains a method to parse the function expression to get the functionname and the arguments.
  *@author zhlmmc
  *@version 1.0
  */

public class Function
{
	String s;
	char name;
	Vector arguments = new Vector();
	Vector funcTerms = new Vector();

	/**constructors
	  *Fuction() receive no arguments 
	  */
	public Function()
	{
		name = '$';
		s = "";
	}

	/**
	  *Fuction(String input)<br/>
	  *@param input the expression of the function
	  *@param terms a Vector that contains the polynomial calculated by Calculate.calculateTerms()
	  */

	public Function(String input,Vector terms)
	{
		this();
		
		funcTerms = terms;
		analyseInput(input);
		s = "DEF" + toString();
		
	}

	/**analyseInput
	  *Analyse the input to separate the
	  *fuction name and argument.
	  *Also this method will store them.
	  *@param input the function express
	  */
	public void analyseInput(String input)
	{

		//analyse the name of the function
		name = input.charAt(3);

		//analyse the arguments
		int i = 5;//because "DEFA(a,b) = ...",the first argument a's subscript is 5
		do
		{

			if (input.charAt(i) == ',')
			{
				continue;
			}
			else
			{
				arguments.add(new Character(input.charAt(i)));
			}

		}
		while (input.charAt(++i) != ')');


	}

	/**output the function expression
	  *@return the function expression in String type
	  */
	public String toString()
	{
		if (funcTerms.size() == 0)
		{
			return s.substring(3,s.length());
		}
		String output = "";
		
		output += name + "(" + ((Character)arguments.get(0)).charValue();

		for (int i = 1;i < arguments.size();i++)
		{
			output += "," + ((Character)arguments.get(i)).charValue();
		}
		output += ")" + "=";
		
		String tempStr = ((TermNode)funcTerms.get(0)).toString();
		
		if (tempStr.charAt(0) == '+')
		{
			
			output += tempStr.substring(1,tempStr.length());
		}
		else output += tempStr.substring(0,tempStr.length());

		int len = funcTerms.size();//the length of terms
		for (int i = 1;i < len ;i++ )
		{
			output += ((TermNode)funcTerms.get(i)).toString();
		}
			

		return output;
	}



};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -