1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
frozen [14]
3 years ago
12

Use the script below as a starting point to create a Rectangle class. Your rectangle class must have the following methods;A con

structor that takes a length and width as parametersgetArea - returns the area of the rectangleisSquare - returns True if length and width are equivalentoverloaded equivalence - compares the length and width of two rectangles and returns true if they are equivalent
Computers and Technology
1 answer:
Greeley [361]3 years ago
4 0

Answer:

The solution code is written in Java.

  1. public class Rectangle {
  2.    private double length;
  3.    private double width;
  4.    public Rectangle(double length, double width){
  5.        this.length = length;
  6.        this.width = width;
  7.    }
  8.    public double getArea(){
  9.        return this.length * this.width;
  10.    }
  11.    public boolean rectangleSquare(){
  12.        if(this.length == this.width){
  13.            return true;
  14.        }else{
  15.            return false;
  16.        }
  17.    }
  18.    public boolean equivalence(Rectangle rect){
  19.        if(this.width == rect.width && this.length == rect.length){
  20.            return true;
  21.        }else{
  22.            return false;
  23.        }
  24.    }
  25. }

Explanation:

Create a class, <em>Rectangle</em> (Line 1) and define two private attributes,<em> width </em>and <em>length</em> (Line 3 - 4). The reason to define the attributes as <em>double</em> type is because the width and length are presumed to be either an integer or a decimal value.

Create constructor which takes <em>width</em> and<em> length </em>as parameters (Line 6).

Next, the require methods, getArea(), isSquare() and overloaded equivalence() along with their expected parameters and return output, are created accordingly in Line 11 -28.

You might be interested in
A __________ note is a private note that you leave for yourself or for other people who might use the presentation file
BaLLatris [955]

Answer:

The answer is that it is a speaker note.

Explanation:

It leaves a note for people that use presentation files. I use it all the time on my google slides.

7 0
2 years ago
Comment on the following 2 arrays. int *a1[8]; int *(a2[8]); a1 is pointer to an array; a2 is array of pointers a1 is pointer to
Hitman42 [59]

Answer:

The answer is "a1 and a2 is an array of pointers".

Explanation:

In this question, A collection of pointers refers to an array of elements where each pointer array element points to a data array element. In the above-given statement, the two-pointer type array "a1 and a2" is declared that holds the same size "8" elements in the array, and each element points towards the array's first element of the array, therefore, both a1 and a2 are pointer arrays.

5 0
3 years ago
Comet Computer Company will make a splash with psychedelic laptop cover designs scheduled for release next year. The computers d
valkas [14]

Answer:

Packaging.

Explanation:

The following system corporation should allow the sensation of psychedelic laptop case patterns planned for these upcoming year's publication. The machines may not disclose any further variations in features from what the following corporation provides. The above effort illustrates using Packaging that distinguishes a commodity as fresh.

So, the following answer is correct according to the given statement.

6 0
3 years ago
Rather than entering an IP address into our browser, we use a text-based address known as a(n
zalisa [80]

Answer:

url

Explanation:

7 0
2 years ago
I have six nuts and six bolts. Exactly one nut goes with each bolt. The nuts are all different sizes, but it’s hard to compare t
juin [17]

Answer:

Explanation:

In order to arrange the corresponding nuts and bolts in order using quicksort algorithm, we need to first create two arrays , one for nuts and another for bolts namely nutsArr[6] and boltsArr[6]. Now, using one of the bolts as pivot, we can rearrange the nuts in the nuts array such that the nuts on left side of the element chosen (i.e, the ith element indexed as nutArr[i]) are smaller than the nut at ith position and nuts to the right side of nutsArr[i] are larger than the nut at position "I". We implement this strategy recursively to sort the nuts array. The reason that we need to use bolts for sorting nuts is that nuts are not comparable among themselves and bolts are not comparable among themselves(as mentioned in the question)

The pseudocode for the given problem goes as follows:

// method to quick sort the elements in the two arrays

quickSort(nutsArr[start...end], boltsArr[start...end]): if start < end: // choose a nut from nutsArr at random randElement = nutsArr[random(start, end+1)] // partition the boltsArr using the randElement random pivot pivot = partition(boltsArr[start...end], randElement) // partition nutsArr around the bolt at the pivot position partition(nutsArr[start...end], boltsArr[pivot]) // call quickSort by passing first partition quickSort(nutsArr[start...pivot-1], boltsArr[start...pivot-1]) // call quickSort by passing second partition quickSort(nutsArr[pivot+1...end], boltsArr[pivot+1...end])

// method to partition the array passed as parameter, it also takes pivot as parameter

partition(character array, integer start, integer end, character pivot)

{

       integer i = start;

loop from j = start to j < end

       {

check if array[j] < pivot

{

swap (array[i],array[j])

               increase i by 1;

           }

 else check if array[j] = pivot

{

               swap (array[end],array[j])

               decrease i by 1;

           }

       }

swap (array[i] , array[end])

       return partition index i;

}

7 0
3 years ago
Other questions:
  • How do you open Microsoft Excel 2013 with Windows 8?
    13·1 answer
  • What is the maximum number of hosts you can have on a network if the first decimal value of the ip address is between 192 and 22
    10·1 answer
  • What option is available on a Host A record to tell the system how long the record should remain in the database after it was cr
    15·1 answer
  • In 1988, Robert Morris, Jr. launched a program called the _________ that used weaknesses in e-mail programs and operating system
    5·1 answer
  • Write a Python program that reads the CSV file, compares the population estimates of every row for 2010 and 2017 and computes th
    10·1 answer
  • Which of the following statements is true regarding the e-mails that were collected from Marina and Rita's Cupcakes' key employe
    11·1 answer
  • How to learning algothrim bett
    5·1 answer
  • What icons in the toolbar change the look of the presentation text? It’s either Drawing, Formatting,Presentation, or Standard
    9·2 answers
  • What is sampling?
    6·1 answer
  • Write a program that gets three input characters which are user's initials and displays them in a welcoming message. Then gets i
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!