Results 1 to 9 of 9
Thread: Maps
- 05-04-2009, 11:37 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
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"); } } }
- 05-04-2009, 11:52 PM #2
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"); } } }
- 05-05-2009, 12:03 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
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"); } } } } }
- 05-05-2009, 12:18 AM #4
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);
- 05-05-2009, 01:26 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
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"); } } } } }
- 05-05-2009, 02:17 PM #6
Member
- Join Date
- Apr 2009
- Posts
- 20
- Rep Power
- 0
This is extra ')'Java Code:myMap.put (People.sum , People.numberCount[COLOR="Red"])[/COLOR]);
- 05-06-2009, 02:15 AM #7
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
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 thoseLast edited by natep67; 05-06-2009 at 02:44 AM.
- 05-06-2009, 02:52 AM #8
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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.
- 05-06-2009, 03:59 AM #9
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
How do I Link data of two maps toghther?
By javanoobie in forum New To JavaReplies: 13Last Post: 04-13-2009, 05:37 PM -
Caching dynamic-maps in Hibernate
By leonus in forum JDBCReplies: 0Last Post: 06-02-2008, 01:06 PM -
Google Maps API
By mew in forum New To JavaReplies: 0Last Post: 12-26-2007, 10:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks