Create a C# project named Proj1, In Proj1 class create class named Rectangle. In the Rectangle class: 1) Declare two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. 2) Declare a string data field named color that specifies the color of a rectangle. Assume that all rectangles have the same color. The default color is white. 3) Define a no-argument constructor that creates a default rectangle. 4) Define a two-arguments constructor that creates a rectangle with the specified width and height. 5) Define properties for all the width and height data fields. For the width and height setters, check that the new values are non-negative. 6) Define a method named getArea() that calculates returns the rectangle area (Hint: area=width*height). 7) Define a method named getPerimeter() that calculates and returns the rectangle perimeter. (Hint: perimeter=2*width+2*height) 8) In the main method in the same class do the following: a) Create a default rectangle named r1, then print its width, height, and color. b) Change the width of the rectangle r1 to 10, then print the new value. c) Create a Rectangle object r2 with width=4, and height=40, then print its width, height, and color. d) Assign the color "red" to all Rectangle objects. e) Print the color of the rectangle r2. f) Create a Rectangle object r3 with width=6, and height=50, then print its width, height, and color. g) Print the areas of the three rectangles r1, r2, and r3. h) Print the perimeters of the three rectangles r1, r2, and r3.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Project#1 (Rectangle)
Create a C# project named Proj1, In Proj1 class create class named Rectangle. In
the Rectangle class:
1) Declare two double data fields named width and height that specify the width and
height of the rectangle. The default values are 1 for both width and height.
2) Declare a string data field named color that specifies the color of a rectangle.
Assume that all rectangles have the same color. The default color is
white.
3) Define a no-argument constructor that creates a default rectangle.
4) Define a two-arguments constructor that creates a rectangle with the specified
width and height.
5) Define properties for all the width and height data fields. For the
width and height setters, check that the new values are non-negative.
6) Define a method named getArea() that calculates returns the rectangle area
(Hint: area=width*height).
7) Define a method named getPerimeter() that calculates and returns the rectangle
perimeter. (Hint: perimeter=2*width+2*height)
8) In the main method in the same class do the following:
a) Create a default rectangle named r1, then print its width, height, and color.
b) Change the width of the rectangle r1 to 10, then print the new value.
c) Create a Rectangle object r2 with width=4, and height=40, then print its
width, height, and color.
d) Assign the color "red" to all Rectangle objects.
e) Print the color of the rectangle r2.
f) Create a Rectangle object r3 with width=6, and height=50, then print its
width, height, and color.
g) Print the areas of the three rectangles r1, r2, and r3.
h) Print the perimeters of the three rectangles r1, r2, and r3.
Transcribed Image Text:Project#1 (Rectangle) Create a C# project named Proj1, In Proj1 class create class named Rectangle. In the Rectangle class: 1) Declare two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. 2) Declare a string data field named color that specifies the color of a rectangle. Assume that all rectangles have the same color. The default color is white. 3) Define a no-argument constructor that creates a default rectangle. 4) Define a two-arguments constructor that creates a rectangle with the specified width and height. 5) Define properties for all the width and height data fields. For the width and height setters, check that the new values are non-negative. 6) Define a method named getArea() that calculates returns the rectangle area (Hint: area=width*height). 7) Define a method named getPerimeter() that calculates and returns the rectangle perimeter. (Hint: perimeter=2*width+2*height) 8) In the main method in the same class do the following: a) Create a default rectangle named r1, then print its width, height, and color. b) Change the width of the rectangle r1 to 10, then print the new value. c) Create a Rectangle object r2 with width=4, and height=40, then print its width, height, and color. d) Assign the color "red" to all Rectangle objects. e) Print the color of the rectangle r2. f) Create a Rectangle object r3 with width=6, and height=50, then print its width, height, and color. g) Print the areas of the three rectangles r1, r2, and r3. h) Print the perimeters of the three rectangles r1, r2, and r3.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY