📄 helpmode.java
字号:
import java.io.*;
import java.util.Vector;
/**Class HelpMode<br/>
*This class to run the HelpMode,contains sevaral commands :<br/>
*list -- to see the command list<br/>
*help -- to see the help document<br/>
*func -- to see the Functions that have been defined<br/>
*done -- to see the polynomials that have been calculated<br/>
*info -- to see the program's information
*close -- close the HelpMode to the original mode<br/>
*Also this class contians a read method to read these methods and to judge if the input
*command if legal.
*/
public final class HelpMode
{
private static Vector functionList = new Vector();
private static Vector calculated = new Vector();
private static BufferedReader d;
private static final String INFORMATION =
"*-----------------------*-多项式计算器-*----------------------*\n\n" +
" 版本 : Pcalc 1.0\n" +
" 作者 : zhlmmc\n" +
" 信箱 : zhlmmc@hotmail.com\n" +
" *************************\n" +
" * This software is FREE *\n" +
" * Copyright @ zhlmmc *\n" +
" * All Rights Reserved *\n" +
" *************************\n\n";
private static final String COMMANDS =
"*-------*-命令表-*-------*\n" +
"list -- 查看命令表\n" +
"help -- 查看帮助文档\n" +
"func -- 查看已经定义过的函数\n" +
"done -- 查看已经计算过的多项式\n" +
"info -- 查看软件信息\n" +
"close -- 退出帮助模式\n\n";
/**This method is to read the command in the HelpMode
*and judge if the command is legal.
*/
public static void read()
{
//print the welcome information
System.out.println(
"*************************************************************************\n" +
"**************************欢 迎 进 入 帮 助 模 式************************\n" +
"*************************************************************************\n\n");
System.out.println(COMMANDS);
//declear the reader and the StreamReaderBuffer
InputStreamReader cin = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(cin);
String s = "";//string to recive the polynomial
//this block is to do the read task
do
{
try
{
System.out.print("请输入命令 :");
s = "";
s += bf.readLine();
if ((s.equals("help")) || (s.equals("func")) || (s.equals("done"))
|| (s.equals("info")) || (s.equals("list")))
{
dealCommands(s);
}
else if ( s.equals("close"))
{
System.out.println();
break;
}
else
{
System.out.println("对不起,您输入的命令错误!");
}
}catch(IOException e)
{
System.out.println("Wrong!");
}
}while(true);
}
/*this method is to deal the command
*/
private static void dealCommands(String cmd)
{
if (cmd.equals("help"))
help();
else if (cmd.equals("list"))
{
System.out.println(COMMANDS);
}
else if (cmd.equals("func"))
{
func();
}
else if (cmd.equals("done"))
{
done();
}
else if (cmd.equals("info"))
{
System.out.println(INFORMATION);
}
}
/**this method is to deal the func command
*/
private static void func()
{
if (functionList.size() == 0)
{
System.out.println("对不起,暂时还没有自定义函数!\n");
return;
}
System.out.println("*------------*-已经定义的函数-*-------------*");
for (int i = 0;i < functionList.size() ;i++ )
{
System.out.println((i+1)+") " + functionList.get(i));
}
System.out.println();
}
/**this method is to deal the done command
*/
private static void done()
{
if (calculated.size() == 0)
{
System.out.println("对不起,暂时还没有计算过任何多项式!\n");
return;
}
System.out.println("*----------*-已经计算过的多项式-*-----------*");
for (int i = 0;i < calculated.size() ;i++ )
{
System.out.println((i+1)+") " + calculated.get(i));
}
System.out.println();
}
/**this method is to deal the help command
*/
private static void help()
{
String temp = "";
try
{
d = new BufferedReader(new InputStreamReader(new FileInputStream("help.txt")));
}
catch (IOException e)
{
System.out.println("ERROR :File not found!");
System.exit(1);
}
while (true)
{
try
{
temp = d.readLine();
if (temp != null)
{
System.out.println(temp);
}
else break;
}
catch (EOFException eof)
{
break;
}
catch (IOException e)
{
break;
}
}
try
{
d.close();
}
catch (IOException e)
{
}
}
/**This method is to update the functions
*@param functions the newest functions
*/
public static void setFunctions(Vector functions)
{
functionList = functions;
}
/**This method is to add the calculated polynomials
*@param expression the current polynoimal
*/
public static void addCalculated(String expression)
{
calculated.add(expression);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -