dfl2m's Profile User Rating: -----

Reputation: 0 Apprentice
New Members
Active Posts:
11 (0.01 per day)
05-December 12
Profile Views:
Last Active:
User is offline Feb 25 2013 06:16 PM

Previous Fields

Dream Kudos:
Icon   dfl2m has not set their status

Posts I've Made

  1. In Topic: Read a file into ArrayList

    Posted 24 Feb 2013

    I changed my code to the following:

    	public void loadDept(File file) throws Exception {
    		Scanner scanner = new Scanner(file);
    			String line = scanner.nextLine();
    			String [] parts = line.split(" ");
    			if (parts[0].equals("Store")){
    				s = Integer.parseInt(parts[2]);
    			} else if (parts[0].equals("Dept")){
    				d = Integer.parseInt(parts[2]);
    			} else {
    				String dName = "";
    				for (int i = 0; i < parts.length; i++){
    					dName += parts[i] + " ";
    				days = scanner.nextInt();
    				Store entry = new Department(s,dName,d,days);

    But now I get the following error:

    Exception in thread "main" java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Unknown Source)
    at LD.loadDept(LD.java:33)
    at LD.<init>(LD.java:12)
    at Main.main(Main.java:8)

    do i need to add a blank line at the end of the output?? i tried tracing and debugging and eclipse would not tell me if the array is being filled.
  2. In Topic: Read a file into ArrayList

    Posted 24 Feb 2013

    View Postpbl, on 24 February 2013 - 09:00 PM, said:

    Sorry, might work seen that way... still an horrible design but it will work
    so your question: why this one

    days = scanner.nextInt();

    fails ?

    Yes, because the code will work fine if I just create one object and no more, but when it tries to create the second object it fails. I would assume since there are more lines in the text file, that the code will be able to translate it.

    When you say "horrible design" what exactly do you mean? Is there a way to recognize the integer in the first line without splitting it into an array of strings?
  3. In Topic: Read a file into ArrayList

    Posted 24 Feb 2013

    The input file is as follows:

    Store ID: 1
    Dept ID: 1030
    House Wares Department
    Store ID: 1
    Dept ID: 1035
    Store ID: 2
    Dept ID: 1030
    House Wares Department
  4. In Topic: Count frequency of numbers in a phone number using ArrayList

    Posted 30 Jan 2013

    Okay it seems i figure it out

    	for (int i = 0; i < frequencySize; i++){
    			int count = 0;  //reset this after every iteration of the outer loop
    			for (int j = 0; j < arraySize; j++){  
    				if (i == array.get(j)){  //for example, if i = 0, and array.get(j) = 0, then 
    					count++;            //incremement count by 1
    					frequency.set(i, count); // set frequency(0, 1)
    		System.out.println("The number of " + i + " is " + frequency.get(i));

My Information

Member Title:
New D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



dfl2m hasn't added any friends yet.


dfl2m has no profile comments yet. Why not say hello?