Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo

ich versuche gerade n:m Beziehungen mit Hilfe von Assoziationsklassen herzustellen.

Mein Projekt : Schule

Ich arbeite mit BLUEJ

Klasse der Schulklasse:



public class SCHULKLASSE

{

    private String name;

    private int Klassenzimmer;

    private String zweig;


    public SCHULKLASSE(String n)

    {

        name = n;

    }



    }




Lehrerklasse:


public class LEHRER

{

    private int persnr;

    private String nachname;

    private String amtsbezeichung;

    public LEHRER(int nr  )

    {

        persnr= nr;

    }




}

Hilfsklasse der Assoziationsklasse(LEHRERKLASSE):

public class LEHRERKLASSE

{

    private SCHULKLASSE klasse;

    private LEHRER person;

    public LEHRERKLASSE(SCHULKLASSE kla, LEHRER per)


    {   klasse=kla;

        person= per;


    }




}



Beziehung UNTERRICHTET:


public class UNTERRICHTET

{

    private LEHRERKLASSE[] klehrer;


    public UNTERRICHTET()

    {

        klehrer = new LEHRERKLASSE[100];


    }


    public void Lehrer_zuordnen(SCHULKLASSE sklasse, LEHRER person){

        klehrer= new LEHRERKLASSE(sklasse, person);

    }

}



Mein Problem ist Folgendes: Beim Übersetzen der Klasse UNTERRICHTET erscheint folgende Fehlermeldung in der Zeile

" klehrer= new LEHRERKLASSE(sklasse, person);"

incompatible types-found LEHRERKLASSE but expected LEHRERKLASSE[]

Was hab ich falsch gemacht? Wie kann ich den Fehler beheben?

Bearbeitet von Senf

Generell ein Tip: Halte Dich an die allgm gültige Notation, in der Klassen nicht Uppercase benannt werden.

In Deiner Methode "Lehrer_zuordnen" weist Du klehrer ein neues Objekt einer (!) Lehrerklasse zu, da klehrer als Array deklariert ist, wird das nicht funktionieren. Entweder musst Du klehrer anders deklarieren und dann verwenden oder Du weist das neue Objekt einer entsprechenden Position des Arrays zu. Generell würde ich in diesem Fall davon abraten Arrays zu verwenden, da diese statisch sind. Schau Dir das Collectioninterface an (Collection (Java 2 Platform SE v1.4.2) )

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.