import javabook.*;
class Triangle
{
// DATA
//............................................................
//Private Variables
private double theBase;
private double theHeight;
private double theArea; //base and height = Area is enough calculation
// CONSTRUCTORS
//............................................................ // same name as the class and the file name
public Triangle()
{
this.theBase=0;
this.theHeight=0;
this.theArea=0;
}
public Triangle(OutputBox oBox, MainWindow mWindow)
{
this.theBase=0;
this.theHeight=0; this.theArea=0; //This is a proof that the area of any triangle is 1/2 b x h’ of a base and height and the ‘area of a triangle is half of the base times the height’.
}
public void calculateArea()
{
InputBox iBox = new InputBox(mWindow);
this.theBase = iBox.getDouble("Please enter the length of the base of the triangle ");
this.theHeight = iBox.getDouble("Please enter the height of the triangle");
computeArea();
oBox.println(" The area of a triangle of base : " + this.theBase+ " and height : " + this.theHeight +" is equal to : "+ this.theArea);
}
// METHODS - behaviours
//............................................................
public void computeArea()
{
this.theArea = (this.theBase/2) * this.theHeight;
}
// METHODS - gets (accessors) and sets (mutators)
//............................................................
//length
public void setThebase(double base)
{
this.theBase= base;
}
public double getTheBase()
{
return(this.theBase);
}
//breath
public void setTheHeight(double height)
{
this.theHeight= height;
}
public double getTheHeight()
{
return(this.theHeight);
}
//area
public double getTheArea()
{
return(this.theArea);
}
}
Я-то не хватает или выше this.theBase = iBox.getDouble («Пожалуйста, введите длину основания треугольника»); Может ли кто-нибудь указать на то, что я оставил? Будьте осторожны, поскольку я изучаю Java и обязан совершать ошибки.Отсутствует ключ точка на Вычислите площадь треугольника
Это переработанные сообщения об ошибках после фиксации фиктивного {характера:
]./Triangle.java:42: cannot find symbol
symbol : variable mWindow
location: class Triangle
InputBox iBox = new InputBox(mWindow);
^
./Triangle.java:46: cannot find symbol
symbol : variable oBox
location: class Triangle
oBox.println(" The area of a triangle of base : " + this.theBase+ " and height : " + this.theHeight +" is equal to : "+ this.theArea);
Обновлен 4 ошибки:
./Triangle.java:36: cannot find symbol
symbol : variable oBox
location: class Triangle
this.oBox = oBox;
^
./Triangle.java:37: cannot find symbol
symbol : variable mWindow
location: class Triangle
this.mWindow = mWindow; //This is a proof that the area of any triangle is 1/2 b x h’ of a base and height and the ‘area of a triangle is half of the base times the height’.
^
./Triangle.java:47: cannot find symbol
symbol : variable mwindow
location: class Triangle
InputBox iBox = new InputBox(mwindow);
^
./Triangle.java:51: cannot find symbol
symbol : variable oBox
location: class Triangle
oBox.println(" The area of a triangle of base : " + this.theBase+ " and height : " + this.theHeight +" is equal to : "+ this.theArea);
^
Note: App.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
4 errors
^
"что-то не хватает" - вы получаете какие-либо сообщения об ошибках? Если да, отправьте их, пожалуйста. – Sirko
Я добавил сообщения об ошибках, как указано выше. – Irishgirl
Отсутствует точка с запятой после 'this.theHeight = 0' (в дополнение к другим упомянутым ошибкам). – iamnotmaynard