S
Stefan5678
Gast
Hallo Leute ich hab folgendes Problem:
Muss eine Klasse Rectangle (Rechteck) erstellen mit 3 verschiedenen
Konstruktoren und verschiedenen anderen get und set Methoden.
Methoden: (ich schreib die auf englisch auf)
A default constructor that initializes xPos and yPos to zero and width and height
to one.
A constructor that takes two double parameters which specify values for width
and height (in that order).
A constructor that takes four double parameters which specify values for xPos,
yPos, width and height (in that order).
void setPos(double x, double y)
double getXPos()
double getYPos()
double getWidth()
double getHeight()
double getArea() should return width*height
String toString() should return the string "Rectangle (xPos, yPos) - (xPos+width,
yPos+height)", with xPos, yPos, width and height replaced by the actual values
void printShape() should print the rectangle on the screen using * characters. The
double values used for position and size can be rounded into int values by casting.
In der Main sollen dann 2 Rechteckobjekte erstellt werden und einmal über
System.out.println(rectangle); und einmal über rectangle.printShape
ausgegeben werden. Wobei das "rectangle" durch den jeweiligen Objektnamen
ersetzt werden muss. Also z.b. Rechteck1 und Rechteck2 oder so.
Also letztes sollst du noch eine TestRectangles.java machen.
Dafür musst du die Rectangle.java "compareable" machen. Wie das genau geht,
weiß ich auf anhieb nicht mehr.
Und du sollst wohl 10 Rechtecke in eine geeignete Collection speichern und
diese dann mit dem TestRectangles vergleichen und quasi der Größe nach
sortieren. Also nach Flächeninhalt.
die ganze Aufgabe nochmal in englisch falls ich was flasch übersetzt habe ;-)
Rectangle.java
1. Create a class named Rectangle. It should have the following private fields which represent
the position and size of a rectangle in 2D:
· A double named xPos
· A double named yPos
· A double named width
· A double named height
It should have the following public methods:
· A default constructor that initializes xPos and yPos to zero and width and height
to one.
· A constructor that takes two double parameters which specify values for width
and height (in that order).
· A constructor that takes four double parameters which specify values for xPos,
yPos, width and height (in that order).
· void setPos(double x, double y)
· double getXPos()
· double getYPos()
· double getWidth()
· double getHeight()
· double getArea() should return width*height
· String toString() should return the string "Rectangle (xPos, yPos) - (xPos+width,
yPos+height)", with xPos, yPos, width and height replaced by the actual values
· void printShape() should print the rectangle on the screen using * characters. The
double values used for position and size can be rounded into int values by casting.
2. Add a main method (public static void main(String [] args)), that...
· Creates the following objects:
o A default Rectangle
o A Rectangle that goes from (2,2) to (4,6)
· Performs System.out.println(rectangle); for both of the above objects.
· Performs rectangle.printShape(); for both of the above objects.
TestRectangles.java
This assignment will get you using collections, comparators and the online documentation!
Bitte um eure Hilfe, weil ich jetzt zimmlich ratlos bin.
Vielen Dank im Vorraus.
Gruß
Stefan
Muss eine Klasse Rectangle (Rechteck) erstellen mit 3 verschiedenen
Konstruktoren und verschiedenen anderen get und set Methoden.
Methoden: (ich schreib die auf englisch auf)
A default constructor that initializes xPos and yPos to zero and width and height
to one.
A constructor that takes two double parameters which specify values for width
and height (in that order).
A constructor that takes four double parameters which specify values for xPos,
yPos, width and height (in that order).
void setPos(double x, double y)
double getXPos()
double getYPos()
double getWidth()
double getHeight()
double getArea() should return width*height
String toString() should return the string "Rectangle (xPos, yPos) - (xPos+width,
yPos+height)", with xPos, yPos, width and height replaced by the actual values
void printShape() should print the rectangle on the screen using * characters. The
double values used for position and size can be rounded into int values by casting.
In der Main sollen dann 2 Rechteckobjekte erstellt werden und einmal über
System.out.println(rectangle); und einmal über rectangle.printShape
ausgegeben werden. Wobei das "rectangle" durch den jeweiligen Objektnamen
ersetzt werden muss. Also z.b. Rechteck1 und Rechteck2 oder so.
Also letztes sollst du noch eine TestRectangles.java machen.
Dafür musst du die Rectangle.java "compareable" machen. Wie das genau geht,
weiß ich auf anhieb nicht mehr.
Und du sollst wohl 10 Rechtecke in eine geeignete Collection speichern und
diese dann mit dem TestRectangles vergleichen und quasi der Größe nach
sortieren. Also nach Flächeninhalt.
die ganze Aufgabe nochmal in englisch falls ich was flasch übersetzt habe ;-)
Rectangle.java
1. Create a class named Rectangle. It should have the following private fields which represent
the position and size of a rectangle in 2D:
· A double named xPos
· A double named yPos
· A double named width
· A double named height
It should have the following public methods:
· A default constructor that initializes xPos and yPos to zero and width and height
to one.
· A constructor that takes two double parameters which specify values for width
and height (in that order).
· A constructor that takes four double parameters which specify values for xPos,
yPos, width and height (in that order).
· void setPos(double x, double y)
· double getXPos()
· double getYPos()
· double getWidth()
· double getHeight()
· double getArea() should return width*height
· String toString() should return the string "Rectangle (xPos, yPos) - (xPos+width,
yPos+height)", with xPos, yPos, width and height replaced by the actual values
· void printShape() should print the rectangle on the screen using * characters. The
double values used for position and size can be rounded into int values by casting.
2. Add a main method (public static void main(String [] args)), that...
· Creates the following objects:
o A default Rectangle
o A Rectangle that goes from (2,2) to (4,6)
· Performs System.out.println(rectangle); for both of the above objects.
· Performs rectangle.printShape(); for both of the above objects.
TestRectangles.java
This assignment will get you using collections, comparators and the online documentation!
Bitte um eure Hilfe, weil ich jetzt zimmlich ratlos bin.
Vielen Dank im Vorraus.
Gruß
Stefan