I am having trouble with part of my java project I have to do during the summer.I was able to complete one of the assignments, but not the second one. I was wondering if any of you could help me with the following assignment:
A trapezoid is a geometric shape that has four sides. Two of these are parallel and are called the bases of the trapezoid. The height is the distance between the bases. Define a Trapezoid class that encapsulates the height and the length of each base. Provide a constructor that initializes these instance variables. Provide one instance method that calculates the area of the shape. The area equals 0.5 *height *(base1+base2). Instantiate an object of this class and invoke its method.
Comments
:
: A trapezoid is a geometric shape that has four sides. Two of these are parallel and are called the bases of the trapezoid. The height is the distance between the bases. Define a Trapezoid class that encapsulates the height and the length of each base. Provide a constructor that initializes these instance variables. Provide one instance method that calculates the area of the shape. The area equals 0.5 *height *(base1+base2). Instantiate an object of this class and invoke its method.
:
Here's a start. There are several things which you need to write, but that shouldn't be too difficult.
[code]
public class Trapezoid {
private int topBase;
private int bottomBase;
public Trapezoid(int base1, int base2) {
super;
setToBase(base1)
// Add additional initializations
}
public int getTopBase() {
// write yourself
}
public void setTopBase(int value) {
// write yourself
}
// Add also access methods for bottomBase
public double getArea() {
// Perform calculation and return result;
}
}
[/code]
: : I am having trouble with part of my java project I have to do during the summer.I was able to complete one of the assignments, but not the second one. I was wondering if any of you could help me with the following assignment:
: :
: : A trapezoid is a geometric shape that has four sides. Two of these are parallel and are called the bases of the trapezoid. The height is the distance between the bases. Define a Trapezoid class that encapsulates the height and the length of each base. Provide a constructor that initializes these instance variables. Provide one instance method that calculates the area of the shape. The area equals 0.5 *height *(base1+base2). Instantiate an object of this class and invoke its method.
: :
: Here's a start. There are several things which you need to write, but that shouldn't be too difficult.
: [code]
: public class Trapezoid {
:
: private int topBase;
: private int bottomBase;
:
: public Trapezoid(int base1, int base2) {
: super;
: setToBase(base1)
: // Add additional initializations
: }
:
: public int getTopBase() {
: // write yourself
: }
: public void setTopBase(int value) {
: // write yourself
: }
: // Add also access methods for bottomBase
:
: public double getArea() {
: // Perform calculation and return result;
: }
: }
: [/code]
:
Thanks, that helped allot