This discussion is archived
9 Replies Latest reply: Apr 17, 2012 6:22 AM by gimbal2 RSS

There is something wrong with my method.

911664 Newbie
Currently Being Moderated
Hello,
I am trying to write diffrent classes and investigating how they work together. I have encounter that my method which is called pupil2() is not working. And I have no explanation.
class Student{ 
    
    
        String name;
        int age;
        String city;
        String father;
        int brothers ;
       
}
class TheStudent{
    
     public Student pupil(){
           Student st = new Student();
            st.age = 2;
            st.brothers = 2;
            st.city = "London";
            st.father = "Simon";
            st.name = "Carl";
            
        return st;
        
        public Student pupil2(){
           Student st2 = new Student();
            st2.age = 2;
            st2.brothers = 2;
            st2.city = "London";
            st2.father = "Simon";
            st2.name = "Carl";
            
        return st2;
}
}
class StudentInfo{
    
    private void children(){
         
         
     }
    
     public static void main(String args[]) {
        TheStudent oneStudent = new TheStudent();
       System.out.println (" The name of the student" + oneStudent.pupil().city );; 
    }
    
  • 1. Re: There is something wrong with my method.
    DrClap Expert
    Currently Being Moderated
    What makes you think it is "not working"?
  • 2. Re: There is something wrong with my method.
    911664 Newbie
    Currently Being Moderated
    Beacuse Netbeans shows me red shepes.
  • 3. Re: There is something wrong with my method.
    rp0428 Guru
    Currently Being Moderated
    >
    And I have no explanation.
    >
    Have you counted the number of '{' compared to the number of '}' in the code below?
    class TheStudent{
        
         public Student pupil(){
               Student st = new Student();
                st.age = 2;
                st.brothers = 2;
                st.city = "London";
                st.father = "Simon";
                st.name = "Carl";
                
            return st;
            
            public Student pupil2(){
               Student st2 = new Student();
                st2.age = 2;
                st2.brothers = 2;
                st2.city = "London";
                st2.father = "Simon";
                st2.name = "Carl";
                
            return st2;
    }
    }
    {quote}
    If not, count them and see if you get the same number.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 4. Re: There is something wrong with my method.
    EJP Guru
    Currently Being Moderated
    There is something wrong with my method.
    There is also something wrong with your question. There isn't one.
    And I have no explanation.
    And you have no question. And you have furnished no facts for anyone else to help you.

    Instead you have just posted all the source code in the unrealistic expectation that someone will read it all or possibly copy it, paste into a local editor, compile it, view the error messages, and tell you what's wrong.

    That's not the idea. The idea is that you post the error messages here.
  • 5. Re: There is something wrong with my method.
    930029 Newbie
    Currently Being Moderated
    908661 wrote:
    Hello,
    I am trying to write diffrent classes and investigating how they work together. I have encounter that my method which is called pupil2() is not working. And I have no explanation.
    class Student{ 
    
    
    String name;
    int age;
    String city;
    String father;
    int brothers ;
    
    }
    class TheStudent{
    
    public Student pupil(){
    Student st = new Student();
    st.age = 2;
    st.brothers = 2;
    st.city = "London";
    st.father = "Simon";
    st.name = "Carl";
    
    return st;
    
    public Student pupil2(){
    Student st2 = new Student();
    st2.age = 2;
    st2.brothers = 2;
    st2.city = "London";
    st2.father = "Simon";
    st2.name = "Carl";
    
    return st2;
    }
    }
    class StudentInfo{
    
    private void children(){
    
    
    }
    
    public static void main(String args[]) {
    TheStudent oneStudent = new TheStudent();
    System.out.println (" The name of the student" + oneStudent.pupil().city );; 
    }
    one reason i understand can be becos u have not closed method pupil() after return.

    would be good if u post exact error message
  • 6. Re: There is something wrong with my method.
    aksarben Journeyer
    Currently Being Moderated
    And it would be good if you use standard English instead of childish IM-speak. Be aware that many forum members are not native English speakers and will be baffled by immature attempts at cuteness.
  • 7. Re: There is something wrong with my method.
    927244 Newbie
    Currently Being Moderated
    Just change code of TheStudent class as given below .
    class TheStudent{
        
         public Student pupil(){
               Student st = new Student();
                st.age = 2;
                st.brothers = 2;
                st.city = "London";
                st.father = "Simon";
                st.name = "Carl";
                
            return st;
        }    
            public Student pupil2(){
               Student st2 = new Student();
                st2.age = 2;
                st2.brothers = 2;
                st2.city = "London";
                st2.father = "Simon";
                st2.name = "Carl";
                
                return st2;
           }
    }
    Regards VIDs
  • 8. Re: There is something wrong with my method.
    796440 Guru
    Currently Being Moderated
    VID wrote:
    Just change code of TheStudent class as given below .
    Please don't do the OP's work for him. That's not helpful.
  • 9. Re: There is something wrong with my method.
    gimbal2 Guru
    Currently Being Moderated
    jverd wrote:
    VID wrote:
    Just change code of TheStudent class as given below .
    Please don't do the OP's work for him. That's not helpful.
    You know I was about to press the submit button to say something exactly to this effect... but why bother? After VID, there is always the next guy to not understand what they're really doing. And the next. And the next. It never ends :/ Besides, you'd wonder if the OP really deserves a helpful answer when not even asking any kind of half-decent question; just dumping the solution without any further explanation whatsoever doesn't seem inappropriate in the context of this thread IMO.

    Or perhaps I'm more of a bum today than I usually am. I'll just go stand in the corner for about half an hour to rethink my actions, just to be sure.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points