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

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

?? mcalc.java

?? 用java實(shí)現(xiàn)浮點(diǎn)數(shù)加減乘除四則混合運(yùn)算
?? JAVA
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
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 )
				  {
						//保持一個(gè)數(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 
					{
					  //報(bào)錯(cuò),因?yàn)橛蟹莇ouble型的對(duì)象。
					  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ù)字或非行向量,則無(wú)法形成矩陣。
					//彈出全部直到"["為止。
					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 )
					{
						//判斷向量是否可以組成一個(gè)矩陣。
						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 )
					{
						//對(duì)于元素為一的矩陣數(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
					{
						//報(bào)錯(cuò),無(wú)法形成正確的矩陣:由于有數(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
			{
				//報(bào)錯(cuò) 無(wú)匹配的"["				
				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
				{
					//因?yàn)榉钦麛?shù),報(bào)錯(cuò)
					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ù)字無(wú)法運(yùn)算。
							//保持原來(lái)的狀態(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ù)字無(wú)法運(yùn)算。
							myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the addition!" );
						}
					}				
				}
				else
				{
					//運(yùn)算數(shù)字個(gè)數(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ù)字無(wú)法運(yùn)算。
							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ù)字無(wú)法運(yùn)算。
							myStack.push( number2 );
							myStack.push( number1 );

							System.out.println(
								"Error: Matrix and number can't do the subtraction!" );
						}
					}				
				}
				else
				{
					//運(yùn)算數(shù)字個(gè)數(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
						{
							//除零錯(cuò)誤。
							System.out.println( "Error: Can't divide by 0!" );
						}
								
					}
					else
					{
						//矩陣與數(shù)字無(wú)法運(yùn)算。
						myStack.push( number2 );
						myStack.push( number1 );

						System.out.println(
								"Error: The two operands don't match. Can't do the division." );
					}				
				}
				else
				{
					//運(yùn)算數(shù)字個(gè)數(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!" );				
			}	

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99免费精品在线| 国产精品中文字幕一区二区三区| 777a∨成人精品桃花网| 国产aⅴ综合色| 日韩高清不卡一区| 亚洲视频中文字幕| 精品对白一区国产伦| 欧美性猛片aaaaaaa做受| 狠狠狠色丁香婷婷综合激情 | 日韩精品最新网址| 色婷婷国产精品综合在线观看| 国产曰批免费观看久久久| 亚洲一区二区三区在线播放| 中文字幕国产一区| 精品国偷自产国产一区| 国产网站一区二区| 亚洲精品在线网站| 国产欧美1区2区3区| 日韩精品在线看片z| 久久色.com| 欧美成人综合网站| 欧美一区二区性放荡片| 欧美视频一区二区在线观看| 欧美精品亚洲一区二区在线播放| 91理论电影在线观看| 不卡欧美aaaaa| 成人一区二区在线观看| 国产精品中文字幕日韩精品 | 一本大道综合伊人精品热热| 欧美亚洲国产一卡| 欧美一区二区三区喷汁尤物| 久久久久久久久一| 久久久久久综合| 亚洲视频 欧洲视频| 同产精品九九九| 日韩电影在线观看网站| 国产一区二区在线看| jlzzjlzz亚洲女人18| 欧美日韩一区二区三区在线看| 在线看国产一区二区| 91黄色免费观看| 欧美三级视频在线| 久久亚洲欧美国产精品乐播 | 麻豆精品在线播放| 激情综合色播激情啊| 99久久亚洲一区二区三区青草 | 久久综合成人精品亚洲另类欧美 | 欧美96一区二区免费视频| 日韩国产高清在线| 国产白丝精品91爽爽久久| 欧美专区日韩专区| 26uuu国产电影一区二区| 亚洲免费观看高清完整版在线观看| 国产精品久久99| 亚洲综合在线观看视频| 一级女性全黄久久生活片免费| 久久精品国产一区二区三区免费看| 韩国成人福利片在线播放| 91久久精品午夜一区二区| 久久精品人人做| 日韩成人午夜精品| 日本精品一区二区三区高清 | 亚洲国产成人av好男人在线观看| 亚洲va欧美va天堂v国产综合| 日本不卡的三区四区五区| 成人黄色免费短视频| 欧美一级二级三级蜜桃| 国产日韩在线不卡| 日韩精品福利网| 国产91精品欧美| 日韩欧美在线观看一区二区三区| 亚洲人成影院在线观看| 国产精品亚洲专一区二区三区| 欧美精品一二三| 亚洲精品亚洲人成人网在线播放| 日韩高清欧美激情| 在线观看三级视频欧美| 国产精品水嫩水嫩| 天堂va蜜桃一区二区三区漫画版| 91色porny| 国产亚洲欧美日韩日本| 蜜桃视频在线观看一区二区| 欧美日本不卡视频| 中文字幕va一区二区三区| 九色|91porny| 欧美在线短视频| 日韩毛片在线免费观看| 成人深夜福利app| 国产亚洲成aⅴ人片在线观看| 激情小说亚洲一区| 精品久久久久香蕉网| 美女脱光内衣内裤视频久久网站 | 国产三级三级三级精品8ⅰ区| 免费一区二区视频| 91精品国产麻豆国产自产在线| 亚洲亚洲精品在线观看| 色美美综合视频| 亚洲自拍另类综合| 99久久99久久免费精品蜜臀| 中文字幕一区二区在线观看| 精品一区二区在线播放| 欧美xfplay| 国产一区二区三区最好精华液| 精品国产91久久久久久久妲己| 麻豆精品国产传媒mv男同| 日韩精品一区二区三区在线播放 | caoporn国产精品| 国产精品麻豆视频| av在线一区二区| 亚洲日本va午夜在线影院| 日本道色综合久久| 天天色天天操综合| 91精品国产综合久久精品app | 欧美在线色视频| 午夜欧美大尺度福利影院在线看| 欧美乱妇一区二区三区不卡视频| 图片区小说区区亚洲影院| 日韩午夜在线观看| 国产美女一区二区| 国产欧美一区二区精品性色 | 国产日产亚洲精品系列| 国产91精品一区二区| 日韩一区欧美小说| 欧美色综合网站| 日本人妖一区二区| 久久婷婷成人综合色| 99久久精品国产导航| 亚洲一区二区五区| 日韩视频免费直播| 成人小视频免费观看| 亚洲精品欧美在线| 555www色欧美视频| 国产精品 欧美精品| 欧美精品一区二区三区视频| 国产成人在线免费| 亚洲一区二区三区影院| 日韩一级黄色片| 成人做爰69片免费看网站| 一区二区国产视频| 日韩精品一区二区三区视频在线观看 | 麻豆一区二区三| 精品国产伦一区二区三区观看体验| 加勒比av一区二区| 成人免费在线观看入口| 欧美精品乱码久久久久久按摩| 精品亚洲免费视频| 综合色天天鬼久久鬼色| 日韩一区二区影院| 成人精品电影在线观看| 婷婷久久综合九色国产成人 | 亚洲第一福利一区| 久久亚洲精品国产精品紫薇| 色哟哟日韩精品| 麻豆91精品91久久久的内涵| 国产精品短视频| 日韩欧美一级二级三级| 一本一本大道香蕉久在线精品| 蜜桃视频在线一区| 一区二区三区**美女毛片| 国产亚洲精久久久久久| 在线成人午夜影院| 成人a免费在线看| 久久国产视频网| 夜夜嗨av一区二区三区网页 | 国产精品美女久久久久aⅴ| 欧美精品九九99久久| 9l国产精品久久久久麻豆| 蜜芽一区二区三区| 亚洲精品高清在线观看| 久久久亚洲精品石原莉奈| 欧美日韩美女一区二区| av资源网一区| 国内精品免费在线观看| 视频在线在亚洲| 有码一区二区三区| 欧美国产丝袜视频| 欧美电视剧免费全集观看| 91官网在线观看| 99久久综合精品| 国产精品一区在线观看乱码| 日韩激情视频网站| 亚洲亚洲人成综合网络| 亚洲欧美成aⅴ人在线观看| 久久久不卡影院| 日韩欧美电影在线| 欧美一区午夜精品| 欧美精品日韩一本| 欧美亚洲自拍偷拍| 99re6这里只有精品视频在线观看| 国产成人综合在线| 国产精品99久久久久| 激情国产一区二区 | 欧美一激情一区二区三区| 色欧美日韩亚洲| 色94色欧美sute亚洲线路一久| 成人午夜激情在线| 成熟亚洲日本毛茸茸凸凹| 国产成人一级电影| 成人三级在线视频| 国产999精品久久久久久 |