Это ваша проблема, вы не можете иметь методы в рамках метода. Но это было связано с тем, что вы не закрывали свои скобки для своих методов. Я установил свой код и добавил методы, которые вы хотели:
public class MyRectangle {
//Best to group your variables up here
public int MyRectangle;
public int width;
public int height;
public int y;
public int x;
public MyRectangle() {
width = 10;
height = 10;
y = 10;
x = 10;
}//Make sure to close this method with the bracket
public MyRectangle(int width, int height, int y, int x, int MyRectangle) {
this.width = width;
this.height = height;
this.y = y;
this.x = x;
this.MyRectangle = MyRectangle;
}
/**
* Changes the current height to the given new height
* @param newHeight
*/
public final void changeHeight(int newHeight) {
height = newHeight;
}
/**
* Changes the current width to the given new width
* @param newWidth
*/
public final void changeWidth (int newWidth) {
width = newWidth;
}
/**
* Calculates the current perimeter based on the width and height
* @return parameter ofd the rectangle
*/
public final int getPerimeter() {
return ((2 * width) + (2 * height));
}
/**
* Calculates the area based on the width and height
* @return area of the rectangle
*/
public final int getArea() {
return (width * height);
}
public final void changesXCoordinate(int newX){
x = newX;
}
public final void changesYCoordinate(int newY){
y = newY;
}
public final void changesCoordinate(int newX, int newY) {
x = newX;
y = newY;
}
}
поясню более скоро, просто хотел, чтобы отправить правильный код первой: P
Как можно заметить, это своего рода трудно понять, что еще ты ищешь.
Если это то, что вы ищете, пожалуйста, отметьте это как правильный ответ: D
В чем вопрос? и почему вы устанавливаете переменную с тем же именем, что и класс, сначала измените это имя, чтобы ваш класс мог появиться больше readbale. – Tarik
Вы забыли закрыть '}' в своем первом конструкторе. Проверьте код на наличие синтаксических ошибок. –
Вы не можете объявить 'public int MyRectangle;' внутри метода и не можете объявить метод в методе – TheMuffinCoder