Results 1 to 4 of 4
  1. #1
    puchatek is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default Help with my Java program

    I have just began studying Java and I've been enjoying it. However I can't figure out how to write a method for e.g. a method to add a new student name to a school. I've been using BlueJ.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    That should get you started. It describes method declaring, parameters, and how to add those to a class.

  3. #3
    puchatek is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    Thank you for the link. Here is currently what I wrote down at the moment.

    Java Code:
    public class School
    {
    
    private String StudentName;
    
    
    public void StudentName(String Name)
    {
        StudentName = Name;
    }
    public String getStudentName()
    {
        return StudentName;
    }
    
    }
    Its working so far. But it only allows me to add 1 student. What should I change to enable me to add more than 1 student?

    Thanks

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Create a class Student and have School hold an ArrayList<Student>, a collection of Students. Of if you're not at the point of creating classes, then have ArrayList hold String, ArrayList<String> and have an add method to add Strings to this list.

Similar Threads

  1. Replies: 8
    Last Post: 09-30-2010, 06:32 PM
  2. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •