Results 1 to 4 of 4
  1. #1
    ronnie is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default do set and get methods really exists?

    so below i my piece of code
    //main class
    class dfsgdfg {
    public static void main(String ags[]){
    tunaSetmethod g1=new tunaSetmethod();
    tunaSetmethod g2=new tunaSetmethod(12);
    tunaSetmethod g3=new tunaSetmethod(12,43);
    tunaSetmethod g4=new tunaSetmethod(12,43,54);

    System.out.println(g1.html());
    System.out.println(g2.html());
    System.out.println(g3.html());
    System.out.println(g4.html());
    }
    }



    //secondary class


    public class tunaSetmethod{
    private int hour;
    private int minute;
    private int second;

    public tunaSetmethod(){
    this(0,0,0);
    }
    public tunaSetmethod(int h){
    this(h,0,0);
    }
    public tunaSetmethod(int h,int m){
    this(h,m,0);
    }
    public tunaSetmethod(int h,int m,int s){
    Time(h,m,s);
    }
    public void Time(int h,int m,int s){
    code(h);
    codec(m);
    codex(s);
    }
    public void code(int h){
    hour=(hour>=0&&hour<24?h:0);
    }
    public void codec(int m){
    minute=(minute>=0&&minute<24?m:0);
    }
    public void codex(int s){
    second=(second>=0&&second<24?s:0);
    }
    public int pablo(){
    return hour;
    }
    public int pablo1(){
    return minute;
    }
    public int pablo2(){
    return second;
    }
    public String html(){
    return String.format("%d:%02d:%02d ", pablo(),pablo1(),pablo2());
    }
    }



    Under Time method i have written
    code(h);
    codex(m);
    codec(s);
    before it was sethour(h);
    setminute(m);
    setsecond(s);
    respectively.(it dosen't affect the results)
    Now in the return method html() it directs to pablo methods which finally returns hour minute and second,so where from the program got instructions that hour,minute and second are equal to int h,int m ,int s respectively
    So if the outputs are same with and without using set and get methods whats the point of using them
    also i used pablo instead off gethour,getminute and getsecond
    and Time=setTime



    output is
    0:00:00
    12:00:00
    12:43:00
    12:43:54
    Last edited by ronnie; 02-22-2012 at 02:49 PM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

    Default Re: do set and get methods really exists?

    Those attributes ('hour','minute','second') are set in the code, codec and codex methods.

    I am not entirely sure where you are confused.

    If you changed those method names back to getHour etc then they would exist...

  3. #3
    ronnie is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: do set and get methods really exists?

    that means
    public void code(int h){
    hour=(hour>=0&&hour<24?h:0);

    sets the value of hour=h? i mean on what basis it checks the condition
    and without using set and get methods
    Last edited by ronnie; 02-22-2012 at 05:53 PM.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

    Default Re: do set and get methods really exists?

    set and get methods are just normal methods.
    There's nothing special about them.
    The only thing is some frameworks use the naming (Bean naming standards) in order to access those methods, so non-standard naming will result in those frameworks failing.

    As for what code(int h) is doing, it wil set 'hour' to 'h' if 'hour' is currently between 0 and 24, and to 0 otherwise.
    Why it is doing it this way I have no idea. Ask whoever wrote it.

Similar Threads

  1. Checking if IP already exists - MySQL
    By style in forum New To Java
    Replies: 6
    Last Post: 02-08-2012, 11:49 AM
  2. Determining which choice exists
    By kjkrum in forum XML
    Replies: 1
    Last Post: 12-16-2011, 12:27 AM
  3. How do I check if a database exists ...Any help?
    By nmvictor in forum New To Java
    Replies: 5
    Last Post: 05-09-2010, 04:21 PM
  4. How to check whether file is exists or not
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  5. Check if a web page exists or not
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-02-2008, 07:24 PM

Posting Permissions

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