MIDTERM MAC190 Dr. Omar Ait Hellal I. Design and code a class Rectangle that has the following properties: · Two private double members length and width · A constructor that accepts two parameters for...

1 answer below »
Java script you can send code on microsoft word with steps please.





MIDTERM MAC190 Dr. Omar Ait Hellal I. Design and code a class Rectangle that has the following properties: · Two private double members length and width · A constructor that accepts two parameters for the private members · Default constructor that sets both members to 0 · Accessor (getter) for each private member · Mutator (setter) for each private member · Method area() that returns the area of the rectangle · Method Perim() that returns the perimeter of the rectangle · Method toString that return the param as a String · Method Add that accepts a Rectangle and returns a rectangle with length as sum of lengths of this and the input rectangle and the width as the sum too. This should not ne modified. · Method equals() that accepts a rectangle and returns true if the two rectangles are the same and false if not. II. Design a class Cube, that has the following properties: · A base as a Rectangle object and a height. So your class has two private members: Rectangle base and double height. · A default constructor tht sets the base to default Rectangle and height to 0 · A Constructor that accepts a Rectangle and a double · A constructor that accepts three doubles · Getters/setters (also getters/setters for length and width) · Method Area(), that computes the areas of all surfaces of the cube; use any already defines method previously in Rectangle class. · Method Volume() that computes the volume, use any already defines method previously in Rectangle class. · Method add that accepts a Cube and returns the sum of this and the input Cube, without changing this object · toString() that returns the object as a string · equals() that accepts a Cube and returns true if the two are the same. Use previously defined methods in this class or in the Rectangle class whenever possible. III. Write a program to test both classes. Try to use as many of the public constructors and methods as possible.
Answered 1 days AfterApr 23, 2022

Answer To: MIDTERM MAC190 Dr. Omar Ait Hellal I. Design and code a class Rectangle that has the following...

Dipansu answered on Apr 25 2022
95 Votes
class Rectangle {
    height = 0.00;
    width  = 0.00
    constructor(height=0, width=0) {
  this.height = height;
      this.width = width;
    }

    get height() {
      return this.height;
    }

    set height(v) {
      assert.ok(typeof v === 'number', 'Height must be a number');
      return v;
    }

    get width() {
      return this.width;
    }

    set width(v) {
      assert.ok(typeof v === 'number', 'Width must be a number');
      return v;
    }
    area(){
        return this.width * this.height;
    }
    Perim(){
        return 2*(this.width + this.height);
    }
    toString(){
        return this.width.toString()+" is the width and the height is "+this.height.toString()
    }
    equal(a, b)
    {
        if (a === b) return true;

        if (isNaN(a.x) != isNaN(b.x)) return false;
        if (!isNaN(a.x) && !isNaN(b.x) && a.x != b.x) return false;
        if (isNaN(a.y) != isNaN(b.y)) return false;
        if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here