Jump to content

How to get one object from a class with multiple objects.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Animus

Animus

    Newbie

  • Members
  • PipPip
  • 26 posts
kay im making a premade list where each student has different courses, the problem is when its printing i can only have one object for all students, there are three courses IT, CS, ACT. each student has different courses, how do you make it different for each student, if your bounded with this?


list[0] =new Student(new StudentName("Ma", "J","jame"),19,new Course("BSCS", "BSIT", "BSACT"),new StudentChairLocation(1,1));

         list[1]=new Student(new StudentName("Mike", "j","Cek"),17,new Course("BSCS", "BSIT", "BSACT"),new StudentChairLocation(2,1));



JOptionPane.showMessageDialog(null,"Course:"+list[i].course.BSACT);


Class:
public class Course {

    String BSCS;

    String BSIT;

    String BSACT;


    public Course(String c,String i,String a ){

        BSCS=c;

        BSIT=i;

        BSACT=a;


    }



#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You'll first need to build the complete string with the info of the whole List. And then use the complete String to display it.

Use StringBuilder to do this, like:

StringBuilder sb = new StringBuilder("");


<--Loop students

sb.append(list[i].getName()).append("\n");


  <--Loop courses

     sb.append("\t").append(list[i].getCourse(i)).append("\n");

   end loop -->


end loop-->


JOptionPane.showMessageDialog(null, sb.toString());







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users