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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:45:40+00:00 2026-05-26T13:45:40+00:00

I have a program that takes a list of names from a file and

  • 0

I have a program that takes a list of names from a file and puts it in a List. Then the user can do what they want from it using the methods provided. I am wondering how I would go about putting a second file in there so the user can choose to upload a list of names or a list of integers. I have created the File I just can’t seem to put it in…Here is my code:

import java.util.Scanner;
import java.io.*;
import java.util.*;

public class MyProgram7{
public static void main(String[] args)throws Exception{

    //Declare Variables
    File file = new File ("data7_names_Fall_2011.txt");
    File file2 = new File ("data7_integers_Fall_2011.txt");
    Scanner input = new Scanner(file);
    Prog7Methods pm = new Prog7Methods();
    Scanner scan = new Scanner(System.in);
    String menu, outputString;
    int option = 1;

    MyList<String> list = new MyLinkedList<String>();
    while (input.hasNext()){
        list.add(input.next());
    }



    //Create menu
    menu ="\n\t1  Create list of names." +
            "\n\t2  Display list of names." +
            "\n\t3  Search for element in list." +
            "\n\t4  Check if list is empty." +
            "\n\t5  Check the size of list." +
            "\n\t6  Remove item from list." +
            "\n\t7  Clear the list." +

            "\n\t0  Quit\n\n\n";

    System.out.println(menu);
    System.out.println("Enter your selection:\t");
    option = scan.nextInt();

    //Continue menu
    while (option != 0) {

    switch (option){

        case 1: //Reading
                    pm.createLists(scan, input);
                    break;

        case 2:  pm.displayList(list);
                    break;

        case 3:  pm.searchList(scan, list);
                    break;

        case 4:  pm.checkList(list);
                    break;

        case 5:  pm.checkSize(list);
                    break;

        case 6:  pm.remove(scan, list);
                    break;

        case 7:  pm.clearList(list);
                    break;

        default: outputString = "\nInvalid Selection\n";
                    System.out.println(outputString);
                    break;
    }//end switch

    System.out.print(menu);
    System.out.println("Enter your selection:\t");
    option = scan.nextInt();
}





}


}
  • 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-26T13:45:41+00:00Added an answer on May 26, 2026 at 1:45 pm

    You can use Scanner class to ask about the type of list that the user wants to handle.
    Depending on the user input (int or String), you can load either one of the Lists (from the corresponding file). After that, you can continue as you have listed in your code.

    Regards!

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

Sidebar

Related Questions

i have a list which is being populated from a program that takes user
I have a perl program that takes input and output file arguments, and I'd
I have a program that gets a JSON from the server using getJSON and
I have a program that takes a text file with values for example: 20
I have a python program that takes the md5 & sha1 hash values of
I have been assigned wit the task to write a program that takes a
I have a program, that takes a long time to load. Because of this,
I have program that runs fast enough. I want to see the number of
I have a program that saves an image in a local directory and then
I have a program in python that includes a class that takes a function

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.