Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Java Binary Search Help Please!

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Binary Search Help Please!

    Please write a program that performs a binary search on a sorted array.

    Write the interface SortedList with the following methods:

    //write a binary search for Strings, remember String implements Comparable automatically so you have access
    //to String’s compareTo() method. Look it up to see how it works.
    public int binarySearch(String[] words, String key, int size);

    //adds the value at an index that maintains sorted order, and not necessarily at the end
    //increase the number of toppings by 1, Find the position where top goes and move the others down and insert
    //the correct topping.
    public boolean add(String top);

    obj.add(“pineapple”) would yield true and

    once you have 20 toppings the add method would return
    false and print the message “no more toppings”



    //searches for the correct topping, then deletes it and maintains sorted order
    // Find the position where the topping goes and move the others down
    // decrease the number of toppings by 1
    public boolean delete(String top);

    obj.delete(“ham”) would yield true and

    once you have 0 toppings the delete method would return
    false and print the message “no toppings”




    //prints a numbered list going down.
    // Note the numbers are one more than the index
    public String printArray();

    *******************
    Here are the toppings:

    1. anchovies
    2. extra cheese
    3. ground beef
    4. ham
    5. mushrooms
    6. onions
    7. pepperoni
    8. peppers
    9. pineapple
    10. sausage

    *******************


    Write class called MyList that implements the SortedList interface.

    You will need one instance variable that is a String Array that could hold
    up to 20 toppings and an integer with how many are valid toppings
    Originally the integer should have the value 9. You will need
    one constructor without parameters that creates the list of the 9 given
    pizza toppings. Toppings 10-20 should be “ZZZ”.

    Write the add method that will insert a topping in the correct place in the
    list. You need to find the correct place in the array, bump the current values down and then insert the new topping.

    Write the delete method that will delete a topping from the correct place in the list. You need to find the correct place in the array and bump the current values up.


    Add the methods to get the instance variables and the printArray()method. Only print the toppings that are valid.
    You do not need the set methods.

    Write a that MyListTester that
    1. Creates a list of pizza toppings.
    2. Print out the list.
    3. Add three more toppings to the list.
    4. Print out the list
    5. Delete two toppings from the list.
    6. Print out the list
    7. Ask the person to pick a topping and call the binary search method to decide if the topping is there.
    8. Do this 4 times with some toppings being there and some not.


    DO NOT USE THE JAVA BUILT IN SEARCH OR SORT.


  2. #2
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Java Binary Search Help Please!

    Please post specific problems in your program and what is that you have tried. We are not here to do your assignments.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Binary Search Help Please!

    I know but im a COMPLETE beginner and have no idea what this is.. please please help me its urgent!! i would REALLY appreciate if you could. i dont understand anything... ahhhh god

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,061
    My Mood
    Mellow
    Thanks
    184
    Thanked 652 Times in 639 Posts

    Default Re: Java Binary Search Help Please!

    This program is the wrong place for a COMPLETE beginner to start. Complete beginners should start with a HelloWorld program and build from there. Further, we can't help with "no idea." That's what instructors, courses and study are supposed to do. We'll help when you have some idea that needs adjusting or expanding.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    5
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Binary Search Help Please!

    If this is for school i recommend offering money as noone is kind enough to spend their night creating this code that would take 1-2weeks.

Similar Threads

  1. Binary Search Help
    By OwsumEmam in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 31st, 2011, 11:01 PM
  2. Binary Search Help!
    By Allicat in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 15th, 2011, 04:03 PM
  3. Binary Search Tree in Java [HELP]
    By alan in forum Algorithms & Recursion
    Replies: 2
    Last Post: February 5th, 2011, 05:44 AM
  4. Binary Search Tree
    By lex25288 in forum Algorithms & Recursion
    Replies: 3
    Last Post: January 19th, 2011, 08:10 AM
  5. Binary Search Loop
    By Tarakara in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 29th, 2010, 08:22 AM

Tags for this Thread