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 4 of 4

Thread: Beginner Java HELP!

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

    Default Beginner Java HELP!

    Need help on my project. This project is devised to encapsulate the attributes and behavior of Boats. Specifically, you will create a class "Fleet" whose constructor accepts a list of boat names in a string array and will create a "Boat" object for each name in an array of boats (i.e., each name will be used to create an element in the array for a bat). The boat names are passed as arguments to the main method. Provide a method that assigns a boat ID to each boat created. The ID should be a 5 digit randomly generated number and not two IDs should be the same. Any boat name that starts with the letters B,C, and N will raise the sail; otherwise lower the sail. Provide a method "DisplayBoatNames" that displays the boat names, boat IDs and state of the sail. Provide a method "FindBoatName" that accepts the boat name as an argument and returns the array index of the boat if it exists; otherwise, it returns -1. Use the following boat names to test your java application:
    "Sea Monkey, Backdraft, Cast Away, Nautifish, Destiny"

    Thanks in advance.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Beginner Java HELP!

    Make an attempt at writing the code. If you get stuck post your code here using code tags, copy and paste exact error messages and ask a specific question.

    Do not dump your homework on us and expect someone to do it for you.
    Improving the world one idiot at a time!

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

    Default Re: Beginner Java HELP!

    Quote Originally Posted by Junky View Post
    Make an attempt at writing the code. If you get stuck post your code here using code tags, copy and paste exact error messages and ask a specific question.

    Do not dump your homework on us and expect someone to do it for you.
    I finished it, just need the last part where it states "FindBoatName" that accepts the boat name as an argument and returns the array index of the boat if it exists; otherwise, it returns -1.

    I'm stuck on this part. I have
    void FindBoatName(String boat) {
    for (int i = 0 ; i < boatObjectCount ; i++) {

    if (allTheBoats[i].boatName.equals(boat)) {

    System.out.println(allTheBoats[i].boatName + "boat ID is " + allTheBoats[i].id + ".");
    return;
    }
    }

    System.out.println(boat + " does not exist in the boats list.");
    }

    and under main, i have
    boats.FindBoatName("Nautifish");

    boats.FindBoatName("Second Wind");

    which I know is wrong, because I cant get the return -1 in.
    But I dont know how to code this part. Since return -1, its an integer, but I'm using a string..

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Beginner Java HELP!

    if (allTheBoats[i].boatName.equals(boat))    {
        System.out.println(allTheBoats[i].boatName + "boat ID is " + allTheBoats[i].id + ".");
        return;
    }
    When the boat is found why do you print out a message? Is that what your assignment says to do?
    Why do you return nothing? Is that what your assignment says to do?

    If your code does not find the boat where does the code go? (Hint: it has to do with the loop). What are you supposed to return in that situation?
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 2
    Last Post: January 18th, 2013, 10:12 AM
  2. Java beginner
    By peter raad in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 9th, 2013, 06:24 AM
  3. Replies: 1
    Last Post: January 6th, 2013, 05:32 AM
  4. Another beginner to Java!
    By jwise95 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 21st, 2011, 04:27 PM
  5. Java Beginner
    By rannoune in forum Java Theory & Questions
    Replies: 3
    Last Post: December 25th, 2009, 02:30 AM