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
Yuliya22 [10]
3 years ago
5

Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 3

5.7. Display the width, height, area, and perimeter of each rectangle in this order.
Computers and Technology
1 answer:
BARSIC [14]3 years ago
5 0

Answer:

public class Rectangle {

   private double width;

   private double heigth;

   public Rectangle(double width, double heigth) {

       this.width = width;

       this.heigth = heigth;

   }

   public double getWidth() {

       return width;

   }

   public void setWidth(double width) {

       this.width = width;

   }

   public double getHeigth() {

       return heigth;

   }

   public void setHeigth(double heigth) {

       this.heigth = heigth;

   }

   public double perimeter(double width, double heigth){

       double peri = 2*(width+heigth);

       return peri;

   }

   public double area(double width, double heigth){

       double area = width*heigth;

       return  area;

   }

}

class RectangleTest{

   public static void main(String[] args) {

       //Creating two Rectangle objects

       Rectangle rectangle1 = new Rectangle(4,40);

       Rectangle rectangle2 = new Rectangle(3.5, 35.7);

       //Calling methods on the first Rectangel objects

       System.out.println("The Height of Rectangle 1 is: "+rectangle1.getHeigth());

       System.out.println("The Width of Rectangle 1 is: "+rectangle1.getWidth());

       System.out.println("The Perimeter of Rectangle 1 is: "+rectangle1.perimeter(4,40));

       System.out.println("The Area of Rectangle 1 is: "+rectangle1.area(4,40));

       // Second Rectangle object

       System.out.println("The Height of Rectangle 2 is: "+rectangle2.getHeigth());

       System.out.println("The Width of Rectangle 2 is: "+rectangle2.getWidth());

       System.out.println("The Perimeter of Rectangle 2 is: "+rectangle2.perimeter(4,40));

       System.out.println("The Area of Rectangle 2 is: "+rectangle2.area(4,40));

   }

}

Explanation:

  • Firstly A Rectangle class is created with two fields for width and heigth, a constructor and getters and setters the class also has methods for finding area and perimeters
  • Then a RectangleTest class containing a main method is created and two Rectangle objects are created (Follow teh comments in the code)
  • Methods to get height, width, area and perimeter are called on each rectangle object to print the appropriate value
You might be interested in
Data frames can be subset by a chosen value using ==.
balandron [24]

Using python knowledge and writing code importing pandas, it is possible to create a function that corresponds to what you want.

<h3>Writting in python:</h3>

<em>import pandas as pd</em>

<em>if __name__ == "__main__":</em>

<em>    df=pd.read_csv('mtcars.csv')</em>

<em>    cylinders=int(input())</em>

<em>    print(df[df.cyl==cylinders].shape)</em>

See more about python at brainly.com/question/18502436

#SPJ1

5 0
2 years ago
The computer mouse is used to
Alexandra [31]
Is there options to this question?
7 0
3 years ago
Write a Python program string_functions.py that defines several functions. Each function re-implements Python's built-in string
grigory [225]

Answer:

def my_compare(str1, str2):

   mylist = sorted([str1, str2])

   if str1 == str2:

       return 0

   elif str1 == mylist[0]:

       return -1

   elif str1 == mylist[1]:

       return 1

def is_char_in(string, char):

   if char in string:

       return True

   return False

def is_char_not_in(string, char):

   if char not in string:

       return True

   return False

def my_count(string, char):

   return string.count(char)

def my_endswith(string, char):

   return string.endswith(char)

def my_find(string, char):

   if char in string:

       return string.index(char)

   else:

       return -1

def my_replace(string, char1, char2):

   lst = [i for i in string]

   print(lst)

   for i, v in enumerate(lst):

       if v==char1:

           lst[i] = char2

   return "".join(lst)

Explanation:

Above are defined functions similar to the string built-in functions in python. To use them, type in the function name and pass in the required arguments. Save the file name as "string_functions" with a ".py" file extension and use the functions in other files by importing all the function as "import string_functions" or import individual functions with "from string_function import 'function_name' ".

5 0
3 years ago
Cloud kicks recently completed the implementation of sales cloud. Cloud kicks has trained the users to use the mobile app to acc
aleksandrvk [35]

Answer:

see how long the people are on the app and see low long te time is constant where nobody is on at all

Explanation:

7 0
4 years ago
What is Malware? Discuss this topic and give 3 examples of Malware AS WELL AS a description of how they cause damage to computer
Papessa [141]

Answer:

Definition:

Malware refers to the malicious electronic instructions ( programmes ) which copy and store themselves on the memory of the computer which destroys and halts the working condition of the computer.

Examples:

<em>→</em><em> </em><em>Trojanic</em><em> </em><em>bomb</em><em>.</em>

<em>→</em><em> </em><em>Memory</em><em> </em><em>bomb</em><em>.</em>

<em>→</em><em> </em><em>Polymorphic</em><em> </em><em>bomb</em><em>.</em>

5 0
3 years ago
Other questions:
  • Another important mode, XTS-AES, has been standardized by the __________ Security in Storage Working Group. a. IEEE b. ITIL c. N
    9·2 answers
  • Hello... does anyone know why Brainly notifications aren’t working???
    11·2 answers
  • Monica is teaching herself to paint. What web resource would be the most helpful
    14·1 answer
  • WILL UPVOTE ALL plz
    13·1 answer
  • Adding all the three primary colors-red, green, and blue-at maximum intensity produces the color _____, while adding any two of
    9·1 answer
  • I want to know why almost every single "expert answer verified" thing I come across is wrong. If it's wrong, why the h is it exp
    8·2 answers
  • printArray is a method that accepts one argument, an arrayof int. The method prints the contents of the array; it does not retur
    5·1 answer
  • Many networks are set up using a hierarchical architecture to create a "backbone" network. In this system, several connected rou
    12·1 answer
  • Susan is a network administrator and is setting up her company's network. In the process to determine an open port on a firewall
    11·1 answer
  • Give examples of an outdated memory or storage device. what do you think is the main reason they are outdated?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!