8 Replies - 422 Views - Last Post: 30 January 2018 - 02:15 AM Rate Topic: -----

#1 Abhavya  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 21-January 18

I need to add ignoreCase while reading a name from a file provided

Posted 25 January 2018 - 09:30 PM

I need to add ignoreCase while reading a name from a file provided..still a beginner so where am I supposed to add the .equalsIgnoreCase() method? please help!

while(inputFileBoy.hasNext())
    {
        male.add(inputFileBoy.nextLine());
    }
    while (inputFileGirl.hasNext())
    {
        female.add(inputFileGirl.nextLine());
    }
    Boolean ifMales,ifFemales;
    ifMales=ifFound(male,name);
    ifFemales=ifFound(female,name);

    //if statement to check
    if(ifMales || ifFemales)
    {
        System.out.println("Name *"+ name+ "* is POPULAR");
    }
    else
    {
        System.out.println("Name *"+ name+ "* is NOT POPULAR");
    }

This post has been edited by ndc85430: 30 January 2018 - 01:12 AM
Reason for edit:: Removed quote tags.


Is This A Good Question/Topic? 0
  • +

Replies To: I need to add ignoreCase while reading a name from a file provided

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 14032
  • View blog
  • Posts: 56,119
  • Joined: 12-June 08

Re: I need to add ignoreCase while reading a name from a file provided

Posted 25 January 2018 - 09:35 PM

Where are you comparing strings that you would need to ignore cases?

I am pretty sure we don't see that code here.
Was This Post Helpful? 0
  • +
  • -

#3 Abhavya  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 21-January 18

Re: I need to add ignoreCase while reading a name from a file provided

Posted 25 January 2018 - 09:39 PM

[quote name='modi123_1' date='25 January 2018 - 11:35 PM' timestamp='1516941305' post='2351862']
Where are you comparing strings that you would need to ignore cases?

public class asdfg
{
	public static void main(String[]args)throws IOException
	{
		//
		File boy=new File("BoyNames.txt");
		Scanner inputFileBoy=new Scanner(boy);

		//
		File girl=new File("GirlNames.txt");
		Scanner inputFileGirl=new Scanner(girl);

		ArrayList<String>female=new ArrayList<>();
		ArrayList<String>male=new ArrayList<>();

		System.out.print("Enter a name: ");
		Scanner keyboard=new Scanner(System.in);
		String name=keyboard.nextLine();

		while(inputFileBoy.hasNext())
		{
			male.add(inputFileBoy.nextLine());
		}
		while (inputFileGirl.hasNext())
		{
			female.add(inputFileGirl.nextLine());
		}
		Boolean ifMales,ifFemales;
		ifMales=ifFound(male,name);
		ifFemales=ifFound(female,name);

		//if statement to check
		if(ifMales || ifFemales)
		{
			System.out.println("Name *"+ name+ "* is POPULAR");
		}
		else
		{
			System.out.println("Name *"+ name+ "* is NOT POPULAR");
		}
	}
	public static boolean ifFound(ArrayList<String>array,String name)
	{
		boolean found= false;
		int i=0;
		while(!found && i<array.size())
		{
			if(array.get(i).equals(name))
			{
				found=true;
			}
			i++;
		}
		return found;
	}
}
:code:

Quote

I want to compare the user input with the names provided in the file

This post has been edited by modi123_1: 25 January 2018 - 09:47 PM
Reason for edit:: In the future, please use the [code] tag button in the editor..

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 14032
  • View blog
  • Posts: 56,119
  • Joined: 12-June 08

Re: I need to add ignoreCase while reading a name from a file provided

Posted 25 January 2018 - 09:47 PM

Okay.. can you identify the line that comparison is happening on?
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3540
  • View blog
  • Posts: 16,130
  • Joined: 20-September 08

Re: I need to add ignoreCase while reading a name from a file provided

Posted 26 January 2018 - 02:29 AM

What's with this thing about 'popularity'? All your code does is to see if the name is present once in the collection
You're making your filling of the name collections needlessly complex too: https://docs.oracle.....nio.file.Path-

This post has been edited by g00se: 26 January 2018 - 02:32 AM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#6 ndc85430  Icon User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 798
  • View blog
  • Posts: 3,258
  • Joined: 13-June 14

Re: I need to add ignoreCase while reading a name from a file provided

Posted 27 January 2018 - 01:15 AM

The method ifFound is unnecessary, as ArrayList has a method contains that does that. The name ifFound is not too meaningful anyway - if your method returns a boolean, then its name should be something that's asking a question with a yes/no answer (contains, isEven, hasNext, ...).

This post has been edited by ndc85430: 27 January 2018 - 01:26 AM

Was This Post Helpful? 0
  • +
  • -

#7 Abhavya  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 21-January 18

Re: I need to add ignoreCase while reading a name from a file provided

Posted 29 January 2018 - 05:54 PM

We haven't been taught contains() yet.And our instructor told us to only use the methods that we have done in our class..

This post has been edited by ndc85430: 30 January 2018 - 01:12 AM
Reason for edit:: Removed quote tags.

Was This Post Helpful? 0
  • +
  • -

#8 ndc85430  Icon User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 798
  • View blog
  • Posts: 3,258
  • Joined: 13-June 14

Re: I need to add ignoreCase while reading a name from a file provided

Posted 30 January 2018 - 01:13 AM

I'm not sure why your post was in a quote, since you're not quoting anything. In any case, if you have to write your own method to do what contains does, fair enough I guess. At least give it a proper name, though.
Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3540
  • View blog
  • Posts: 16,130
  • Joined: 20-September 08

Re: I need to add ignoreCase while reading a name from a file provided

Posted 30 January 2018 - 02:15 AM

Quote

At least give it a proper name, though.
And get rid of that variable i which does nothing except add clutter
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1