我写的第一个小的程序

原创 2007年09月29日 10:54:00

  我学习JAVA来写的第一个小的程序,这个程序主要是识别7种不同的动物,程序采用问答式运行,希望大家欣赏,给点意见。

import java.awt.*;
import java.lang.*;
import java.io.*;
/*import java.applet.Applet;*/
public class AnimalIdentify {
 /* 数据Boolean 类定义*/
 boolean mammal,aves,carnivore,ungulate;
 boolean hair,feather,claw,sharpTooth,hoof,cloot,longLeg,longNeck;
 boolean galactopoiesis,fly,layEgg,eatMeat,ruminate,eyeFrontad,notFly,swimming,beGoodAtFly;
 boolean snuffColor,fuscousFleck,blackStripe,white,blackAndWhite;
 boolean leopard,tiger,zebra,giraffe,ostrich,penguin,salangane;     
 /* 数据初始化*/   
 public AnimalIdentify(){
  mammal=aves=carnivore=ungulate=true;
  hair=feather=claw=sharpTooth=hoof=cloot=longLeg=longNeck=false;
  galactopoiesis=fly=layEgg=eatMeat=ruminate=eyeFrontad=notFly=swimming=beGoodAtFly=false;
  snuffColor=fuscousFleck=blackStripe=white=blackAndWhite=false;
  leopard=tiger=zebra=giraffe=ostrich=penguin=salangane=false;
 }
 /* 规则定义*/
 public boolean rule1 (boolean hair){
  if (hair)
  System.out.println("The animal is a mammal");
  return  mammal;
 }
 

 public boolean rule2(boolean galactopoiesis){
  if (galactopoiesis)
  System.out.println("The animal is a mammal");
  return mammal;
 }
 public boolean rule3(boolean feather){
  if(feather)
  System.out.println("The animal is an aves");
  return aves;
 }
 public boolean rule4(boolean fly, boolean layEgg){
  if (fly&&layEgg)
  System.out.println("The animal is an aves");
  return aves;
 }
 public boolean rule5(boolean mammal, boolean eatMeat){
  if (mammal&&eatMeat)
  System.out.println("The animal is a carnivore");
  return carnivore;
 }
 public boolean rule6(boolean mammal,boolean claw,boolean sharpTooth ,boolean eyeFrontad){
  if (mammal&&claw&&sharpTooth&&eyeFrontad)
  System.out.println("The animal is a carnivore");
  return carnivore;
 }
 public boolean rule7(boolean mammal,boolean hoof){
  if (mammal&&hoof)
  System.out.println("The animal is a ungulate");
  return ungulate;
 }
 public boolean rule8(boolean mammal,boolean ruminate){
  if(mammal&&ruminate)
  System.out.println("The animal is ungulate and cloot");
  return cloot;
 }
 public boolean rule9(boolean carnivore,boolean snuffColor,boolean fuscousFleck){
  if(carnivore&&snuffColor&&fuscousFleck)
  System.out.println("The animal is a leopard");
  return leopard;
 }
 public boolean rule10(boolean carnivore,boolean snuffColor,boolean blackStripe){
  if (carnivore&&snuffColor&&blackStripe)
  System.out.println("The animal is a tiger");
  return tiger;
 }
    public boolean rule11(boolean ungulate,boolean longLeg,boolean longNeck,boolean snuffColor,boolean fuscousFleck){
     if(ungulate&&longLeg&&longNeck&&snuffColor&&fuscousFleck)
     System.out.println("The animal is a giraffe");
     return giraffe;
    }
    public boolean rule12(boolean ungulate,boolean white,boolean blackStripe){
     if (ungulate&&white&&blackStripe)
     System.out.println("The animal is a zebra");
     return zebra;
    }
    public boolean rule13(boolean aves,boolean notFly,boolean longLeg,boolean longNeck,boolean blackAndWhite){
     if (aves&&notFly&&longLeg&&longNeck&&blackAndWhite)
     System.out.println("The animal is ostrich");
     return ostrich;
    }
    public boolean rule14(boolean aves,boolean notFly,boolean swimming,boolean blackAndWhite){
     if (aves&&notFly&&swimming&&blackAndWhite)
     System.out.println("The animal is a penguin");
     return penguin;
    }
    public boolean rule15(boolean aves,boolean beGoodAtFly){
     if (aves&&beGoodAtFly)
     System.out.println("The animal is a salangane");
     return salangane;
    }
   
   
    /*规则查询分析*/
    public void queryUseRule( ){
     
     System.out.println("please in your complexion about the animal");
     System.out.println("the animal doesn't have hair? In(Y/N)");
        try {
         BufferedInputStream st1= new BufferedInputStream (System.in);
         if(st1.read( )==(int)('Y')){
         hair=true;
        rule1(hair);}
       }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }

     
     System.out.println("continue observe");
     System.out.println("the animal isn't galactopoiesis? In(Y/N)");
     try {
      BufferedInputStream st1= new BufferedInputStream (System.in);
      if(st1.read( )==(int)('Y')){
           galactopoiesis=true;
         rule2(galactopoiesis);
              }
       }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }

     
     System.out.println("continue observe");
     System.out.println("the animal doesn't have feather? In(Y/N)");
     try {
      BufferedInputStream st1= new BufferedInputStream (System.in);
      if (st1.read( )==(int)('Y')){
          feather=true;
             rule3(feather);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal doesn't fly? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      boolean t4_1=st1.read()==(int)('Y');
            System.out.println("the animal doesn't layegg? In(Y/N)");
            boolean t4_2=st2.read()==(int)('Y');
           
            if(t4_1&&t4_2) {
            fly=true; layEgg=true;
            rule4(fly,layEgg);
        }
        }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
       
       
     System.out.println("continue observe");
     System.out.println("the animal isn't mammal? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      boolean t5_1=st1.read()==(int)('Y');
         System.out.println("the animal doesn't eatMeet? In(Y/N)");
         boolean t5_2=st2.read()==(int)('Y');
  
         if (t5_1&&t5_2){
          mammal=true; eatMeat=true;
          rule5(mammal,eatMeat);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
        System.out.println("continue observe");
     System.out.println("the animal isn't mammal? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      BufferedInputStream st4= new BufferedInputStream (System.in);
      boolean t6_1=st1.read()==(int)('Y');
   
         System.out.println("the animal doesn't have claw? In(Y/N)");
          boolean t6_2=st2.read()==(int)('Y');
   
          System.out.println("the animal doesn't have sharpTooth? In(Y/N)");
         boolean t6_3=st3.read()==(int)('Y');
   
         System.out.println("the animal isn't eyeFrontad? In(Y/N)");
         boolean t6_4=st4.read()==(int)('Y');
   
         if (t6_1&&t6_2&&t6_3&&t6_4){
          mammal=true;claw=true;sharpTooth=true;eyeFrontad=true;
          rule6(mammal,claw,sharpTooth,eyeFrontad);
     }
        }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't mammal? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      boolean t7_1=st1.read()==(int)('Y');
         System.out.println("the animal doesn't have hoof? In(Y/N)");
         boolean t7_2=st2.read()==(int)('Y');
   
         if (t7_1&&t7_2){
          mammal=true;hoof=true;
          Y
          rule7(mammal,hoof);
           }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't mammal? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      boolean t8_1=st1.read()==(int)('Y');
   
         System.out.println("the animal doesn't ruminate? In(Y/N)");
         boolean t8_2=st2.read()==(int)('Y');
   
         if (t8_1&&t8_2){
          mammal=true;ruminate=true;
            rule8(mammal,ruminate);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't carnivore? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      boolean t9_1=st1.read()==(int)('Y');
   
          System.out.println("the animal isn't snuffColor? In(Y/N)");
            boolean t9_2=st2.read()==(int)('Y');
   
          System.out.println("the animal isn't fuscousFleck? In(Y/N)");
         boolean t9_3=st3.read()==(int)('Y');
   
         if (t9_1&&t9_2&&t9_3){
          carnivore=true;snuffColor=true;fuscousFleck=true;
          rule9(carnivore,snuffColor,fuscousFleck);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't carnivore? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      boolean t10_1=st1.read()==(int)('Y');
         System.out.println("the animal isn't snuffColor? In(Y/N)");
            boolean t10_2=st2.read()==(int)('Y');
   
         System.out.println("the animal isn't blackStripe? In(Y/N)");
         boolean t10_3=st3.read()==(int)('Y');
     
         if (t10_1&&t10_2&&t10_3){
          carnivore=true;snuffColor=true;blackStripe=true;
          rule10(carnivore,snuffColor,blackStripe);
        }
        }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
   
   
   
        System.out.println("continue observe");
     System.out.println("the animal isn't ungulate? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      BufferedInputStream st4= new BufferedInputStream (System.in);
      BufferedInputStream st5= new BufferedInputStream (System.in);
      boolean t11_1=st1.read()==(int)('Y');
   
         System.out.println("the animal doesn't have longLeg? In(Y/N)");
            boolean t11_2=st2.read()==(int)('Y');
   
         System.out.println("the animal doesn't have longNeck? In(Y/N)");
         boolean t11_3=st3.read()==(int)('Y');
     
            System.out.println("the animal isn't snuffColor? In(Y/N)");
         boolean t11_4=st4.read()==(int)('Y');
   
          System.out.println("the animal isn't fuscousFleck? In(Y/N)");
          boolean t11_5=st5.read()==(int)('Y');
     
         if (t11_1&&t11_2&&t11_3&&t11_4&&t11_5){
          ungulate=true;longLeg=true;longNeck=true;snuffColor=true;fuscousFleck=true;
          rule11(ungulate,longLeg,longNeck,snuffColor,fuscousFleck);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't ungulate? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      boolean t12_1=st1.read()==(int)('Y');
   
          System.out.println("the animal isn't white ? In(Y/N)");
          boolean t12_2=st2.read()==(int)('Y');
   
         System.out.println("the animal isn't blackStripe? In(Y/N)");
            boolean t12_3=st3.read()==(int)('Y');
     
         if (t12_1&&t12_2&&t12_3){
          ungulate=true;white=true;blackStripe=true;
          rule12(ungulate,white,blackStripe);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't aves? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      BufferedInputStream st4= new BufferedInputStream (System.in);
      BufferedInputStream st5= new BufferedInputStream (System.in);
      boolean t13_1=st1.read()==(int)('Y');
   
         System.out.println("the animal isn't notFly? In(Y/N)");
         boolean t13_2=st2.read()==(int)('Y');
      
         System.out.println("the animal doesn't have longLeg? In(Y/N)");
         boolean t13_3=st3.read()==(int)('Y');
   
            System.out.println("the animal doesn't have longNeck? In(Y/N)");
            boolean t13_4=st4.read()==(int)('Y');
   
         System.out.println("the animal isn't blackAndWhite? In(Y/N)");
          boolean t13_5=st5.read()==(int)('Y');
     
         if (t13_1&&t13_2&&t13_3&&t13_4&&t13_5){
          aves=true;notFly=true;longLeg=true;longNeck=true;blackAndWhite=true;
          rule13(aves,notFly,longLeg,longNeck,blackAndWhite);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't aves? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      BufferedInputStream st3= new BufferedInputStream (System.in);
      BufferedInputStream st4= new BufferedInputStream (System.in);
      boolean t14_1=st1.read()==(int)('Y');
     
         System.out.println("the animal isn't notFly? In(Y/N)");
         boolean t14_2=st2.read()==(int)('Y');
   
         System.out.println("the animal doesn't swimming? In(Y/N)");
            boolean t14_3=st3.read()==(int)('Y');
     
            System.out.println("the animal doesn't have blackAndWhite? In(Y/N)");
         boolean t14_4=st4.read()==(int)('Y');
   
            if (t14_1&&t14_2&&t14_3&&t14_4){
          aves=true;notFly=true;swimming=true;blackAndWhite=true;
          rule14(aves,notFly,swimming,blackAndWhite);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
     
     
     System.out.println("continue observe");
     System.out.println("the animal isn't aves? In(Y/N)");
     try{
      BufferedInputStream st1= new BufferedInputStream (System.in);
      BufferedInputStream st2= new BufferedInputStream (System.in);
      boolean t15_1=st1.read()==(int)('Y');
   
         System.out.println("the animal isn't beGoodAtFly? In(Y/N)");
         boolean t15_2=st2.read()==(int)('Y');
          if (t15_1&&t15_2){
          aves=true;beGoodAtFly=true;
          rule15(aves,beGoodAtFly);
     }
     }catch(IOException e)
      {  System.out.println("Error reading from user");    
      }
    }
       /*主函数 */
      public static void main (String[ ] args){
       AnimalIdentify animal1=new AnimalIdentify();
       animal1.queryUseRule();
    }  

手把手教你写第一个J2ME手机程序

  • 2008年06月05日 10:00
  • 445KB
  • 下载

【教她写代码】使用Intellij创建第一个Springboot程序

首先先介绍一下Springboot:Spring是Java开发中,十分著名的一个框架。但是该框架的使用必须结合大量的XML配置文件,这一点让开发人员痛苦无比。Springboot是Spring官方重新...

手把手教写第一个WCF程序

  • 2009年05月07日 14:55
  • 754KB
  • 下载

自已写的第一个WIN下C程序

  • 2012年09月28日 22:38
  • 643B
  • 下载

用记事本写第一个Servlet程序

第一步 在tomcat的webapps目录下新建一个web应用,这里我取名为FirstServlet,然后在此web应用下新建一个WEB-INF/classes目录; 第二部 在classes目录中新...

我写的第一个程序,是程序哟

  • 2010年05月01日 12:28
  • 14.31MB
  • 下载

servlet(1) - 手写第一个servlet程序 - 小易Java笔记

声明:如tomcat的安装目录为D:\Java\tomcat6,下面要根据tomcat的安装目录而定 1. 建立程序的文件结构 ==>找到tomcat的安装目录,在webapps目录下新建一个名为...

第一个 OpenGL ES的小程序(过程写的非常详细)

#import"King_ViewController.h" @interface King_ViewController() @end @imple...

安装Android Studio并写第一个程序.

一、安装Android Studio 1.安装Java开发工具包 安装和配置的介绍:http://jingyan.baidu.com/article/86f4a73e852b4c37d65269a6....
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:我写的第一个小的程序
举报原因:
原因补充:

(最多只允许输入30个字)