public class ReactionTest { static Reaction[] re = new Reaction[18]; // TODO Auto-generated method stub static Reaction hgo=new Reaction("2HgO",null,"点燃","无"); static Reaction mgo=new Reaction("Mg","O2","点燃","无"); static Reaction fe3o4=new Reaction("3Fe","2O2","点燃","无"); static Reaction cuo=new Reaction("2Cu","O2","加热","无"); static Reaction al2o3=new Reaction("4Al","3O2","点燃","无"); static Reaction h2o=new Reaction("2H2","O2","点燃","无"); static Reaction p2o5=new Reaction("4P","5O2","点燃","无"); static Reaction so2=new Reaction("S","O2","点燃","无"); static Reaction co2=new Reaction("C","O2","点燃","无"); static Reaction co=new Reaction("2C","O2","点燃","无"); static Reaction coco2=new Reaction("2CO","O2","点燃","无"); static Reaction c2h5oh=new Reaction("C2H5OH","3O2","点燃","无"); static Reaction k2mno4=new Reaction("2KMnO4","无","加热","无"); static Reaction h2o2=new Reaction("h2o2",null,"无","二氧化锰"); static Reaction h2od=new Reaction("2H2O",null,"通电","无"); static Reaction caoh2=new Reaction("CaO","H2O","无","无"); static Reaction h2co3=new Reaction("H2O","CO2","无","无"); static Reaction caco3=new Reaction("CaCO3",null,"高温","无"); public static boolean get() { for(int i = 0;i<re.length;i++) { re[i]=new Reaction(null, null, null, null); }; re[0]=hgo; re[1]=mgo; re[2]=fe3o4; re[3]=cuo; re[4]=al2o3; re[5]=h2o; re[6]=p2o5; re[7]=so2; re[8]=co2; re[9]=co; re[10]=coco2; re[11]=c2h5oh; re[12]=k2mno4; re[13]=h2o2; re[14]=h2od; re[15]=caoh2; re[16]=h2co3; re[17]=caco3; String str = Frame.text.getText(); String str1 = Frame.text1.getText(); String str2 = Frame.info; String str3 = Frame.info1; //System.out.println(str + str1 + str2 + str3); TEST[] test = new TEST[1]; TEST Test = new TEST(str, str1, str2, str3); test[0] = Test; System.out.println(re[0].toString()); for (int i = 0; i < re.length; i++) { Reaction target = re[i]; if (target.toString().equals(Test.toString())) { // 使用 Reaction 类中的 equals 方法比较两个实例是否相等 System.out.println("Matched: " + target); return true; } } System.out.println("No match found."); return false; } }
时间: 2023-07-19 15:38:02 浏览: 147
fb-auto-reaction:Bot Auto React Facebook(FB)2021年
这段代码是一个 Java 类,名为 ReactionTest。它声明了一个 Reaction 类型的数组 re,包含了18个 Reaction 对象,每个 Reaction 对象表示一种化学反应。它还定义了一个名为 get 的静态方法,该方法接收用户输入的化学反应信息,并比较该信息与数组中的 Reaction 对象是否匹配,如果匹配则返回 true,否则返回 false。在比较过程中,使用 Reaction 类中的 equals 方法比较两个实例是否相等。这个类还包含了一些主函数中未定义的类和变量,比如 Frame、TEST 等。
阅读全文