Guten Tag,
Ich habe folgendes Problem mit meinem Code.
Ich kann die Referenzen von der Klasse MediaAdmin nicht in der Klasse Medium oder MediaCopy aufrufen. Die Klassen sind alle Public. Ich habe die Aufgabe von meinem Prof bekommen und soll sie vervollständigen. Ich schicke euch einmal die Aufgabe die ich von Prof bekommen habe + Aufgabenstellung und danach die ausgearbeitete von mir. Die Klasse MediaAdmin darf ich NICHT verändern. Die Aufgabenstellung schicke ich auch mal dazu. Wobei ihr die Klasse MediaCopy erstmal überspringen könnt. Habe diese nur mal dazu gepostet das es vollständig ist.
Hier die 3 Klassen und danach die Aufgabenstellung:
Aufgabenstellung:
LadenSiedasProjekt MediaAdmin. Es enthält drei Klassen: Medium, MediaCopy und MediaAdmin
Lassen Sie die Klasse MediaAdmin unverändert.
Vervollständigen Sie die Implementierung der Klassen Medium, und MediaCopy. Das Programmms sollte folgende Ausgabe erzeugen:
Medium, id: 11, title: aaa
comparing media:
medium_1, medium_2: false
medium_4, medium_3: false
medium_1, medium_4: true
comparing copies:
copy_1, copy_2: false
copy_1, copy_3: true
copy_1, copy_3: false
Copy signature: 321, loation: K102
Copy signature: 321, loation: K102 Medium, id: 11, title: aaa
Mein ausgearbeitetes:
Hier mein geschriebenes für die Klasse Medium. Media Admin bleibt ja gleich. MediaCopy lasse ich einfach erstmal weg.
if ( ??????? != otherMedium )
Hier bei den Fragezeichen ist meine Frage, wie setze ich das um das er jede Referenz dort einfügt und diese dann testet? Es muss ja dreimal durchlaufen werden.
Ich weiß es ist einiges das ich hier gepostet habe.
Aber vielleicht kann mir ja trotzdem jemand weiter helfen.
Meinem Prof hab ich schon eine Email geschrieben, aber er antwortet mir nicht und ich sehe ihn auch jetzt längere zeit nicht mehr.
Also vielen dank mal im vorraus
Ich habe folgendes Problem mit meinem Code.
Ich kann die Referenzen von der Klasse MediaAdmin nicht in der Klasse Medium oder MediaCopy aufrufen. Die Klassen sind alle Public. Ich habe die Aufgabe von meinem Prof bekommen und soll sie vervollständigen. Ich schicke euch einmal die Aufgabe die ich von Prof bekommen habe + Aufgabenstellung und danach die ausgearbeitete von mir. Die Klasse MediaAdmin darf ich NICHT verändern. Die Aufgabenstellung schicke ich auch mal dazu. Wobei ihr die Klasse MediaCopy erstmal überspringen könnt. Habe diese nur mal dazu gepostet das es vollständig ist.
Hier die 3 Klassen und danach die Aufgabenstellung:
Java:
/*
* To change this template, choose Tools | Templates
* and open the template consoleInput the editor.
*/
package mediaadmin;
public class MediaAdmin {
static MediaAdmin singleInstance;
private MediaAdmin() {
}
public static void main(String[] args) {
MediaAdmin mediaAdmin = getInstance();
mediaAdmin.testMedium();
mediaAdmin.testCopy();
return;
}
void testMedium() {
Medium aMedium_1 = new Medium(11, "aaa");
Medium aMedium_2 = new Medium(11, "bbb");
Medium aMedium_3 = new Medium(22, "aaa");
Medium aMedium_4 = new Medium(11, "aaa");
aMedium_1.print();
System.out.println();
System.out.println(" comparing media:");
boolean comp = aMedium_1.equals(aMedium_2);
System.out.println(" medium_1, medium_2: " + comp);
comp = aMedium_2.equals(aMedium_3);
System.out.println(" medium_4, medium_3: " + comp);
comp = aMedium_1.equals(aMedium_4);
System.out.println(" medium_1, medium_4: " + comp);
return;
}
void testCopy() {
MediaCopy aCopy_1 = new MediaCopy(321, "K102");
MediaCopy aCopy_2 = new MediaCopy(432, "L028");
MediaCopy aCopy_3 = new MediaCopy(321, "K102");
System.out.println(" comparing copies:");
boolean comp = aCopy_1.equals(aCopy_2);
System.out.println(" copy_1, copy_2: " + comp);
comp = aCopy_1.equals(aCopy_3);
System.out.println(" copy_1, copy_3: " + comp);
aCopy_1.theMedium = new Medium(11, "aaa");
comp = aCopy_1.equals(aCopy_3);
System.out.println(" copy_1, copy_3: " + comp);
aCopy_3.print();
System.out.println();
aCopy_1.print();
System.out.println();
return;
}
static MediaAdmin getInstance() {
if (singleInstance == null) {
singleInstance = new MediaAdmin();
}
return singleInstance;
}
}
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mediaadmin;
public class Medium {
int id;
String title;
// define a constructor that sets the values of
// the members id and title
Medium() {
}
void print() {
// print out the id and the title
System.out.print(" Medium, id: " . . .
System.out.print(", title: " . . .
}
boolean equals(Medium otherMedium){
// This method returns true if the members
// of this object hold the same values
// as the members of the other object.
// Otherwise it returns false.
// Hint: the clearest way is to test for inequality:
if ( . . . != . . . ) {
return false;
}
. . .
return . . .
}
}
Java:
package mediaadmin;
public class MediaCopy {
Medium theMedium; // a reference to a medium
// fill in the appropriate datatypes . . .
signature; // a member that holds an integer value
location; // a reference to a String object
// define a constructor that sets the values of
// the members signature and location
MediaCopy(int , String ) {
}
void print() {
// print out the signature and the location
System.out.print(" Copy signature: " . . .
System.out.print(", location: " . . .
// if this object contains reference to a medium-object (not null)
// then call the print-method of the medium-object
if . . .
return;
}
boolean equals(MediaCopy otherCopy) {
// This method returns true if the members
// of this object contain the same values
// as the members of the other object.
// Otherwise it returns false.
// Hint: the clearest way is to test for inequality:
if ( . . . != . . . ) {
return false;
}
// Hint 2: location is of type String.
// compare two string with location.equals( . . . )
. . .
return . . .
}
}
Aufgabenstellung:
LadenSiedasProjekt MediaAdmin. Es enthält drei Klassen: Medium, MediaCopy und MediaAdmin
Lassen Sie die Klasse MediaAdmin unverändert.
Vervollständigen Sie die Implementierung der Klassen Medium, und MediaCopy. Das Programmms sollte folgende Ausgabe erzeugen:
Medium, id: 11, title: aaa
comparing media:
medium_1, medium_2: false
medium_4, medium_3: false
medium_1, medium_4: true
comparing copies:
copy_1, copy_2: false
copy_1, copy_3: true
copy_1, copy_3: false
Copy signature: 321, loation: K102
Copy signature: 321, loation: K102 Medium, id: 11, title: aaa
Mein ausgearbeitetes:
Hier mein geschriebenes für die Klasse Medium. Media Admin bleibt ja gleich. MediaCopy lasse ich einfach erstmal weg.
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mediaadmin;
public class Medium {
int id;
String title;
// define a constructor that sets the values of
// the members id and title
Medium(int _id, String _title) {
id=_id;
title=_title;
}
void print() {
// print out the id and the title
System.out.print(" Medium, id: " + id);
System.out.print(", title: " + title);
}
boolean equals(Medium otherMedium){
// This method returns true if the members
// of this object hold the same values
// as the members of the other object.
// Otherwise it returns false.
// Hint: the clearest way is to test for inequality:
if ( ??????? != otherMedium ) {
return false;
}
else{
return true;
}
}
}
if ( ??????? != otherMedium )
Hier bei den Fragezeichen ist meine Frage, wie setze ich das um das er jede Referenz dort einfügt und diese dann testet? Es muss ja dreimal durchlaufen werden.
Ich weiß es ist einiges das ich hier gepostet habe.
Aber vielleicht kann mir ja trotzdem jemand weiter helfen.
Meinem Prof hab ich schon eine Email geschrieben, aber er antwortet mir nicht und ich sehe ihn auch jetzt längere zeit nicht mehr.
Also vielen dank mal im vorraus