Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    Basic help with my program please? (Certified Noob)


    Hello! This is my first post, and my first program. I need help with it because it is throwing up some error that I can't seem to fix... It is 2 errors, both about reaching the end of the file while parsing. The program is for changing the sign in front of my school, because we spend about 10 minutes seeing what letters we can salvage from the previous message, and this program is supposed to do that by removing the spaces from two entered strings (The New and Previous message), removing the white space, turning it into an array of Characters, then checking one letter of the first statement with all of the second, and removing the like ones (Leaving you with two arrays of what you need to bring and what will be left over) Here is the code:

    Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class marqueemaker {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main (String[] args) {
    
    		String input;
    		String output;
    
    		System.out.println("Enter the new message");
    		input = sc.nextString;
    
    		System.out.println("Enter the old message");
    		output = sc.nextString;
    
    		String inputnospace = input.replaceAll("\\s","");
    		String outputnospace = output.replaceAll("\\s","");
    
    		char[] inputArray = input.toCharArray();
    		char[] outputArray = output.toCharArray();
    
            for(int i=1; i<input.length; i++){
    			for(int j=1; i<output.length; i++){
    
    				if(inputArray[i] == outputArray[j]) {
    					outputArray.splice(j, 1);
    			} else {
    			}
    
    		System.out.println("Bring the following letters:");
    
    		for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    Downloadable .java file:
    http://www.speedyshare.com/sDnGS/marqueemaker.java
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    it is throwing up some error that I can't seem to fix... It is 2 errors, both about reaching the end of the file while parsing.
    Sounds like a missing }
    Make sure that all the {s have a matching }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    So apparently that code was unfinished...


    I'm still having the error but the last two lines of the code. This is the actual code:
    Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class marqueemaker {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main (String[] args) {
    
    		String input;
    		String output;
    
    		System.out.println("Enter the new message");
    		input = sc.nextString;
    
    		System.out.println("Enter the old message");
    		output = sc.nextString;
    
    		String inputnospace = input.replaceAll("\\s","");
    		String outputnospace = output.replaceAll("\\s","");
    
    		char[] inputArray = input.toCharArray();
    		char[] outputArray = output.toCharArray();
    
            for(int i=1; i<input.length; i++){
    			for(int j=1; i<output.length; i++){
    
    				if(inputArray[i] == outputArray[j]) {
    					outputArray.splice(j, 1);
    			} else {
    			}
    
    		System.out.println("Bring the following letters:");
    
    		for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    	}
    }
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    Go back and check again that each { has a } that goes with it.

    One way is to print the program on paper and use a pencil to circle each { and draw a line to the } that goes with it. Start at deeply nested {s and work out.

    Some IDE editors have a menu item or key strokes for finding the pairs of {}.
    On mine, I place he cursor just before a { and press: CTRL and ]
    and the cursor jumps to the } that goes with it.
    Last edited by NormR; September 28th, 2013 at 05:12 PM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    This is my new code with {} for the for loops, but it still has the same error...


    Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class marqueemaker {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main (String[] args) {
    
    		String input;
    		String output;
    
    		System.out.println("Enter the new message");
    		input = sc.nextString;
    
    		System.out.println("Enter the old message");
    		output = sc.nextString;
    
    		String inputnospace = input.replaceAll("\\s","");
    		String outputnospace = output.replaceAll("\\s","");
    
    		char[] inputArray = input.toCharArray();
    		char[] outputArray = output.toCharArray();
    
    
            for(int i=1; i<input.length; i++){
    			for(int j=1; i<output.length; i++){
    
    				if(inputArray[i] == outputArray[j]) {
    					outputArray.splice(j, 1);
    					inputArray.splice(i, 1);
    			    } else {
    				}
    			}
    		}
    		System.out.println("Bring the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    
    
    		System.out.println("Bring back the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    	}
    }
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0
    I did the pencil thing and that's what I found, the foor loops.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    That's a tried and true method.

    but it still has the same error...
    I guess you missed a { that needs a } to go with it,
    Print it and draw some circles and lines.
    Maybe use the editor to find all the { and then circle it on the paper so you don't miss any.
    Last edited by NormR; September 28th, 2013 at 06:21 PM.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    I found my error, unearthing 6 more :/


    Originally Posted by NormR
    That's a tried and true method.



    I guess you missed a { that needs a } to go with it,
    Print it and draw some circles and lines.
    Maybe use the editor to find all the { and then circle it on the paper so you don't miss any.
    See, as soon as I located the error (The first for loop that printed the final arrays) it started giving me six error about not being able to find the symbol, which is essentially for all the periods in the code (input.length, output.length, .splice, .nextInt)

    Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class marqueemaker {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main (String[] args) {
    
    		String input;
    		String output;
    
    		System.out.println("Enter the new message");
    		input = sc.nextString;
    
    		System.out.println("Enter the old message");
    		output = sc.nextString;
    
    		String inputnospace = input.replaceAll("\\s","");
    		String outputnospace = output.replaceAll("\\s","");
    
    		char[] inputArray = input.toCharArray();
    		char[] outputArray = output.toCharArray();
    
    
            for(int i=1; i<input.length; i++){
    			for(int j=1; i<output.length; i++){
    
    				if(inputArray[i] == outputArray[j]) {
    					outputArray.splice(j, 1);
    					inputArray.splice(i, 1);
    			    } else {
    				}
    			}
    		}
    		System.out.println("Bring the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    
    
    		System.out.println("Bring back the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    	}
    }
    Here's a pasting of the errors:

    Code:
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:14: error: cannot find symbol
    		input = sc.nextString;
    		          ^
      symbol:   variable nextString
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:17: error: cannot find symbol
    		output = sc.nextString;
    		           ^
      symbol:   variable nextString
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:26: error: cannot find symbol
            for(int i=1; i<input.length; i++){
                                ^
      symbol:   variable length
      location: variable input of type String
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:27: error: cannot find symbol
    			for(int j=1; i<output.length; i++){
    			                     ^
      symbol:   variable length
      location: variable output of type String
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:30: error: cannot find symbol
    					outputArray.splice(j, 1);
    					           ^
      symbol:   method splice(int,int)
      location: variable outputArray of type char[]
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:31: error: cannot find symbol
    					inputArray.splice(i, 1);
    					          ^
      symbol:   method splice(int,int)
      location: variable inputArray of type char[]
    6 errors
    
    Tool completed with exit code 1
  16. #9
  17. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    You call nextString as it is an variable.
    when you call a function you have use () at the "end".
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    Ok, I added parenthasis, fixing two of these problems


    Originally Posted by MrFujin
    You call nextString as it is an variable.
    when you call a function you have use () at the "end".
    First, If I can call next string, is there any reason that it is still getting it's error? This is a pasting of the errors:
    Code:
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:13: error: cannot find symbol
    		input = sc.nextString();
    		          ^
      symbol:   method nextString()
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:16: error: cannot find symbol
    		output = sc.nextString();
    		           ^
      symbol:   method nextString()
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:29: error: cannot find symbol
    					outputArray.splice(j, 1);
    					           ^
      symbol:   method splice(int,int)
      location: variable outputArray of type char[]
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:30: error: cannot find symbol
    					inputArray.splice(i, 1);
    					          ^
      symbol:   method splice(int,int)
      location: variable inputArray of type char[]
    4 errors
    
    Tool completed with exit code 1
    Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class marqueemaker {
    	static Scanner sc = new Scanner(System.in);
    
    	public static void main (String[] args) {
    
    		String input;
    		String output;
    
    		System.out.println("Enter the new message");
    		input = sc.nextString();
    
    		System.out.println("Enter the old message");
    		output = sc.nextString();
    
    		String inputnospace = input.replaceAll("\\s","");
    		String outputnospace = output.replaceAll("\\s","");
    
    		char[] inputArray = input.toCharArray();
    		char[] outputArray = output.toCharArray();
    
    
            for(int i=1; i<input.length(); i++){
    			for(int j=1; i<output.length(); i++){
    
    				if(inputArray[i] == outputArray[j]) {
    					outputArray.splice(j, 1);
    					inputArray.splice(i, 1);
    			    } else {
    				}
    			}
    		}
    		System.out.println("Bring the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    
    
    		System.out.println("Bring back the following letters:");
            for(int k=1; k<outputArray.length; k++) {
    			System.out.print(outputArray[k] + ", ");
    		}
    	}
    }
    And, as always, a pasting of the code...
  20. #11
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    Code:
    input = sc.nextString();
    Check the Scanner class's API doc to make sure you are spelling the method name correctly. Java is very fussy about spelling.
    Code:
    inputArray.splice(i, 1);
    Where is the splice() method defined for char arrays? Arrays do not have methods.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0
    If array's don't have methods, is there any good way to remove a certain character from an array?
  24. #13
  25. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    Arrays are defined with a fixed size that is not changeable. To get a new array with elements removed, create a new array and copy the desired elements from the old one to the new one. Then assign the array variable name to the new array.

    If you used the ArrayList class, you would be able to remove elements from it.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    Arrays are defined with a fixed size that is not changeable. To get a new array with elements removed, create a new array and copy the desired elements from the old one to the new one. Then assign the array variable name to the new array.

    If you used the ArrayList class, you would be able to remove elements from it.
    I changed the code to this, but it's still throwing up errors (6). These are the errors:
    Code:
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:14: error: cannot find symbol
    		input = sc.nextString();
    		          ^
      symbol:   method nextString()
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:17: error: cannot find symbol
    		output = sc.nextString();
    		           ^
      symbol:   method nextString()
      location: variable sc of type Scanner
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:22: error: cannot find symbol
            ArrayList inputArray = new ArrayList(input.toCharArray());
            ^
      symbol:   class ArrayList
      location: class marqueemaker
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:22: error: cannot find symbol
            ArrayList inputArray = new ArrayList(input.toCharArray());
                                       ^
      symbol:   class ArrayList
      location: class marqueemaker
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:23: error: cannot find symbol
            ArrayList outputArray = new ArrayList(output.toCharArray());
            ^
      symbol:   class ArrayList
      location: class marqueemaker
    C:\Users\jdaniels\Desktop\Grady's Files\Java Projects\Java\marqueemaker.java:23: error: cannot find symbol
            ArrayList outputArray = new ArrayList(output.toCharArray());
                                        ^
      symbol:   class ArrayList
      location: class marqueemaker
    6 errors
    
    Tool completed with exit code 1
    Thing is, that should be correct. After multiple failed attempts, I ended up copying both the scanner and arraylist declarations from the websites that explained them. I honestly don't even know what the hell is wrong
  28. #15
  29. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    Did you read the API doc for the Scanner class?

    I don't know where you copied the ArrayList statements from. The compiler doesn't think they are correct.
    Did you read the API doc for ArrayList? What are the value args for its constructor?
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo