Jump to content

Help with array of structures

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Animus

Animus

    Newbie

  • Members
  • PipPip
  • 26 posts
*SIGH*

Can somebody help me with this?

im trying to create a seatplan program with the following objectives.

1.Allows the user to input a students name,
2.Program then searches the name on a premade list.
3 then prints out the students name, age, chair location.

This is all hay to be done with array of structures.
basically we divided each element into different classes,
but the problem is when we try it writing it into our Main class.
it doesnt accept it, we ended up making the link to the class into an array, but when it comes to inputing certain errors come up. :(


public class Main {


    

    public static void main(String[] args) {

        

        Student students[]=new Student[32];

        Student comp=new Student(StudentName.class,17,12,StudentChairLocation.class);



        System.out.print(comp.name.First);



  

    }


}


public class Student {

    StudentName name;

    int age;

    String course;

    StudentChairLocation chairLocation;

    public Student(StudentName n,int a, String c, StudentChairLocation cl){

        name=n;

        age=a;

        course=c;

        chairLocation=cl;


    }


    

    

}



public class StudentChairLocation {

    int Row;

    int Column;

    public StudentChairLocation(int r,int c){

        Row=r;

        Column=c;

    }

}



public class StudentName {

    String First;

    String Midle;

    String Last;

    public StudentName(String f,String m,String l){

        First=f;

        Midle=m;

        Last=l;

    }

}


#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
[LEFT][COLOR=#333333]new Student(StudentName.class,17,12,StudentChairLocation.class);[/COLOR][/LEFT]
You're passing classes instead of objects of the classes like
[LEFT][COLOR=#333333]new Student(new StudentName("a", "b","c"),17,12, new StudentChairLocation(0,1));[/COLOR][/LEFT]


#3
Animus

Animus

    Newbie

  • Members
  • PipPip
  • 26 posts
i see thank you.
one more thing.
can somebody tell me how do i put all these method into a single array element? :sleep:
i been nagging since last week.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users