Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:52:14+00:00 2026-06-03T10:52:14+00:00

I apologize but I am new to programming and I’m having difficulty coding a

  • 0

I apologize but I am new to programming and I’m having difficulty coding a program. The original program is as follows:

import java.io.*;
import java.io.IOException;
import java.io.InputStreamReader;

class buildABoat{

    String boatName;      // Boat name
    void buildABoat(){      
        String BoatName;            
    }

    void nameTheBoat() {        
        try {           
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("\n\nWhat should we name this vessel? \n\n");
            this.boatName = br.readLine();
            System.out.println("\n\nThe " + boatName + " is ready to sail!\n");             
        }           
        catch (IOException e) {                 
        }   
    }
}

class proj1{

    public static void main(String[] arg){

        buildABoat boat1;
        buildABoat boat2;
        buildABoat boat3;
        buildABoat boat4;
        buildABoat boat5;

        boat1 = new buildABoat();
        boat2 = new buildABoat();
        boat3 = new buildABoat();
        boat4 = new buildABoat();
        boat5 = new buildABoat();

        boat1.nameTheBoat();
        boat2.nameTheBoat();
        boat3.nameTheBoat();
        boat4.nameTheBoat();
        boat5.nameTheBoat();

        System.out.println("(Press ENTER to exit)");

        try {           
            System.in.read();
        }           
        catch (IOException e) {         
            return;
        }
    }
}

This produces the following:

What should we name this vessel?
Enterprise
The Enterprise is ready to sail!
What should we name this vessel?
Columbia
The Columbia is ready to sail!
What should we name this vessel?
Challenger
The Challenger is ready to sail!
What should we name this vessel?
Atlantis
The Atlantis is ready to sail!
What should we name this vessel?
Endeavor
The Endeavor is ready to sail!
(Press ENTER to exit)

I tried to change this to the following:

import java.io.*;
import java.io.IOException;
import java.io.InputStreamReader;

class buildABoat{    
    String boatName;      // Boat name

    void buildABoat(){
        String BoatName;
    }

    void nameTheBoat() {
        try {           
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("\n\nWhat should we name this vessel? \n\n");
            this.boatName = br.readLine();
            System.out.println("\n\nThe " + boatName + " is ready to sail!\n");             
        }           
        catch (IOException e) {                 
        }   
    }
}

class proj1{

    public static void main(String[] arg){

        Boat[] boat;            
        boat = new Boat[5];    
        for(int i = 0; i <= Boat.Length; i++){          
            nameTheBoat();          
        }           
        System.out.println("(Press ENTER to exit)");

        try {           
            System.in.read();
        }           
        catch (IOException e) {         
            return;
        }
    }
}

This of course produces the following error:

proj1.java:71: error: cannot find symbol
                for(int i = 0; i <= Boat.Length; i++){
                                        ^
  symbol:   variable Length
  location: class Boat
proj1.java:73: error: cannot find symbol
                        nameTheBoat();
                        ^
  symbol:   method nameTheBoat()
  location: class proj1
2 errors

What am I missing in the new program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:52:15+00:00Added an answer on June 3, 2026 at 10:52 am

    where you have

    nameTheBoat();
    

    in your for() loop you need to have

    boat[i] = new Boat();
    boat[i].nameTheBoat();
    

    The reasons are:
    1) nameTheBoat() is a method that only operates on objects of type Boat. You are not giving it any object to work on.
    2) boat[] = new Boat[5]; initializes an Array object, but doesn’t create the 5 new Boats in the Array object. So you need to create each of those 5 Boats before you can run a Boat method on them. Otherwise you’ll get a null pointer error.

    EDIT: and of course as others mentioned, boat.length is the length of the array boat, boat.Length is wrong.

    Enjoy!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Haskell so I apologize if this is an easy question, but
First I want to apologize for such a silly question but I'm quite new
I am very new to programming, so I apologize if this question seems absurdly
I'm not only new to Rails, but to development in general, so I apologize
I'm very new to programming so I apologize in advance if my question is
Programming is so new to me that I apologize for not knowing how to
( Hi, everyone. I'm very new to Windows programming, so I apologize in advance
I am somewhat new to Python and programming in general so I apologize. By
I'm fairly new to Objective-C and iPhone programming so I apologize if this is
Firstly, I'm new to Android (so I apologize if this question is ignorant) but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.