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 6906539
In Process

The Archive Base Latest Questions

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

This program starts off in the FleetInterface class by asking the user for a

  • 0

This program starts off in the FleetInterface class by asking the user for a file (run()). The buildFleet() method reads the file then calls the Vehicle to the Fleet class by calling the addVehicle() method and in that method, it sets the new Vehicle object into the vehicle array.

After all that’s done, a user menu comes up asking if they would like to 1.) Add a Vehicle, 2.) Delete a Vehicle.

Let’s say they add a new Vehicle. The requirement is to have the user manually enter data about that vehicle (All the same info that was in the file in the beginning). The problem is that this option also calls addVehicle(). If I program in the addVehicle() method some statements like “Please enter the model of your vehicle:”, that will also show up when the program first starts and calls addVehicle().

The tricky part – I am not allowed to create any new public methods (only private), and I cannot add any new class level data.

My Fleet class has 2 constructors: 1 is blank (Not allowed to set anything here.) And 1 has a parameter value of File (Used for reading the original file).

So to sum it up, I need a way for the program to start by reading the values in a file, calling addVehicle(), then also allow the user to enter in a vehicle manually via Scanner.. while also calling addVehicle()

Here is my code:

FleetInterfaceApp:

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

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

    userMenu(file, fleet);

}

private void userMenu(File file, Fleet fleet) throws FileNotFoundException
{
    int choice = 0;

    Scanner input = new Scanner(System.in);

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

    switch(choice)
    {
    case 1:
        fleet.addVehicle(Honda);
        break;
    }
}

Fleet:
Class Level data (cannot change):

Vehicle[] vehicles = new Vehicle[4];
File file;

addVehicle:

public void addVehicle(Vehicle Honda[]) throws FileNotFoundException
{
    Scanner reader = new Scanner(file);

    if(canAddVehicle() == true)
    {
        for(int i = 0; i < vehicles.length; i++)
        {
            if(vehicles[i] == null)
            {
                Honda[i] = new Vehicle();
                Honda[i].readRecord(reader);
                vehicles[i] = Honda[i];
                reader.close();
                break;
            }
        }
        System.out.println("Vehicle Added!");

    }
    else
    {
        System.out.println("You can not add more than 4 vehicles.");
    }

}
  • 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:19:24+00:00Added an answer on May 27, 2026 at 8:19 am

    You can write out the user input to a temp file and then set the file attribute in your fleet object to the temp file before you call addVehicle. The file attribute is accessible to other classes because it is scoped package private by default. This means that any classes in the same package can access it. If FleetInterfaceApp is in the same package then it can already do this.

    Here is some example code based off of the code provided in the question. This needs extra work before it will run.

    // somewhere inside userMenu(File file, Fleet fleet)
    File tempFile = File.createTempFile( "tmp", ".tmp" );
    
    FileWriter fout = new FileWriter( tempFile );
    fout.append( userInput );
    fout.close();
    
    fleet.file = tempFile;
    
    switch(choice)
    {
    case 1:
        fleet.addVehicle(Honda);
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the moment my batch file look like this: myprogram.exe param1 The program starts
This program reads emails (really just a .txt file structured like an email) and
I Have a java program that does sort of this: It starts off with
This program I use has it's own variables to set when you run it,
I have this simple little batch file program that I wrote but it fails
I have a class that starts a few threads. Each thread (extends Thread) calls
I am working with an architecture that has a main program. When this starts
I have a PyQt program, in this program I start a new thread for
I have a simple script which is used to start another program. This other
I have a ClickOnce environment like this: \\Fileserver\ClickOnceApps\App1.application C:\Documents and Settings\user\Start Menu\Programs\publisher\app1.appref-ms My understanding

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.