Results 1 to 2 of 2
  1. #1
    mm2236 is offline Member
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Default How can i add a new count to this source code ?

    Hi everyone

    I have 5 variables

    1. XTSM is between 0~200
    2. XTS is between 0~2
    3. XRX is 0~3
    4. XHAN is 0~7
    5. ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL

    they are related to their with this shape .

    XTSM->XTS->XRX->XHAN->ZHTYPE (Just Logical)

    Please tell me how can i see this output?

    Java Code:
    ----Type------------------Total---------------------Total of ZHTYPE-----------------
        XTSM:0/XTS:0               in this case is : 29     TCHF_HLF:28 TCHSD:1 TCHFULL:0
        XTSM:0/XTS:1               No. of found   
        XTSM:0/XTS:2               No. of found   
        XTSM:1/XTS:0               No. of found   
        XTSM:1/XTS:1               No. of found   
        XTSM:1/XTS:2               No. of found
    I get XTSM/XTS/TRX/XHAN and now i want count total of this

    ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL

    they are related to their with this shape .

    * Each XTSM has 3 XTS (0-2)
    * Each XTS has 4 XRX (0-3)
    * Each XRX has 8 XCHAN (0-7)
    * and Each line has a type of ZHTYPE

    This is sample file: http://www.4shared.com/file/21056615...db_online.html

    This output with this code is true but I want add ZHTYPE at the end of each line + XTSM/XTS please help me ???(for example this : XTSM:0/XTS:0 : 29 TCHF_HLF:28 TCHSD:1 TCHFULL:0)

    Java Code:
    public class Test {
    
        public static void main(String[] args) throws IOException {
            Test test = new Test();
            test.execute();
        }
    
        private static String TYPE_XTSM = "XTSM";
        private static String TYPE_XTS = "XTS";
        private static String TYPE_XRX = "XRX";
        private static String TYPE_XHAN = "XHAN";
    
        private void execute() throws IOException {
            InputStream in = null;
            BufferedReader br = null;
            TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap = new TreeMap<Integer, TreeMap<Integer, Integer>>();
            try {
                in = Test.class.getResourceAsStream("db.txt");
                br = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = br.readLine()) != null) {
                    Record rec = new Record(line);
                    processRecord(xtsmMap, rec);
                }
            } finally {
                if (br != null) {
                    br.close();
                }
            }
            printResults(xtsmMap);
        }
    
        private void processRecord(
                TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap, Record rec) {
            TreeMap<Integer, Integer> xtsMap;
            if (xtsmMap.containsKey(rec.getXtsm())) {
                xtsMap = xtsmMap.get(rec.getXtsm());
            } else {
                xtsMap = new TreeMap<Integer, Integer>();
                xtsmMap.put(Integer.valueOf(rec.getXtsm()), xtsMap);
            }
            if (xtsMap.containsKey(rec.getXts())) {
                Integer count = xtsMap.get(rec.getXts());
                xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(count
                        .intValue() + 1));
            } else {
                xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(1));
            }
        }
    
        private void printResults(
                TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap) {
            System.out.println("Type\t\tTotal");
            Set<Integer> xtsmSet = xtsmMap.navigableKeySet();
            for (Integer xtsm : xtsmSet) {
                TreeMap<Integer, Integer> xtsMap = xtsmMap.get(xtsm);
                Set<Integer> xtsSet = xtsMap.navigableKeySet();
                for (Integer xts : xtsSet) {
                    Integer count = xtsMap.get(xts);
                    String outputLine = TYPE_XTSM + ":" + xtsm + "/" + TYPE_XTS
                            + ":" + xts + "\t" + count;
                    System.out.println(outputLine);
                }
            }
        }
    
        private static class Record {
    
            private Integer xtsm, xts, xrk, xhan;
    
            Record(String line) {
                StringTokenizer st = new StringTokenizer(line, "/");
                while (st.hasMoreTokens()) {
                    String token = st.nextToken();
                    String type = token.substring(0, token.indexOf(":"));
                    String valueStr = token.substring(token.indexOf(":") + 1, token
                            .length());
                    Integer value = Integer.valueOf(valueStr);
                    if (TYPE_XTSM.equals(type)) {
                        xtsm = value;
                    } else if (TYPE_XTS.equals(type)) {
                        xts = value;
                    } else if (TYPE_XRX.equals(type)) {
                        xrk = value;
                    } else if (TYPE_XHAN.equals(type)) {
                        xhan = value;
                    }
                }
            }
    
            public Integer getXtsm() {
                return xtsm;
            }
    
            public Integer getXts() {
                return xts;
            }
    
            public Integer getXrk() {
                return xrk;
            }
    
            public Integer getXhan() {
                return xhan;
            }
        }
    }
    I want add ZHTYPE to this ...

    Java Code:
    Type        Total
    XTSM:0/XTS:0    29        such as this : TCHF_HLF:28 TCHSD:1 TCHFULL:0
    XTSM:0/XTS:1    29
    XTSM:0/XTS:2    29
    XTSM:1/XTS:0    29
    XTSM:1/XTS:1    29
    XTSM:1/XTS:2    29
    XTSM:2/XTS:0    29
    XTSM:2/XTS:1    29
    XTSM:2/XTS:2    29
    XTSM:3/XTS:0    14
    XTSM:3/XTS:1    14
    XTSM:3/XTS:2    14
    XTSM:4/XTS:0    13
    Thanks a lot.
    Last edited by mm2236; 01-30-2010 at 12:09 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. How can i add a new count to this source code ?
    By mm2236 in forum New To Java
    Replies: 2
    Last Post: 01-31-2010, 03:32 AM
  2. wrong source code
    By pro85 in forum Java Applets
    Replies: 4
    Last Post: 02-17-2009, 03:46 AM
  3. Replies: 1
    Last Post: 11-28-2008, 06:27 PM
  4. source code of 'javac'?
    By Pooja Deshpande in forum Advanced Java
    Replies: 2
    Last Post: 06-04-2008, 11:24 AM
  5. Need a source code
    By vissu007 in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •