[Show all top banners]

bange
Replies to this thread:

What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 Java
[VIEWED 6953 TIMES]
SAVE! for ease of future access.
Posted on 04-13-11 11:12 AM     [Snapshot: 71]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Can you paste the code of  file MultiHashMapTest.java.?
 
Posted on 04-13-11 12:45 PM     [Snapshot: 106]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

// Add javadoc on ur own, test with ur test file, test file would have been helpful if you've pasted it here/, yata herne fursad nai choina, SB ma chat gardai masta, let me know how it goes, you know where to find me

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;


import org.apache.commons.collections.MultiMap;

public class MultiHashMap extends HashMap implements MultiMap
{
    private static final long serialVersionUID = 1L;

    public Object getAll(Object key)
    {
        return super.get(key);
    }
    public void putAll(Object key, Collection values)
    {
         super.put(key, values);
    }

    public boolean contains(Object key, Object value)
    {
        List list = (ArrayList) super.get(key);
        if (list == null && list.size() < 1)
        {
            return false;
        }
        else
        {
            return list.contains(value);
        }
    }

    public Object get(Object key)
    {
        List list = (ArrayList) super.get(key);
        if(list == null)
        {
            return null;
        }
        else
        {
            return list.get(list.size() - 1);
        }
    }

    public String put(Object key, Object value)
    {
        List list =(ArrayList) super.get(key);
        if (list == null)
        {
            list = new ArrayList();
        }
        list.add(value);
        super.put(key, list);
        if (list.size() == 1)
        {
            return null;
        }
        else
        {
            return (String)list.get(list.size() - 2);
        }
     }

    public Object remove(Object key, Object item)
    {
        List list =(ArrayList) super.get(key);
        if (list == null && list.size() < 1)
        {
            return false;
        }
        else
        {
            return list.remove(item);

        }
    }
}

Last edited: 13-Apr-11 12:48 PM

 
Posted on 04-13-11 1:24 PM     [Snapshot: 127]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks a lot Prankster! I really appreciate it..here is the
fileMultiHashMapTest.java



import java.util.*;
public class MultiHashMapTest {
    /** Objects to be used as keys */
    private static final Object o1 = new Object();
    private static final Object o2 = new Object();
    private static final Object o3 = new Object();
    private static final Object o4 = new Object();
    /** Strings to be used as values */
    private static final String s1 = "one";
    private static final String s2 = "two";
    private static final String s3 = "three";
    private static final String s4 = "four";
    /** Collections to be used to test */
    private static final Collection c12 = new Vector();
    private static final Collection c12n = new Vector();
    /** Main entry point to program */
    public static void main(String[] args) {
     setupCollections();
     try {
         testMHM();
     } catch (Exception excn) {
         excn.printStackTrace();
     }
    }
    public static void setupCollections() {
     c12.add(s1);
     c12.add(s2);
     c12n.addAll(c12);
     c12n.add(null);
    }
    public static void testMHM() throws CheckFailedException {
     MultiHashMap mhm = new MultiHashMap();
     check("Assigning value to a key that was not in before", mhm.put(o1, s1) == null);
     check("Verifying association caused by put", s1.equals(mhm.get(o1)));
     check("Verifying return value when reassigning a key to a value", s1.equals(mhm.put(o1, s2)));
     checkEqualCollection("Verifying getAll method", c12, mhm.getAll(o1));
     mhm.putAll(o3, c12);
     checkEqualCollection("Verifying putAll method", c12, mhm.getAll(o3));
     mhm.put(o3, null);
     checkEqualCollection("Verifying the ability to add null values with put method", c12n, mhm.getAll(o3));
     check("Verifying the contains method works for null", mhm.contains(o3, null));
     check("Verifying the contains method works", mhm.contains(o3, s1));
     check("Verifying remove method return value", mhm.remove(o3, null));
     check("Verifying remove method works", !mhm.contains(o3, null));
     checkEqualCollection("Verifying HashMap remove method return value", (Collection) mhm.remove(o3), c12);
     check("Verifying HashMap remove method works", mhm.get(o3) == null);
    }
   
    public static void check(String message, boolean result) throws CheckFailedException {
     if (result == false)
         throw new CheckFailedException(message + " failed");
     else
         System.out.println(message + " passed");
    }
    public static void checkEqualCollection(String message, Collection c1, Collection c2) throws CheckFailedException {
     check(message, c1.containsAll(c2) && c2.containsAll(c1));
    }
    private static class CheckFailedException extends Exception {
     public CheckFailedException() { super(); }
     public CheckFailedException(String message) { super(message); }
    }
}

 
Posted on 04-13-11 1:41 PM     [Snapshot: 132]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Answer to second.
import java.util.Comparator;

class NameComparator implements Comparator
{

    public int compare(Object ratNum1, Object ratNum2)
    {

        //parameter are of type Object, so we have to downcast it to Employee objects

        String ratNum1Val = ((RatNum)ratNum1).getValue();
        String ratNum2Val = ((RatNum)ratNum1).getValue();
        if(ratNum1Val > ratNum2Val)
            return 1;
        else if(ratNum1Val < ratNum2Val)
            return -1;
        else
            return 0;
    }

}

Not sure how yourRatNumSortingTest.java,

but you can sort using this class as below
Arrays.sort(arrayOfRatNumObjects, new RatNumComparator());

 

 

Last edited: 13-Apr-11 01:42 PM

 
Posted on 04-14-11 1:56 PM     [Snapshot: 186]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Please help me with this..Thank you in advance :)



In this lab, you are required to program with Swing and File I/O.

 

Your application will be a Graphical User Interface (GUI) that looks similar to these:

<!--[if !vml]--><!--[endif]--> <!--[if !vml]--><!--[endif]-->

 

This GUI contains several components:

<!--[if !supportLists]-->·      <!--[endif]-->a JTextArea component, in which you can type text or display content of a file.

<!--[if !supportLists]-->·      <!--[endif]-->a JMenuBar component, which contains two JMenu components

<!--[if !supportLists]-->1)    <!--[endif]-->a JMenu component which is labeled "File". This menu contains three items: "Open", "Save As" and "Exit".

<!--[if !supportLists]-->2)    <!--[endif]-->a JMenu component which is labeled "Style". This menu contains two sub-menus: the JMenu "font-type" and the JMenu "textAreaColor". The "font-type" menu contains three items: "Plain", "Bold" and "Italic". The "textAreaColor" menu contains two sub-menus: the JMenu "Foreground-Color" and the JMenu "Background-Color", each contains four items representing the color: “Pink”, “White”, “Blue” and “Black”.

 

You are required to achieve the following tasks with these components:

<!--[if !supportLists]-->(1)  <!--[endif]-->If you click “File”-> “Open”, you should be able to open a file window as below. You can open a file by either double clicking the file name or typing in the file name and hitting the “open” button, just as you normally do. The content of the file you selected should be shown in the text area. Only the content of a plain text file is required to be shown correctly. If the file doesn’t exist (double clicking the file name won’t has this problem, but if you type into the file name, it is possible), show a message box to indicate such an error. If you click “Cancel”, this window will be closed and nothing happens.


<!--[if !vml]--><!--[endif]-->

 

 

 

 

 

 

HINT: Design of this “open” window is NOT your job; it’s already done in the JFileChoose class. Go to http://java.sun.com/j2se/1.4.2/docs/api/ to check what functions and fields this class provides. What you need to do is figuring out which file has been selected and how to read its context into the text area. As to the message box, refer to the JOptionPane class.

<!--[if !supportLists]-->(2)           <!--[endif]-->If you click “File”-> “Save As”, you should be able to open a file window as below. After you double click a file name or type in a file name and click “Save”, the text currently shown in the text area should be saved in that file. You are NOT required to handle a double confirmation if the file has existed, so be careful that you may override some useful files (just be careful by yourself, this lab doesn’t require you to do anything about it). If you click “Cancel”, this window will be closed and nothing happens.

<!--[if !vml]--><!--[endif]-->

 

 

 

 

 

 

 

 

HINT: Same as task (1), this window is also manipulated by the JFileChoose class.

<!--[if !supportLists]-->(3)           <!--[endif]-->If you click “File”-> “Exit”, your text editor window will be closed and the program stops.

<!--[if !supportLists]-->(4)           <!--[endif]-->You should be able to change the font style, the foreground color and the background color of the text area.


 
Posted on 04-14-11 3:18 PM     [Snapshot: 195]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Java_help

Your 60% solution is in my thread.
IT Solutions Center

 
Posted on 04-14-11 3:24 PM     [Snapshot: 212]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks Ayush...much appreciated!
 
Posted on 04-14-11 4:56 PM     [Snapshot: 228]     Reply [Subscribe]
Login in to Rate this Post:     1       ?     Liked by
 

...and don't think that the professor's Turn It In report will miss sajha.com!
Similarity Index ma sabai dekhai dincha!

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
tesla stock OMG !!
Those who are in TPS, what’s your backup plan?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
I hope all the fake Nepali refugee get deported
From Trump “I will revoke TPS, and deport them back to their country.”
Tourist Visa - Seeking Suggestions and Guidance
Documents instead of Birth Certificate
Now, more than ever, is it a good idea to apply for advance parole?
POE for TPS travel
interesting fact about sajha.
Does anyone know if the passport renewal process at the DC embassy is active again?
Looking for girl
Occupied
To Sajha admin
ढ्याउ गर्दा दसैँको खसी गनाउच
All the Qatar ailines from Nepal canceled to USA
Travel Document for TPS (approved)
MAGA and all how do you feel about Trumps cabinet pick?
TPS Travel Permit Processing time
Looking for girl
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters