#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Beginner Java Homework HELP PLS!!


    Hi, I need help on my homework~
    My homework 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"

    Much help is appreciated!~
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    what have you done?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by bullet
    what have you done?
    I finished all of it, except the last part where it says "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.

    Im confused on the "return -1"

    int 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 -1;
    }
    }

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

    }

    Before I used void, then i changed it to int but then i get compiler error...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    Nvm, I got the entire project solved.

IMN logo majestic logo threadwatch logo seochat tools logo