Results 1 to 6 of 6
  1. #1
    sebo is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Question java annotations - small prog

    i've got some test-prog to write using annotations, there are some guidelines how it has to look like, so here they are:

    i have to define @Bind annotation which used for chosen fields of a class let me add their values to a map behind the keys = variable names.

    The process of adding and getting values to/from the map has to find his place in another class called Binder.

    i'm new in java things so..... :(

    things i must follow:
    -----------------------

    public class Test {
    @Bind static double a;
    @Bind static double b;
    double static c;

    somwhere in a method:
    a = 7;
    b = 12;
    c = 1;

    in some method of a constructor:
    Binder bdr = new Binder(...)
    bdr.bind();

    somwhere else:
    Map<..> map = bdr.getMap();

    and using 'map' there should be a possibility to access the values of 'a' and 'b', but not the 'c'.

    It seems to be very easy, but not for me, not now... can anyone help me to do this so i can be able to work on other things like that... thx in advance!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    Do you have any code for your problem?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  4. #4
    sebo is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    k, so if i'm right there should be an apart class for the annotation:
    Java Code:
    public @interface Bind {
    //and because i'm not experienced i'm not sure if there is sth needed here ?
    }
    my test-class, not sure if correct:
    Java Code:
    public class Test {
    	
    	@Bind static double a;
    	@Bind static double b;
    	static double c;
    
    	public static void main(String[] args) {
    		setValues();
    		Binder bdr = new Binder(a,b,c);
    		bdr.bind();
    		
    		Map<Integer,double> map = new HashMap<Integer,double>();
    		map = bdr.getMap();
    		
    		//some for-each to get these values
    	}
    	
    	private static void setValues() {
    		a = 7;
    		b = 12;
    		c = 1;
    	}		
    }
    but i still don't know how should exactly my Binder-class look like in order to add and get those values.... just to be honest - dnt know how it exactly works :(
    Java Code:
    public class Binder {
    	
    	public Binder(double a, double b, double c) {
    		// TODO
    	}
    	
    	public void bind() {
    		// TODO 		
    	}
    
    	public Map<Integer, Integer> getMap() {
    		// TODO 
    		return null;
    	}
    }
    any help now?

  5. #5
    sebo is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    anybody ...?

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Proofreading this small Java program
    By almina in forum New To Java
    Replies: 5
    Last Post: 10-23-2009, 08:42 AM
  2. Replies: 1
    Last Post: 07-13-2008, 04:16 PM
  3. Small scale Java Editor
    By Greenfrog99 in forum AWT / Swing
    Replies: 0
    Last Post: 01-27-2008, 09:46 PM
  4. need a prog on java 2d applet
    By bachelorswalk in forum Java Applets
    Replies: 0
    Last Post: 12-25-2007, 06:26 PM
  5. Small tennis simulation in Java
    By diego in forum New To Java
    Replies: 1
    Last Post: 12-02-2007, 02:32 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
  •