Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: please help

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post please help

    class Student
    {
    private int sid;
    private String sname;
    void setdata(int sid,String sname)
    {
    this.sid=sid;
    this.sname=sname;
    }
    int getsid()
    {
    return sid;
    }
    String getsname()
    {
    return sname;
    }
    }

    class Marks
    {
    private int sub1,sub2;
    student std=new student();
    void setdata(int sid,String sname,int s1,int s2)
    {
    std.setdata(sid,sname);
    sub1=s1;
    sub2=s2;
    }
    void findresult()
    {
    System.out.println("sid is"+std.getsid());
    System.out.println("sname is"+std.getsname());
    if (sub1<40 || sub2<40)
    {
    System.out.println("FAIL");

    }
    else
    {
    System.out.println("PASS");
    }
    }
    }

    class Test
    {
    public static void main(String[ ] args)

    Marks m=new Marks();
    m.setdata(10,"Anil",67,64);
    m.findresult();
    }
    Attached Images Attached Images

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: please help

    Welcome to the forum! Please read the announcement topic at the top of most sub forums to learn how to properly post code and ask questions.

  3. #3
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: please help

    class Student
    {
    private int sid;
    private String sname;
    void setdata(int sid,String sname)
    {
    this.sid=sid;
    this.sname=sname;
    }
    int getsid()
    {
    return sid;
    }
    String getsname()
    {
    return sname;
    }
    }

    class Marks
    {
    private int sub1,sub2;
    student std=new student();
    void setdata(int sid,String sname,int s1,int s2)
    {
    std.setdata(sid,sname);
    sub1=s1;
    sub2=s2;
    }
    void findresult()
    {
    System.out.println("sid is"+std.getsid());
    System.out.println("sname is"+std.getsname());
    if (sub1<40 || sub2<40)
    {
    System.out.println("FAIL");
     
    }
    else
    {
    System.out.println("PASS");
    }
    }
    }

    class Test
    {
    public static void main(String[ ] args)
     
    Marks m=new Marks();
    m.setdata(10,"Anil",67,64);
    m.findresult();
    }

    Ok, you seem to be missing an ending } for your class Test as you have closed the bracket for the main method but not the class.

    Maybe that was a copying error.

    You should really consider using constructors.

    They're things that create the object.

    For instance

     
    public Student(nt sid,String sname)
    {
    this.sid=sid;
    this.sname=sname;
    }

    rather than your set methods.

    Also, and I can't say for certain on this as all you did was post code and not explain what was wrong, but I do see a possible issue

     
    if (sub1<40 || sub2<40)
    {
    System.out.println("FAIL");
     
    }

    If you are intending that both have to be at least 40, then you are doing it right.

    If, however, you are intending that at least one must be at least 40 in order to pass, then you are doing it wrong.

    If you are intending that it be at least one, then you should use && as that would make it so that both have to be less than 40 to fail whereas with || you are making it so that both have to be 40 or more in order to pass.