Ask Experts Questions for FREE Help !
Ask
    alexman27's Avatar
    alexman27 Posts: 2, Reputation: 1
    New Member
     
    #1

    Dec 1, 2014, 10:46 PM
    Can someone fix this for me!?
    Can someone please! Fix this for me?
    I need to write a program that reads from a text file of popular girl names and a text file of popular boy names.The user should be able to enter a boy's name, a girl's name, or both, and the application will display messages indicating whether the names were among the most popular.
    This is what I have until now.. Thank you for your time : )
    import java.io.*;
    import java.util.Scanner;
    public class NamesSearch {




    public static void main(String[] args) throws FileNotFoundException {
    File BoysNamesfile = new File ("BoysNames");
    Scanner inputFile = new Scanner(BoysNamesfile);


    File GirlsNamesfile = new File ("GirlsNames");
    Scanner inputFile2 = new Scanner(BoysNamesfile);


    String[] BoysNamefile = BoysNamesfile.list();
    String[] GirlsNamefile = GirlsNamesfile.list();


    Scanner keyboard = new Scanner(System.in);


    int choice;
    String input = null;
    String name;






    System.out.println("Enter 1 if you would like to check a boys name in the popular name list, or enter 2 if you would like to+" +
    "check for a girls name.");
    choice = keyboard.nextInt();
    if(choice == 1)
    {
    System.out.println("Enter the name you would like to check.");
    name = keyboard.nextLine();
    inputFile = sequentialSearch(BoysNamefile, name);
    if (BoysNamesfile.list = name )
    {
    System.out.println("The name is on the popular list.");
    }
    else
    {
    System.out.println("The name is not on the popular list.");
    }
    }












    }


    private static Scanner sequentialSearch(String[] boysNamefile, String input) {
    // TODO Auto-generated method stub
    return null;
    }


    }
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #2

    Dec 2, 2014, 09:27 AM
    First off you're opening the boy's name file twice, once as the boys scanner, and once as the girls scanner.

    Also:
    if (BoysNamesfile.list = name )
    is an assignment not a equality test. IE, you're setting BoysNamesfile.list to name, not checking to see if they're the same.

    I am primarily a C/C++ programmer, but there's something hinky with the way you're using the scanners and the input files. I neither have the time nor the will right now to look up and re-learn Java, but I would look at your Java book on examples of how to use those classes because I think you got them wrong. Be careful on your naming and the use of it, you can generate bugs by just copy and pasting without changing. As well, make sure you debug as you go, for example your search method is undefined but you'll probably get the code around it working before defining it. If there's a bug you won't know if it is in the main part or the method. Build the method, test that it's solid then move on and put it all together. Be VERY conscious of your syntax too.

    Good luck.
    alexman27's Avatar
    alexman27 Posts: 2, Reputation: 1
    New Member
     
    #3

    Dec 2, 2014, 12:27 PM
    Quote Originally Posted by CravenMorhead View Post
    First off you're opening the boy's name file twice, once as the boys scanner, and once as the girls scanner.

    Also:
    is an assignment not a equality test. IE, you're setting BoysNamesfile.list to name, not checking to see if they're the same.

    I am primarily a C/C++ programmer, but there's something hinky with the way you're using the scanners and the input files. I neither have the time nor the will right now to look up and re-learn Java, but I would look at your Java book on examples of how to use those classes because I think you got them wrong. Be careful on your naming and the use of it, you can generate bugs by just copy and pasting without changing. As well, make sure you debug as you go, for example your search method is undefined but you'll probably get the code around it working before defining it. If there's a bug you won't know if it is in the main part or the method. Build the method, test that it's solid then move on and put it all together. Be VERY conscious of your syntax too.

    Good luck.
    THank you for your time and input !

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Hole in trunk; to fix or not to fix? [ 1 Answers ]

I have a massive Catalpa (sp) tree in my front yard. The trunk is about 4 feet in diameter at ground level. About 10 feet up the trunk, there is an oblong hole that's about 10" tall by 4" wide. I think squirrels are living in there. While I don't want to harm the squirrels, I don't want to lose...

How to fix [ 4 Answers ]

Kitchen sink, hot water pressure is terrible but the cold water is fine. What's the problem and how do you fix it? I need more details on how to fix it please. Thx

Can I fix hazardous steps if a contractor is refusing to fix, and threatens to sue? [ 1 Answers ]

I live in central Texas. I hired a landscape contractor to install retaining walls and a patio which included 4 steps in stone. These steps range in size from 6.5" to 9.5" and the tallest is on the top! They are very dangerous. He refuses to do any fixes, and walked off project. At one point in the...

How do I fix this? [ 6 Answers ]

I am the biggest idiot in the world. I was going out the man I wanted to spend the rest of my life with and because of a fight I went out got drunk and was unfaithful. I love this man so much it hurts. We are broken up for 2 months and I have tried so hard to get him back. I've been to counseling,...


View more questions Search