problem need help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: problem need help

  1. #1
    Join Date
    Oct 2002
    Posts
    6

    problem need help

    hi
    i am having a problem with this program the program does not print what i enterd it just takes the info but i can't get it to print what the user asked for i highlited some of the problems using *** it means i think the problem is here:
    now ther is a nother class called Store.java i will put it under the main program.

    /**
    * MallSearch is a search application to find information about stores in a mall.
    * MallSearch takes no arguments and immediately starts a dialogue, like that shown below:
    * (user inputs are underlined):
    *
    * <pre>
    * % <u>java MallSearch</u>
    * Please enter match type ('exact' or 'wild') or 'exit': <u>exact</u>
    * Please input the store type: <u>department</u>
    * Please input the store name: <u>Hudson's Bay Company</u>
    * Please input an item type: <u>bedding</u>
    * "Hudson's Bay Company": department store selling bedding, located on floor 1, #1.
    * 1 match printed.
    * Please enter match type ('exact' or 'wild') or 'exit': <u></u>
    * Please input the store type: <u></u>
    * Please input the store name: <u></u>
    * Please input an item type: <u>CD</u>
    * "Sam's": entertainment store selling CD, located on floor 1, #11.
    * "HMV": entertainment store selling CD, located on floor 3, #1.
    * 2 matches printed.
    * Please enter match type ('exact' or 'wild') or 'exit': <u>exit</u>
    *
    * %
    * </pre>
    *
    * Two types of searches are permitted: "exact" and "wild" (short for
    * wildcard); "exit" can also be entered, which will cause the program to quit.
    * <br>
    * Permitted store types include all those accepted by
    * <A HREF="Store.html#typeNameIndex(java.lang.String)">Store.typeNameIndex</A>,
    * as well as the empty string.
    * <br>
    * There are no restrictions on store names or items.
    */
    import printer;
    public class MallSearch
    {

    /**
    * Indicates the match of search string to name and/or item must be exact.
    */
    private static final int MATCH_EXACT = 0;

    /**
    * Indicates the search string can match anywhere in the name and/or item.
    */
    private static final int MATCH_WILDCARD = 1;

    /**
    * Indicates the command to quit.
    */
    private static final int EXIT = -1;


    // *** HERE YOU MUST ENTER THE CORRECT DOCUMENTATION!! ***
    private static void printSearchResults (//*** FY THE ARGUMENTS *** */
    )
    {
    /* *** HERE YOU MUST IMPLEMENT THE METHOD *** */

    }

    /**
    * Returns the text of the next input line, after printing the appropriate prompt.
    * @param prompt the text to print
    * @return the text of the input line typed in response to the prompt
    */
    private static String getLineWithPrompt (String prompt)
    {
    printer.print (prompt);
    return printer.readLine ();
    }


    /**
    * Returns match type requested by the user, one of MATCH_EXACT,
    * MATCH_WILDCARD, or EXIT. The user is first prompted and their response is
    * matched against "exact", etc. If no match is found, the type defaults to
    * MATCH_WILDCARD.
    * @return the match type requested by the user or MATCH_WILDCARD, if no valid
    * type was requested
    */
    private static int getMatchType ()
    {
    String matchType = getLineWithPrompt ("Please enter match type ('exact' or 'wild') or 'exit': ");
    if (matchType.equalsIgnoreCase("exit"))
    return EXIT;
    else if (matchType.equalsIgnoreCase("exact"))
    return MATCH_EXACT;
    else if (matchType.equals("") || matchType.equalsIgnoreCase("wild"))
    return MATCH_WILDCARD;
    else
    {
    printer.println("Unknown match type. Using wildcard.");
    return MATCH_WILDCARD;
    }
    }


    /**
    * Returns the type of store requested by the user. The user is repeatedly
    * prompted, until an acceptable type is entered. Permitted store types
    * include all those accepted by
    * <A HREF="Store.html#typeNameIndex(java.lang.String)">Store.typeNameIndex</A>,
    * as well as the empty string.
    * @return the type of store requested by the user
    */
    private static int getStoreType ()
    {
    // get store type, making sure it is valid
    int storeType = 0;
    String storeTypePrompt = "Please input the store type: ";
    do
    {
    String storeTypeName = getLineWithPrompt (storeTypePrompt);
    if (storeTypeName.length() == 0)
    storeType = Store.ANY_STORE_TYPE;
    else
    storeType = Store.typeNameIndex(storeTypeName);
    storeTypePrompt = "Invalid type. Please reenter: ";
    } while(storeType == Store.INVALID_STORE_TYPE);
    return storeType;
    }


    /**
    * Runs the application.
    */
    public static void main(String args[])
    {
    MallMap theMap = new MallMap();
    int matchType = getMatchType ();


    while (matchType != EXIT)
    {
    int storeType = getStoreType ();
    String storeName = getLineWithPrompt ("Please input the store name: ");
    String item = getLineWithPrompt ("Please input an item type: ");

    printSearchResults (i have to print the argument that will produce what user asked for ! *** */ );

    matchType = getMatchType ();
    }
    }
    }
    ---------------
    Store.java class

    public class Store
    {

    private String name = null;
    private int type = 0;
    private String itemTypes[] = null;
    public static final int ANY_STORE_TYPE = -2;
    public static final int INVALID_STORE_TYPE = -1;
    public static final int EMPTY_STORE = 0;
    public static final int SPECIALTY_STORE = 1;
    public static final int FOOD_STORE = 2;
    public static final int DEPARTMENT_STORE = 3;
    public static final int CLOTHING_STORE = 4;
    public static final int GIFT_STORE = 5;
    public static final int BOOK_STORE = 6;
    public static final int HOME_STORE = 7;
    public static final int ENTERTAINMENT_STORE = 8;
    public static final int N_STORE_TYPES = 9;
    public static final int DEFAULT_STORE_TYPE = 1;
    private static final String validTypeNames[];

    public Store(String s, String s1, String as[])
    {
    init(s, typeNameIndex(s1), as);
    }

    public Store(String s, int i, String as[])
    {
    init(s, i, as);
    }

    private void init(String s, int i, String as[])
    {
    name = s;
    if(i >= 0 && i < 9)
    type = i;
    else
    type = 1;
    if(as == null)
    itemTypes = new String[0];
    else
    itemTypes = as;
    }

    public static int typeNameIndex(String s)
    {
    if(s == null)
    return -1;
    for(int i = 0; i < validTypeNames.length; i++)
    if(s.equalsIgnoreCase(validTypeNames[i]))
    return i;

    return -1;
    }

    public String getName()
    {
    return name;
    }

    public int getType()
    {
    return type;
    }

    public String getTypeName()
    {
    return validTypeNames[type];
    }

    public int getNItemTypes()
    {
    return itemTypes.length;
    }

    public String getItemType(int i)
    {
    if(i >= itemTypes.length)
    return null;
    else
    return itemTypes[i];
    }

    public String toString()
    {
    return "\"" + name + "\": " + getTypeName() + " store";
    }

    static
    {
    validTypeNames = new String[9];
    validTypeNames[0] = "empty";
    validTypeNames[1] = "specialty";
    validTypeNames[2] = "food";
    validTypeNames[3] = "department";
    validTypeNames[4] = "clothing";
    validTypeNames[5] = "gift";
    validTypeNames[6] = "book";
    validTypeNames[7] = "home";
    validTypeNames[8] = "entertainment";
    }
    }

  2. #2
    Join Date
    Nov 2002
    Posts
    59
    I just kinda skimmed the code...that's alot to try and figure out. ;-p

    Looks to me like you need a few private class-scoped variables that you print out in that method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center