楼主: rhythmit
793 0

[新手尝试] code-java [推广有奖]

  • 0关注
  • 0粉丝

小学生

42%

还不是VIP/贵宾

-

威望
0
论坛币
4 个
通用积分
0.6516
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
318 点
帖子
8
精华
0
在线时间
2 小时
注册时间
2015-1-25
最后登录
2015-12-7

楼主
rhythmit 发表于 2015-1-25 05:26:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

import java.io.Serializable;

import java.util.Hashtable;


public class SpamFilter implements Serializable {

        private Hashtable<String, String> badWords; // hash table that hold a list

                                                                                                // of bad words.


        /**

         * defalut constructor that create an instance of SpamFilter.

         */

        public SpamFilter() {

                badWords = new Hashtable<String, String>();

        }


        /**

         *

         * @param word

         *            insert the word into bad words list.

         */

        public void insert(String word) {

                /**

                 * if it is already in the list, no need to insert again.

                 */

                if (isBadWord(word))

                        System.out.println(word

                                        + " is already in Hashtable, no need to insert.");

                /**

                 * insert to the list if it is not in the list yet.

                 */

                else {

                        badWords.put(word, word);

                        System.out.println(word + " is added to Hashtable.");

                }

        }


        /**

         *

         * @param word

         *            remove the word if it is in list.

         * @throws ElementNotFoundException

         *             when there is no such element found.

         */

        public void remove(String word) throws ElementNotFoundException {

                /**

                 * remove the word if it is found.

                 */

                if (isBadWord(word)) {

                        badWords.remove(word);

                        System.out.println(word + " is removed from Hashtable.");

                }

                /**

                 * not found then throw an exception.

                 */

                else

                        throw new ElementNotFoundException(word

                                        + " is not found in the Hashtable.");

        }


        /**

         *

         * @param checkMe

         *            check if the given String is in the hashtable or not.

         * @return true if it is. false if it is not.

         */

        public boolean isBadWord(String checkMe) {

                return (badWords.containsKey(checkMe));

        }


        /**

         *

         * @param message

         *            open the file of the given message.

         * @return the % that contain spam words.

         */

        public float checkEmail(String message) {


                String[] messages = message.split(" ");// split the sentences

                int countBadWords = 0;

                for (String s : messages)

                        // check each word if it is a spam or not.

                        if (isBadWord(s))

                                countBadWords++; // increment by 1 if it is.

                return (float) countBadWords / messages.length; // return the %

        }

}


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:code Java COD jav ODE private public create import insert

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-9 03:15