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

📄 newclass.java

📁 人工智能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            str = "验证不成功! 您要验证的动物不是" +"\""+x.getName().name +"\""+ "!";        }		System.out.println(str);	}	// 推理机	public void reasoning(AnimalDataBase x) {		introduce();		step1();		step2(x);	}}/////******************************************/////////////////////////////////////////////////////定义可以(反向)推理的推理机class Reasoning1{	String name = "";      // 动物名称	String YorN = "";      // 判断	private int id_R = 0;  // 下一步推理序号	private int id_Kind3 = 1;// 要输出的三级属性的序号	public Reasoning1()    {	}	// 系统介绍   private void introduce()    {		String str1;		str1 = "\nA猎豹, B老虎,C长颈鹿 , D斑马, E鸵鸟, F企鹅, G海燕\n"				+ "请输入您要(反向推理)动物编号并按回车键结束\n:";		System.out.println(str1);	}	// 用户输入方法	private String inPut()    {		String s = "";		try        {			BufferedReader stdin = new BufferedReader(new InputStreamReader(					System.in));			s = stdin.readLine();		} catch (IOException e)        {			e.printStackTrace();		}		return s;	}	// 二号方案,三级属性输出方法。	private boolean outPut(AnimalDataBase1 x)    {		String str = "动物特性是否满足?(确认请输入‘YES’,'NO'请回车!)\n";		if (id_Kind3 < x.MAXSIZE)        {			while (x.kind3[id_Kind3].kind3 != EnumKinds.kind3.空类)            {				str += x.kind3[id_Kind3++].kind3 + ";";			}			System.out.println(str);			return true;		}		return false;	}	// 对输出的三级属性的回复做出判断	private boolean judge(AnimalDataBase1 x)    {		if (outPut(x) == true)        {			YorN = inPut();			if (YorN.equals("YES")) {                return true;            }			else {                return false;            }		}		return false;	}	// 请用户输入动物名称	private void step1()    {		name = inPut();         //name是字符串变量。		boolean flag = false;		while (!flag)        {			flag = true;			if (name.equals("A")) //A猎豹            {                id_R = 9;            }			else if (name.equals("B")) //B老虎            {                id_R = 10;            }			else if (name.equals("C")) //C长颈鹿            {                id_R = 11;            }			else if (name.equals("D")) //D斑马            {                id_R = 12;            }			else if (name.equals("E")) //E鸵鸟            {                id_R = 13;            }			else if (name.equals("F"))//F企鹅            {                id_R = 14;            }			else if (name.equals("G")) //G海燕            {                id_R = 15;            }			else            {				name = "";				flag = false;				System.out.println("请输入大写字母:");				name = inPut();			}		}	}	// 对用户输入动物进行推理	private void step2(AnimalDataBase1 x)    {//		int m1 = 1;//		int m2 = 11;//		int m3 = 21;		boolean end = false;//验证正确标志。正确时end=true		while (id_R != 0)        {			switch (id_R)            {			case 1:            {                x.setKind3(EnumKinds.kind3.黑色条纹);//				x.setKind3(EnumKinds.kind3.有毛发);//                x.setKind3(EnumKinds.kind3.吃肉);////                x.setKind3(EnumKinds.kind3.有利齿);//                x.setKind3(EnumKinds.kind3.有毛发);////                x.setKind3(EnumKinds.kind3.有长爪);//                x.setKind3(EnumKinds.kind3.深色斑点);////                x.setKind3(EnumKinds.kind3.眼睛前视);//                x.setKind3(EnumKinds.kind3.能产乳);//                x.setKind3(EnumKinds.kind3.黄褐色);                           				if (judge(x))                {					id_R = 0;					end = true;				 } else {                    id_R = 2;                }				// y.R1(x);				break;			  }			case 2:            {				x.setKind3(EnumKinds.kind3.能产乳);				if (judge(x)) {                    end = true;                }				id_R = 0;				// y.R2(x);				break;			}			case 3:            {				x.setKind2(EnumKinds.kind2.鸟类);                System.out.println("鸟");				if (judge(x))                {					id_R = 4;									} else {                    id_R=0;//鸟类                }				// y.R3(x);				break;			}			case 4:            {				x.setKind3(EnumKinds.kind3.有羽毛);				x.setKind3(EnumKinds.kind3.能生蛋);				if (judge(x)) {                    id_R=6;                                    }                else{                    id_R=0;                     //鸟类                }				// y.R14(x);				break;			}			case 5:            {      /*有毛发,                   能产乳,             //哺乳                     眼睛前视,*/     			x.setKind3(EnumKinds.kind3.有毛发);                x.setKind3(EnumKinds.kind3.能产乳);                x.setKind3(EnumKinds.kind3.眼睛前视);               							if (judge(x)) {                    id_R = 16;                }				else {                    id_R = 0;//哺乳动物                }				// y.R5(x);				break;			}			case 6:            {								x.setKind3(EnumKinds.kind3.能飞行);                x.setKind3(EnumKinds.kind3.善于飞行);				if (judge(x)) {                    id_R = 0;                    end=true; //海燕                }				else {                    id_R = 0;//鸵鸟。企鹅                    end=true;                }								break;			}			case 7:            {				x.setKind2(EnumKinds.kind2.有蹄动物);                System.out.println("有蹄动物");				if (judge(x)) {                    id_R = 17;                }				else {                    id_R = 8;                }				// y.R7(x);				break;			}			case 8:            {				x.setKind3(EnumKinds.kind3.反刍);				if (judge(x)) {                    id_R = 1;                }				else {                    id_R = 0;                }				// y.R8(x);				break;			}			case 9:            {				x.setName(EnumKinds.name.猎豹);				x.setKind1(EnumKinds.kind1.哺乳动物);                System.out.println("哺乳动物");				// System.out.println(x.kind3[1].kind3+x.kind3[2].kind3.toString());				if (judge(x)) {                    id_R = 5;                }				else {                    id_R = 0;                }				break;			}			case 10:            {				x.setName(EnumKinds.name.老虎);				x.setKind1(EnumKinds.kind1.哺乳动物);				System.out.println("哺乳动物");				if (judge(x)) {                    id_R = 5;                }				else {                    id_R = 0;                }				// y.R10(x);				break;			}			case 11:            {				x.setName(EnumKinds.name.长颈鹿);     			x.setKind1(EnumKinds.kind1.哺乳动物);                System.out.println("哺乳动物");				if (judge(x)) {                    id_R = 5;                }				else {                    id_R = 0;                }				// y.R11(x);				break;			}			case 12:            {				x.setName(EnumKinds.name.斑马);				x.setKind1(EnumKinds.kind1.哺乳动物);                System.out.println("哺乳动物");				if (judge(x)) {                    id_R = 5;                }				else {                    id_R = 0;                }				// y.R12(x);				break;			}			case 13:            {				x.setName(EnumKinds.name.鸵鸟);                x.setKind1(EnumKinds.kind1.鸟类动物);                System.out.println("鸟类动物");//				x.setKind3(EnumKinds.kind3.有长腿);//				x.setKind3(EnumKinds.kind3.有长颈);//				x.setKind3(EnumKinds.kind3.黑色与白色相杂);				if (judge(x)) {                    id_R = 3;                }				else {                    id_R = 0;                }				// y.R13(x);				break;			}			case 14:            {				x.setName(EnumKinds.name.企鹅);                x.setKind1(EnumKinds.kind1.鸟类动物);                System.out.println("鸟类动物");//				x.setKind3(EnumKinds.kind3.能游泳);//				x.setKind3(EnumKinds.kind3.有长颈);//				x.setKind3(EnumKinds.kind3.黑色与白色);				if (judge(x)) {                    id_R = 3;                }				else {                    id_R = 0;                }				// y.R14(x);				break;			}			case 15:            {				x.setName(EnumKinds.name.海燕);				x.setKind1(EnumKinds.kind1.鸟类动物);                System.out.println("鸟类动物");				// y.R15(x);				if (judge(x)) {                    id_R = 3;                }				else {                    id_R = 0;                }				break;			}            case 16:            {/*				有长爪,有利齿,    / /食肉吃肉*/                x.setKind3(EnumKinds.kind3.有长爪);                x.setKind3(EnumKinds.kind3.吃肉);                x.setKind3(EnumKinds.kind3.有利齿);  				if (judge(x)) {                                    id_R = 19;                                   }				else {                    id_R = 21;//有蹄                }				// y.R10(x);				break;			}            case 17:            {//				x.setName(EnumKinds.name.长颈鹿);				x.setKind3(EnumKinds.kind3.有长腿);				x.setKind3(EnumKinds.kind3.有长颈);				x.setKind3(EnumKinds.kind3.黄褐色);				x.setKind3(EnumKinds.kind3.深色斑点);                x.setKind3(EnumKinds.kind3.反刍);                x.setKind3(EnumKinds.kind3.有毛发);                x.setKind3(EnumKinds.kind3.能产乳);                                                                				if (judge(x)) {                    id_R = 0;                    end = true;                }				else {                    id_R = 0;                }				// y.R11(x);				break;			}                        case 19:               {                x.setKind3(EnumKinds.kind3.黑色条纹);          				if (judge(x))                 {                    id_R = 0;                    end=true; //虎                 }                else{                    id_R=20;//包                }               				// y.R10(x);				break;                                    }            case 20:               {                x.setKind3(EnumKinds.kind3.黄褐色);                x.setKind3(EnumKinds.kind3.深色斑点);                				if (judge(x) )                {                    id_R = 0;//包                    end=true;                }                else{                }											break;                }            case 21:               {/*有蹄,                      //有蹄,                    黑色与白色相杂,                    有长腿,                    黑色与白色,                    白色, */                x.setKind3(EnumKinds.kind3.有蹄);                x.setKind3(EnumKinds.kind3.有长腿);                x.setKind3(EnumKinds.kind3.白色);                x.setKind3(EnumKinds.kind3.黑色与白色相杂);                x.setKind3(EnumKinds.kind3.黑色与白色);              				if (judge(x)) {                                 id_R = 22;                                    }                else                {                    id_R=0;                    end=true;//斑马                }				// y.R10(x);				break;                }            case 22:               {                   x.setKind3(EnumKinds.kind3.有长颈);                   x.setKind3(EnumKinds.kind3.反刍);              				if (judge(x)) {                    id_R = 0;                    end=true; //长胫鹿                }								// y.R10(x);				break;                }            case 23:               {                     x.setKind3(EnumKinds.kind3.吃肉);              				if (judge(x)) {                    id_R = 24;                                  }								// y.R10(x);				break;                }                                                  			}// switch		}// while		// 结果判定		String str;		if (id_R == 0 && end == true) {           str = "反向推理成功! 您要验证的动物是" +"\""+x.getName().name+"\"" + "!";        //    str = "反向推理成功!";        }		else {  //         str = "反向推理不成功!! 您要验证的动物不是" +"\""+x.getName().name +"\""+ "!";            str = "反向推理不成功!";        }		System.out.println(str);	}	// 推理机	public void reasoning1(AnimalDataBase1 x) {		introduce();		step1();		step2(x);	}}////////////////////////////////////////////////////主程序public class NewClass{    private String inPut()    {		String s = "";		try{			BufferedReader stdin = new BufferedReader(new InputStreamReader(					System.in));			s = stdin.readLine();		}        catch (IOException e){			e.printStackTrace();		}		return s;	}   public static void main(String[] args)    {        long  step=0;        String choose = "";        System.out.print("你想要正向推理还是反向推理?请选择编号.\n ");        System.out.print("A正向推理,B反向推理\n\n");        try{			BufferedReader stdin = new BufferedReader(new InputStreamReader(					System.in));			choose = stdin.readLine();		}        catch (IOException e){			e.printStackTrace();		}        if(choose.equals("A")){//正向推理。            AnimalDataBase animal = new AnimalDataBase();            Reasoning reasoning=new Reasoning();            reasoning.reasoning(animal);        }        else{//反向推理.            if(choose.equals("B"))            {              //                System.out.println(//                        " a有毛发,  b有长爪, c有利齿, d有羽毛,  e有蹄,  f有长腿,g深色斑点\n" +//                        " h有长颈,  i能产乳, k能生蛋, l能飞行, m能游泳, n吃肉,o黑色与白色\n" +//                        " p反刍,q眼睛前视,r黄褐色,s白色,t黑色与白色相杂,u黑色条纹,v善于飞行\n");                //////////////////////////////////////////////                System.out.print("请选择附合你的选项编号.\n ");            //                try{//                    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));//                    choose = stdin.readLine();//                    }//                catch (IOException e)//                    {//                        e.printStackTrace();//                    }                ////////////////////////////////////////////               AnimalDataBase1 animal = new AnimalDataBase1();               Reasoning1 reasoning1=new Reasoning1();               reasoning1.reasoning1(animal);               //////////////////////////////////////////              /*                 switch(Integer.getInteger(choose))                  {                    case 1:                  }              */              ////////////////////////////////////////////            }//else{//反向推理.             //     if(choose.equals("B"))        }       			}}

⌨️ 快捷键说明

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