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

  • SEARCH
  • Home
  • 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 6910907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:52:34+00:00 2026-05-27T08:52:34+00:00

I have a little problem here. I am declaring a new object Fleet in

  • 0

I have a little problem here.

I am declaring a new object “Fleet” in these methods:

public void run() throws FileNotFoundException
{
    File file = new File(getFile());
    Fleet fleet = new Fleet(file);
    buildFleet(file, fleet);
    }

private void buildFleet(File file, Fleet fleet) throws FileNotFoundException
{
    fleet.addVehicle(Honda);
    userMenu(fleet);

}

The last line calls the userMenu() method. In this method I need to be able to change the value of “File” inside Fleet without creating a new instance of the class.

private void userMenu(Fleet fleet) throws FileNotFoundException
{
    PrintWriter pw = new PrintWriter("temp.txt");
    File file = new File("temp.txt");
    fleet = new Fleet(file);

    this.createMenu();
    choice = this.menu.getChoice();


while(choice != 8)
{
    switch(choice)
    {
    case 1:
        //Do stuff
        fleet.addVehicle(Honda);
        break;
    }
}

Also, I am not allowed to create any new class level data.
Any suggestions?

  • 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-05-27T08:52:35+00:00Added an answer on May 27, 2026 at 8:52 am

    Solved:

    I changed:

    private void userMenu() throws FileNotFoundException
    {
        PrintWriter pw = new PrintWriter("temp.txt");
        File file = new File("temp.txt");
    

    to:

    private void userMenu(Fleet fleet) throws FileNotFoundException
    {
        PrintWriter pw = new PrintWriter("temp.txt");
        File file = new File("temp.txt");
        fleet.file = file;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Obj-C, and I have a little problem here. I'm trying insert
So, I have a little problem here. Suppose I have: public class Repository<TEntity> where
I need a little push in the right direction. Here's my problem: I have
I'm new around here and i have a little problems with a C# application.
I have a little problem with a simple vbScript. The script has to run
I'm having a little problem here! I have discovered the following as being the
I have a little problem with AlertDialogs in my application. So here is my
I have a little problem with my script. When I try to run it
i have a little problem here , this page at firefox, opera, chrome, has
I have a little problem. Here is my example: file1.php : <?php include(file2.php); ?>

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.