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 4 of 4

Thread: How to fix this class/program

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Location
    De Panne (Belgium)
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default How to fix this class/program

    Last week we received a test about Java Fundamentals and I wasn't able to finish it, I was wondering if someone could explain it to how to get it done.
    The task was this:
    Complete the program with collections, generics,... to get this output:

    Room 11 has Hans Desmet as it's teacher
    Felix De Vliegher follows basis
    Koen Vanhoutte follows java
    Serge Vereecke follows java
    Freddy Himpe follows .net

    Room 11 has Hans Desmet as it's teacher
    There are 4 cursisten
    Felix De Vliegher follows C++
    Serge Vereecke follows java
    Freddy Himpe follows .net
    Alexandra Blondeel follows java

    and this was given

     public class Main  {   
     
     
        public static void main(String[] args) {
     
           Traject traject1 = new Traject("c++");
           Traject traject2 = new Traject("java");
           Traject traject3 = new Traject(".net");
           Traject traject4 = new Traject("basis");
           Cursist cursist1 = new Cursist("Felix"   , "De Vliegher"  ,  traject4);
           Cursist cursist2 = new Cursist("Koen"    , "Vanhoutte,"   ,  traject2);
           Cursist cursist3 = new Cursist("Serge"   , "Vereecke"     ,  traject2);
           Cursist cursist4 = new Cursist("Freddy"  , "Himpe"        ,  traject3);
           Instructeur instructeur = new Instructeur("Hans","Desmet");
           Lokaal lokaal = new Lokaal(11, instructeur);
           lokaal.add(cursist1);
           lokaal.add(cursist2);
           lokaal.add(cursist3);
           lokaal.add(cursist4);
           System.out.println(lokaal);
           cursist1.setTraject(traject1);
           Cursist cursist5 = new Cursist("Alexandra" , "Blondeel", traject2);
           lokaal.remove(cursist2);
           System.out.println(lokaal);
     
     
        }
    }


    --- Update ---

    So far I made these classes:
    i think in class Lokaal is everything wrong but I have no idea how to fix it....

    public class Traject {
        public Traject(String traject) {
            setTraject(traject);        
        }
     
        private String traject;
     
        public String getTraject() {
            return traject;
        }
     
        public void setTraject(String traject) {
            this.traject = traject;
        }
        @Override
         public String toString(){
             return traject;
         }
     
     
    }


    public class Lokaal extends Main {
     
        private int nr;
        private int aantalCursisten;
     
        public Lokaal(int nr, Cursist cursist, Traject traject){
            setNr(nr);       
        }
     
        public Lokaal(int nr, Instructeur instructeur){}
     
     
        public int getNr() {
            return nr;
        }
     
        private void setNr(int nr) {
            this.nr = nr;
        }
     
        public void aantalCursisten(int aantal){
            aantalCursisten += aantal;
        }
     
        public void toevoegen(Cursist cursist){
     
        }
         public void remove(Cursist cursist){
     
        }
     
    }


    public class Instructeur {
        public Instructeur(String naam, String familieNaam) {
            setNaam(naam);
            setFamilieNaam(familieNaam);
        }
     
        private String naam;
        private String familieNaam;
     
        public String getNaam(){
            return naam;
        }
     
        public String getFamilieNaam(){
            return familieNaam;
        }
     
        private void setFamilieNaam(String familieNaam){
            this.familieNaam = familieNaam;
        }
     
        private void setNaam(String naam) {
            this.naam = naam;
        }  
     
     
    }


    public class Cursist  {
        public Cursist(String naam, String familieNaam) {
            setNaam(naam);
            setFamilieNaam(familieNaam);
        }
        public Cursist(String naam, String familieNaam, Traject traject){}
     
        private String naam;
        private String familieNaam;
     
        public String getNaam() {
            return naam;
        }
     
        private void setNaam(String naam) {
            this.naam = naam;
        }
     
        public String getFamilieNaam() {
            return familieNaam;
        }
     
        private void setFamilieNaam(String familieNaam) {
            this.familieNaam = familieNaam;
        }
     
        public void setTraject(Traject traject) {
     
        }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: How to fix this class/program

    What exactly is wrong about it? Do you see a compiler error? A runtime Exception? Some strange behavior? Something else?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Location
    De Panne (Belgium)
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: How to fix this class/program

    I don't get the required output:

    Room 11 has Hans Desmet as it's teacher
    Felix De Vliegher follows basis
    Koen Vanhoutte follows java
    Serge Vereecke follows java
    Freddy Himpe follows .net

    Room 11 has Hans Desmet as it's teacher
    There are 4 cursisten
    Felix De Vliegher follows C++
    Serge Vereecke follows java
    Freddy Himpe follows .net
    Alexandra Blondeel follows java

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: How to fix this class/program

    What happened when you stepped through it with a debugger, or added some print statements to figure out what's going on? At what point does your program's execution differ from what you'd expect? Boil it down to that and create an SSCCE, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 25th, 2013, 12:36 AM
  2. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2013, 01:49 PM
  3. [SOLVED] How can i fix and run my program?? Please help..
    By BeginCode in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 7th, 2012, 08:03 PM
  4. How do I fix my program?
    By mjballa in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 15th, 2011, 12:00 AM
  5. can u guys help me fix my program
    By nima9006 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2010, 03:43 AM