Results 1 to 9 of 9

Thread: Maps

  1. #1
    natep67 is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default Maps

    I almost have this done but im running into a few problems especially on lines 23 and 24(the beginning of the if statement). i get this error on both items "Syntax error on token ">", Expression expected after this token". Please help me out!
    Java Code:
    import java.util.HashMap;
    import java.util.Scanner;
    public class Info{
       static String name;
       static int age;
      public Info(final String name, final int age){
          Info.name = name;
          Info.age = age;
      }
      {
           name = People.aName;
           }
      {
           age= People.numberCount;
           }
    
    
        public interface Maps<K, V> {
             HashMap<String, Info>m= new HashMap<String, Info>();
             public class If {
                     public void main(String[] args) {
                         Scanner input = new Scanner(System.in);
    
                         if (input.hasNext()= Maps<K>) {
                             System.out.println(Maps<K, V>);
                         } else {
                             System.out.println("Sorry, Name not entered. Try again");
                         }
                             
    
                 }
    
             }

  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Your brackets are all messed up. I'm not sure what your trying to do.

    Java Code:
    import java.util.Scanner;
    public class Info{
       [COLOR="DarkRed"]static String name;  // maybe public static?[/COLOR]
       [COLOR="DarkRed"]static int age;  // maybe public static?[/COLOR]
      public Info(final String name, final int age){
          Info.name = name;
          Info.age = age;
      } [COLOR="DarkRed"]// This is the end of the constructor [/COLOR] 
      [COLOR="DarkRed"]// Whats this supposed to be? [/COLOR] 
      {
           name = People.aName;
      }
      {
           age= People.numberCount;
      }
    
        [COLOR="DarkRed"]// is this within the Info class? [/COLOR] 
        [COLOR="DarkRed"]/* Also note that interfaces can't have defined methods or variables. */[/COLOR] 
        public interface Maps<K, V> {
             HashMap<String, Info>m= new HashMap<String, Info>(); 
             public class If {
                     public void main(String[] args) {
                         Scanner input = new Scanner(System.in);
    
                         if (input.hasNext()= Maps<K>) {
                             System.out.println(Maps<K, V>);
                         } else {
                             System.out.println("Sorry, Name not entered. Try again");
                         }
                             
    
                 }
    
             }

  3. #3
    natep67 is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Im trying to set up my code so when the user inputs a name and Birthday it assigns the name as the key and the birthday as the value of a map. So when the user inputs a name it will pull up the info attached to it.
    Improved Code
    Java Code:
      import java.util.HashMap;
    import java.util.Scanner;
    public class Info{
      private String name;
      private  int age;
      public Info(final String name, final int age){  
      
       this.name = name;
       this.age = age;
      }
    	public interface Maps<K, V> {
    		 HashMap<String, Info>m= new HashMap<String, Info>();
    		 public class If {
    		 	    public void main(String[] args) {
    		             Scanner input = new Scanner(System.in);
    		 	        if (input.hasNext()= Maps<K>) {
    		 	        	System.out.println(Maps<K, V>);
    		 	        } else {
    		 	        	System.out.println("Sorry, Name not entered. Try again");
    		 	        }
    		 	            
    
    		 	}
    
    		 }
    
    }
    
    }

  4. #4
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Create a map object which holds the name and the birthday
    Maybe something like
    Java Code:
            Map<String, Calendar> myMap = new HashMap<String, Calendar>();
            Calendar myBDay = Calendar.getInstance();
            myBDay.set(1991, 12, 22);
            myMap.put("Joseph M. Pond", myBDay);

  5. #5
    natep67 is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    I am doing a whole lot better this morning. i was working on this and i think i have solved it for what i want except for one problem. On line 16, i get all these errors.-
    Syntax error on tokens, ConstructorHeaderName expected
    instead
    - Syntax error on token "(", delete this token
    - Syntax error on token ")", delete this token
    - Syntax error on token "(", < expected
    - Watchpoint:Info [access and modification] - People
    I realize a lot of it is syntax but i don't know what to do with the parentheses
    New Code
    Java Code:
    import java.util.Set;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;
    public class Info{
      private  int destinyNumber;
      private  int lifePathNumber;
      public Info(final int destinyNumber, final int lifePathNumber){  
     
       this.destinyNumber = destinyNumber;
       this.lifePathNumber = lifePathNumber;
      }
    Map<String, Info> myMap = new HashMap<String, Info>();
    //create an Info item to put into the map, keyed by its name
    Info item = new Info(destinyNumber ,lifePathNumber);
     myMap.put (People.sum , People.numberCount));
             public class If {
                 {
                         Scanner input = new Scanner(System.in);
                         if (input.hasNext(People.aName)) {
                             System.out.println(People.numberCount);
                         } else {
                             System.out.println("Sorry, Name not entered. Try again");
                         }
                             
     
                 }
     
             }
     
    }
     
    }

  6. #6
    kbindumadhavi is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Rep Power
    0

    Default

    Java Code:
    myMap.put (People.sum , People.numberCount[COLOR="Red"])[/COLOR]);
    This is extra ')'

  7. #7
    natep67 is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Removing that did nothing. What i did do to remove almost all of the errors was replace the ) with >. this got rid of all of the problems but these;

    Syntax error on token ">", VariableDeclarator expected after
    this token

    I still have no clue what to do to resolve those
    Last edited by natep67; 05-06-2009 at 03:44 AM.

  8. #8
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    it doesn't matter how many errors you get but that you get errors. often, a typo will conceal errors proceeding it because java can't understand the rest of a statement if the beginning doesn't make sense. don't insert random symbols/characters in hopes that it will solve your issue. instead, look at what the compiler is telling you is wrong and solve them one at a time. almost all the time, you won't solve everything with a single character.

    anyways, your commands aren't even in a method from what i can tell. start there.

  9. #9
    natep67 is offline Member
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

Similar Threads

  1. How do I Link data of two maps toghther?
    By javanoobie in forum New To Java
    Replies: 13
    Last Post: 04-13-2009, 06:37 PM
  2. Caching dynamic-maps in Hibernate
    By leonus in forum JDBC
    Replies: 0
    Last Post: 06-02-2008, 02:06 PM
  3. Google Maps API
    By mew in forum New To Java
    Replies: 0
    Last Post: 12-26-2007, 11:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •