亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? mcalc.java

?? 用java實現(xiàn)浮點數(shù)加減乘除四則混合運算
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
import java.io.*;
import java.util.*;

/**
 * This is the main class of the calculator program. <p>
 * The calculator program can perform matrix arithmetic including addition,
 * subtraction, multiplication, division as well as transposition and
 * inversion. <p>
 * It can also perform floating-number arithmetic. <p>
 * This class reads the commands from the user, solves
 * the problem, and returns the answer.
 * 
 * @author Rachel Chen  0122070
 * @version 1.0    2003/3/22
 * @see java.io.StreamTokenizer
 * @see java.util.Hashtable
 * @see java.util.StringTokenizer
 */
public class Mcalc 
{
	/** Class MyStack is used as the stack for this program.*/  
	private MyStack myStack;

	/** Class Hashtable is used to store the variables' value. */ 
	private Hashtable hashtable;

  /**
	 * This is the constructor for class Mcalc.
	 * It initializes the stack and the hashtable.
	 */
	public Mcalc()
	{
		myStack = new MyStack();
	  hashtable = new Hashtable();		
	}

	/*
	 * +------------+------------+---------------+-----------------+
	 * |  represent |  Command   |    data       |    variable     |
	 * +------------+------------+---------------+-----------------+
	 * |   number   |     0      |  double type  |  String type    |
	 * |            |            |    number     |    or NULL      |
	 * +------------+------------+---------------+-----------------+
	 * |     [      |     1      |      0.0      |       "["       |
	 * +------------+------------+---------------+-----------------+
	 * |     ]      |     2      |      0.0      |       "]"       |
	 * +------------+------------+---------------+-----------------+
	 * |    id N    |     3      |       N       |    "id " + N    |
	 * +------------+------------+---------------+-----------------+
	 * |     =      |     4      |      0.0      |       "="       |
	 * +------------+------------+---------------+-----------------+
	 * |     +      |     5      |      0.0      |       "+"       |
	 * +------------+------------+---------------+-----------------+
	 * |     -      |     6      |      0.0      |       "-"       |
	 * +------------+------------+---------------+-----------------+
	 * |     /      |     7      |      0.0      |       "/"       |
	 * +------------+------------+---------------+-----------------+
	 * |     *      |     8      |      0.0      |       "*"       |
	 * +------------+------------+---------------+-----------------+
	 * |     _      |     9      |      0.0      |       "_"       |
	 * +------------+------------+---------------+-----------------+
	 * |     t      |     10     |      0.0      |       "t"       |
	 * +------------+------------+---------------+-----------------+
	 * |    inv     |     11     |      0.0      |      "inv"      |
	 * +------------+------------+---------------+-----------------+
	 * |   =: V     |     12     |      0.0      |        V        |
	 * +------------+------------+---------------+-----------------+
	 * |   := V     |     13     |      0.0      |        V        |
	 * +------------+------------+---------------+-----------------+
	 * |  dup / d   |     14     |      0.0      |      "dup"      |
	 * +------------+------------+---------------+-----------------+
	 * |  exch / x  |     15     |      0.0      |      "exch"     |
	 * +------------+------------+---------------+-----------------+
	 * |    pop     |     16     |      0.0      |      "pop"      |
	 * +------------+------------+---------------+-----------------+
	 * |  quit / q  |     17     |      0.0      |      "quit"     |
	 * +------------+------------+---------------+-----------------+
	 * |  help / ?  |     18     |      0.0      |      "help"     |
	 * +------------+------------+---------------+-----------------+
	 */

  /**
	 * This mathod reads commands from the user and does the thing it orders.
	 * If the operator doesn't perform correctly,e.g [ 6 7 ] [ 7 8 ] / <p>
	 * Then this operation would be ignored,and [ 6 7 ] [ 7 8 ] remains in <p>
	 * the stack.<p>
	 * It can distinguish different commands, check the validity and returns
	 * the right answer. <p>
	 * 
	 * Explanations for each command:<p>
	 * NO.0 number: Just push the data into the stack. <p>
	 * NO.1 [: Just push "[" into the stack.  <p>
	 * NO.2 ]: First search for the "[" in the stack. When it is found,pop all the 
	 * objects from the stack until "[" is reached. Then organise the objects,
	 * change them into a matrix object and push back to the stack. Otherwise,
	 * give the error information. <p>
	 * NO.3 id N: if data equals 1 ,just push 1.0f, else if data is positive call
	 * Matrix.identityMatrix() to make the Identity matrix and push it, otherwise
	 * give the error information. <p>
	 * NO.4 =: Pop and print the data on top of the stack when it is not empty, otherwise
	 * give the error information. <p>
	 * No.5 +/ NO.6 -/ NO.7 / /NO.8 * /NO.9 _/ NO.10 t/ NO.11 inv:
	 * Search for "[" in the stack. When finds one gives the error information 
	 * because it is not allowed to do the operation inside the matrix.
	 * Then count the operands in the stack. If it is lower than the required number,
	 * give the error information. Then check whether the operands' types matches. 
	 * At last, call the static method in the class Matrix to do the operation 
	 * and push the result into the stack.<p>
	 * NO.12 =: V :First check the validity of the variable's name. If is invalid,
	 * give the error information.Then pop the value from the stack and store it in
	 * the hashtable together with the variable. If the stack is empty,give the 
	 * error information;  <p>
	 * NO.13 := V : Get the value from the hashtable by the variable. If there
	 * is no one matching the variable,give the error information. <p>
	 * NO.14 dup/d: Check the number of data in the stack. If it is non-zero,peek 
	 * the top value and push it to the stack.Otherwise,give the error information. <P>
	 * NO.15 exch/x :Check the data number in the stack. If it not lower than two,
	 * pop the two value and push them back after exchanging the value. <p>
	 * Otherwise give the error information.<p>
	 * NO.16 pop: Pop the data in the stack. Give the error information when the
	 * stack is empty. <p>
	 * NO.17 quit/q : Quit the program. <p>
	 * NO.18 help/? : Show the help information. <p> 
	 * 
	 * @param command Use the value of this parameter to choose the right 
	 * case for the command.
	 * @param data The data for the command.
	 * @param variable The variable for the command.
	 */
	public void readCommand( int command, double data, String variable )
		throws java.io.IOException
	{
		switch ( command )
		{
		case 0:			
		  myStack.push( new Double( data ));
			break;
		case 1:
			myStack.push( "[" );
			break;
		case 2:
			int index = myStack.search( "[" );
      
		  if ( index != -1 )
		  {
				if ( myStack.peek().getClass() == Double.class )
				{
					boolean isValid = true;
					Double[] elem = new Double[ index ];
					for ( int i = index - 1; i >= 0; i-- )
				  {
					  Object tem = myStack.pop();
						if ( tem.getClass() != Double.class )
						{
							isValid = false;
							break;
						}
						elem[i] = ( Double )tem;
			  	}

			   	if ( isValid )
				  {
						//保持一個數(shù)的float性質(zhì)
						if ( elem.length == 1 )
						{
							myStack.pop();
									
				    	myStack.push( elem[0] );
						}
						else
						{
							Matrix temp = new Matrix( elem );

							myStack.pop();
										
							myStack.push( temp );
						}
				  }

					else 
					{
					  //報錯,因為有非double型的對象。
					  System.out.println( 
							"Error: Elements don't match.Unable to make the matrix." );

						//將棧頂?shù)?quot;["為止的元素全部彈出。
						index = myStack.search( "[" );
						for ( int i = 0; i <= index; i++ )
						{
							myStack.pop();
						}
					}
				}
				else if ( myStack.peek().getClass() == Matrix.class )
				{
					Matrix[] elem = new Matrix[index];
					boolean isValid = true;

          //判斷是否全為行向量,若有數(shù)字或非行向量,則無法形成矩陣。
					//彈出全部直到"["為止。
					for ( int i = index - 1; i >= 0; i-- )
					{
						Object tem = myStack.pop();						
						if ( tem.getClass() != Matrix.class || ((Matrix)tem).row() != 1 )
						{
							isValid = false;		
							break;
						}
						elem[i] = (Matrix)tem;
					}
			  						

					if ( isValid )
					{
						//判斷向量是否可以組成一個矩陣。
						loop:
						{					
							for ( int i = 0; i < elem.length - 1; i++ )
							{
								if ( elem[i].column() != elem[i + 1].column())
								{
									isValid = false;
									break loop;
								}
								if ( elem[i].column() == 1 )
								{
									isValid = false;
									break loop;
								}
							}
						}
					}      					

					if ( isValid )
					{
						//對于元素為一的矩陣數(shù)組保留原樣。即[ [ 5 6 ] ]為[ 5 6 ];
						if ( elem.length == 1 )
						{
							myStack.pop();
							myStack.push( elem[0] );
						}
						else
						{
							Matrix temp = 
								new Matrix( elem.length, elem[0].column(),elem );
							myStack.pop();   //彈出"[".												
							myStack.push( temp );
						}
					}
					else
					{
						//報錯,無法形成正確的矩陣:由于有數(shù)字或矩陣不匹配。
						System.out.println(
							"Error: Elements don't match.Unable to make the matrix." );

						//將棧頂?shù)?quot;["為止的元素全部彈出。
						index = myStack.search( "[" );
						for ( int i = 0; i <= index; i++ )
						{
							myStack.pop();
						}
					}
				}				
		  }
			else
			{
				//報錯 無匹配的"["				
				System.out.println( 
					"Error: No \"[\" matches this \"]\".Unable to make the matrix." );
			}
			break;
		case 3:
			int matchIden = myStack.search( "[" );
		  if ( matchIden == -1 )
		  {
				if ( data == 1 )
				{
					myStack.push( new Double( 1 ) );
				}
				else if ( data > 1 )
				{
					myStack.push( Matrix.identityMatrix((int)data ) );
				}
				else
				{
					//因為非正整數(shù),報錯
					System.out.println( "Error: N can't be negative!" );
				}
			}
			else
			{
				System.out.println( 
					"Error: Unable to do the operation inside the matrix!" );			
			}			
			break;
		case 4:
			if ( myStack.size() == 0 )
			{
			   System.out.println( "Error: Stack is empty!" );
			}
			else
			{
				Object result = myStack.pop();
				
				if ( result.getClass() == Double.class )
				{
					System.out.println( result );
				}
				else if ( result.getClass() == Matrix.class )
				{
					System.out.println( Matrix.toString((Matrix)result ) );
				}
			}
			break;
	  case 5:
			int matchAdd = myStack.search( "[" );
		  if ( matchAdd == -1 )
		  {
				if ( myStack.size() >=2 )
				{
					Object number1 = myStack.pop();
					Object number2 = myStack.pop();				

					if ( number1.getClass() == Double.class )
					{
						double num1 = ((Double)number1).doubleValue();
						if ( number2.getClass() == Double.class )
						{
							double num2 = ((Double)number2).doubleValue();						
							myStack.push( Matrix.add( num2,num1)); 
						}
						else
						{
							//矩陣與數(shù)字無法運算。
							//保持原來的狀態(tài)。
              myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the addition!" );
						}
					}
					else
					{
						Matrix num1 = ( Matrix )number1;
						
						if ( number2.getClass() != Double.class )
						{
							Matrix num2 = ( Matrix )number2; 	
							Matrix result = Matrix.add( num2,num1 );
							if ( result != null )
							{
								myStack.push( result );
							}						
						}	
						else
						{
							//矩陣與數(shù)字無法運算。
							myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the addition!" );
						}
					}				
				}
				else
				{
					//運算數(shù)字個數(shù)不足。
					System.out.println( 
						"Error: There aren't enough operands for addition!" );					
				}
		  }
			else
			{
				System.out.println( 
					"Error: Unable to do the addition inside the matrix!" );				
			}			
			break;
		case 6:
			int matchMinus = myStack.search( "[" );
		  if ( matchMinus == -1 )
		  {
				if ( myStack.size() >=2 )
				{
					Object number1 = myStack.pop();
					Object number2 = myStack.pop();

					if ( number1.getClass() == Double.class )
					{
						double num1 = ((Double)number1).doubleValue();
						if ( number2.getClass() == Double.class )
						{
							double num2 = ((Double)number2).doubleValue();
							myStack.push( Matrix.minus( num2,num1)); 
						}
						else
						{
							//矩陣與數(shù)字無法運算。
							myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the subtraction!" );
						}
					}
					else
					{
						Matrix num1 = ( Matrix )number1;
						if ( number2.getClass() == Matrix.class )
						{
							Matrix num2 = ( Matrix )number2; 
							Matrix result = Matrix.minus( num2,num1 );
							if ( result != null )
							{
								myStack.push( result );
							}						
						}	
						else
						{
							//矩陣與數(shù)字無法運算。
							myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the subtraction!" );
						}
					}				
				}
				else
				{
					//運算數(shù)字個數(shù)不足。
					System.out.println( 
						"Error: There aren't enough operands for subtraction!" );				
				}
			}
			else
			{
				System.out.println( 
					"Error: Unable to do the subtraction inside the matrix!" );				
			}		
			break;
		case 7:
			int matchDiv = myStack.search( "[" );
		  if ( matchDiv == -1 )
		  {
				if ( myStack.size() >=2 )
				{
					Object number1 = myStack.pop();
					Object number2 = myStack.pop();

					if ( number1.getClass() == Double.class )
					{
						double num1 = ((Double)number1).doubleValue();
						if ( num1 != 0 )
						{
							if ( number2.getClass() == Double.class )
							{
								double num2 = ((Double)number2).doubleValue();
								myStack.push( Matrix.divide( num2,num1)); 
							}
							else if( number2.getClass() == Matrix.class )
							{
								Matrix num2 = ( Matrix )number2;
								myStack.push( Matrix.divide( num2,num1 ));
							}			
						}
						else
						{
							//除零錯誤。
							System.out.println( "Error: Can't divide by 0!" );
						}
								
					}
					else
					{
						//矩陣與數(shù)字無法運算。
						myStack.push( number2 );
						myStack.push( number1 );

						System.out.println(
								"Error: The two operands don't match. Can't do the division." );
					}				
				}
				else
				{
					//運算數(shù)字個數(shù)不足。
					System.out.println( 
						"Error: There aren't enough operands for division!" );				
				}
			}
			else
			{
				System.out.println( 
					"Error: Unable to do the division inside the matrix!" );				
			}	

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩午夜av一区| 99久久er热在这里只有精品66| 欧美日韩视频不卡| 亚洲理论在线观看| 91在线精品一区二区| 亚洲日穴在线视频| 波多野结衣中文字幕一区二区三区| 国产精品久久久久婷婷二区次| 懂色av一区二区夜夜嗨| 国产精品国产精品国产专区不蜜| 99久久综合99久久综合网站| 亚洲少妇30p| 精品视频1区2区3区| 奇米影视一区二区三区小说| 精品国产91久久久久久久妲己| 国产一区二区三区高清播放| 国产精品久久久久久久久久免费看| 99久久婷婷国产综合精品电影| 亚洲制服丝袜av| 日韩欧美在线网站| 成人精品视频一区| 亚洲成人综合在线| 精品国产一区a| 成人18视频日本| 午夜精品福利在线| 国产女人18毛片水真多成人如厕| 一本到一区二区三区| 秋霞电影网一区二区| 欧美国产精品一区| 欧美久久久久免费| 国产高清不卡一区二区| 亚洲综合色区另类av| ww久久中文字幕| 一本大道av伊人久久综合| 久久精品国产精品青草| 亚洲欧美一区二区三区久本道91| 欧美精品18+| www.亚洲国产| 老司机午夜精品| 亚洲视频免费在线| 精品捆绑美女sm三区| 91精品办公室少妇高潮对白| 精品午夜久久福利影院| 亚洲一区二区三区免费视频| 久久免费视频色| 欧美日韩国产首页| 99在线精品免费| 精品在线播放免费| 亚洲一区二区三区自拍| 亚洲国产高清不卡| 日韩美女一区二区三区四区| 色噜噜久久综合| 成人av电影在线| 国产一区二区三区久久悠悠色av| 五月天久久比比资源色| 亚洲人成影院在线观看| 国产亚洲制服色| 欧美xxxxx牲另类人与| 欧美日韩国产三级| 日本韩国一区二区三区| 成人黄色av网站在线| 激情成人综合网| 免费看日韩精品| 亚洲曰韩产成在线| 亚洲免费观看高清完整版在线观看| 亚洲精品一区二区三区蜜桃下载| 欧美精品第一页| 欧美视频在线一区| 91国产视频在线观看| 丁香另类激情小说| 国产精品456| 激情文学综合插| 麻豆一区二区三| 日本va欧美va瓶| 日韩国产欧美视频| 婷婷综合五月天| 亚洲18影院在线观看| 亚洲韩国一区二区三区| 一区二区三区加勒比av| 一个色综合网站| 玉米视频成人免费看| 亚洲精品大片www| 亚洲综合激情网| 亚洲一级二级在线| 亚洲18色成人| 日本不卡在线视频| 免费国产亚洲视频| 精东粉嫩av免费一区二区三区| 美女看a上一区| 激情六月婷婷久久| 国产成人av一区二区三区在线| 国产精品一区久久久久| 粉嫩一区二区三区在线看| 成人av在线一区二区三区| 97久久超碰国产精品| 99久久99久久免费精品蜜臀| 色伊人久久综合中文字幕| 欧美亚洲自拍偷拍| 日韩区在线观看| 久久久久久久久蜜桃| 国产精品成人免费在线| 亚洲亚洲人成综合网络| 日韩国产高清在线| 国产精品自拍av| 成人黄色免费短视频| 欧美亚洲国产一区二区三区 | 不卡大黄网站免费看| 色综合色综合色综合| 欧美三级三级三级| 精品入口麻豆88视频| 国产精品午夜在线观看| 亚洲国产色一区| 精品亚洲成a人在线观看| 99在线精品观看| 欧美日本精品一区二区三区| 久久综合五月天婷婷伊人| 国产精品毛片久久久久久久| 亚洲超碰精品一区二区| 国产伦理精品不卡| 欧洲一区二区av| 精品国产91洋老外米糕| 亚洲免费观看在线视频| 激情伊人五月天久久综合| 91麻豆国产精品久久| 91精品国产乱码| 中文字幕一区二区三区在线播放 | 欧美三级三级三级| 久久香蕉国产线看观看99| 亚洲欧美国产三级| 国内精品久久久久影院一蜜桃| 色哟哟一区二区三区| 久久综合久久99| 一区二区三区国产| 国产69精品久久久久777| 欧美日韩免费高清一区色橹橹| 国产精品免费视频观看| 蜜臀久久99精品久久久久久9| 99精品国产视频| 精品福利一二区| 亚洲成人免费观看| 91同城在线观看| 久久久精品免费网站| 日韩高清在线一区| 欧洲精品在线观看| 国产精品久久久久久久久动漫 | 日韩精品一区二区在线| 亚洲激情在线播放| 成人激情免费视频| 久久嫩草精品久久久久| 美女免费视频一区| 在线播放亚洲一区| 亚洲国产视频一区| 一本色道久久综合亚洲aⅴ蜜桃| 亚洲国产岛国毛片在线| 国模套图日韩精品一区二区| 777精品伊人久久久久大香线蕉| 亚洲男女一区二区三区| 成人动漫中文字幕| 国产女人aaa级久久久级| 国产一区视频在线看| 精品日韩欧美在线| 蜜臀91精品一区二区三区 | 一区视频在线播放| 国产成人在线视频网站| 精品国产乱码久久| 国产在线精品一区二区夜色| 日韩一区二区三区四区五区六区| 午夜av一区二区三区| 欧美熟乱第一页| 五月婷婷色综合| 555www色欧美视频| 日韩高清欧美激情| 日韩精品中文字幕一区 | 欧美一卡在线观看| 七七婷婷婷婷精品国产| 日韩亚洲欧美成人一区| 伦理电影国产精品| 精品裸体舞一区二区三区| 国产一区在线视频| 国产精品欧美精品| 91丝袜呻吟高潮美腿白嫩在线观看| 《视频一区视频二区| 日本电影欧美片| 亚洲国产婷婷综合在线精品| 欧美精品久久久久久久久老牛影院| 日韩av网站在线观看| 精品国产一区a| 成人一道本在线| 亚洲猫色日本管| 欧美精品高清视频| 国产精品一级黄| 亚洲欧洲精品成人久久奇米网| 色先锋资源久久综合| 午夜精品成人在线视频| 欧美成人午夜电影| 成人av小说网| 亚洲成人黄色影院| wwww国产精品欧美| 色婷婷亚洲精品| 成人黄页毛片网站|