Write code for a Java class Rectangle with the following fields and methods: Rectangle - width : double - height : double - area : double + perimeter : double + diagonal : double + Rectangle () : void + setRectangle (double w, double h) : void + printRectangle () : void + changeWidth (double w) : void + changeHeight (double h) : void - static computeDiagonal (double w, double h) : double Fields Methods Methods: Rectangle: Constructor, creates a rectangle with width and height equal to zero. setRectangle: Sets the width and height equal to the two parameters. Computes and stores the rectangle area, perimeter and diagonal. printRectangle: Prints the width, height, area, perimeter and diagonal of the rectangle with labels. All values are printed with a maximum of 2 digits after the decimal. Extra Credit (+5): Include a visual representation of the rectangle: ##### #3 ##### Extra Credit (+2): Visual representation works with length of 1 for height and/or width. changeWidth: Changes the width of the rectangle by the given parameter. changeHeight: Changes the height of the rectangle by the given parameter. computeDiagonal: Static function that computes the length of the diagonal of a triangle with height and width as given by its parameters. Main Program: Program first creates a Rectangle object and sets width and height as entered by the user. The program then repeatedly reads commands of print, height, width or quit until the user enters quit. When the user enters print, the program prints the rectangle private data. When the user enters height, the height is changed by a user entered value. When the user enters width, the width is changed by a user entered value. An error message should be printed if none of the legal inputs is entered. There is a sample run on the next page. Your output should follow the given text and spacing. Include a header comment describing the program and comment all variables, control structures and methods in the program. When your program is running correctly, submit your main program class and Rectangle class source files, .java extensions, in the Homework 2 area on Blackboard. Sample run (input in bold): Input Rectangle: Width: 4 Height: 3 Enter quit, print, width, or height: print Rectangle: #### # # #### Width = 4 Height = 3 Area = 12 Perimeter = 14 Diagonal = 5 Enter quit, print, width, or height: height Enter change in height: 2 Enter quit, print, width, or height: width Enter change in width: 1 Enter quit, print, width, or height: print Rectangle: ##### # # # #### Width = 5 Height = 5 Area = 25 Perimeter = 20 Diagonal = 7.07 Enter quit, print, width, or height: quit
Write code for a Java class Rectangle with the following fields and methods: Rectangle - width : double - height : double - area : double + perimeter : double + diagonal : double + Rectangle () : void + setRectangle (double w, double h) : void + printRectangle () : void + changeWidth (double w) : void + changeHeight (double h) : void - static computeDiagonal (double w, double h) : double Fields Methods Methods: Rectangle: Constructor, creates a rectangle with width and height equal to zero. setRectangle: Sets the width and height equal to the two parameters. Computes and stores the rectangle area, perimeter and diagonal. printRectangle: Prints the width, height, area, perimeter and diagonal of the rectangle with labels. All values are printed with a maximum of 2 digits after the decimal. Extra Credit (+5): Include a visual representation of the rectangle: ##### #3 ##### Extra Credit (+2): Visual representation works with length of 1 for height and/or width. changeWidth: Changes the width of the rectangle by the given parameter. changeHeight: Changes the height of the rectangle by the given parameter. computeDiagonal: Static function that computes the length of the diagonal of a triangle with height and width as given by its parameters. Main Program: Program first creates a Rectangle object and sets width and height as entered by the user. The program then repeatedly reads commands of print, height, width or quit until the user enters quit. When the user enters print, the program prints the rectangle private data. When the user enters height, the height is changed by a user entered value. When the user enters width, the width is changed by a user entered value. An error message should be printed if none of the legal inputs is entered. There is a sample run on the next page. Your output should follow the given text and spacing. Include a header comment describing the program and comment all variables, control structures and methods in the program. When your program is running correctly, submit your main program class and Rectangle class source files, .java extensions, in the Homework 2 area on Blackboard. Sample run (input in bold): Input Rectangle: Width: 4 Height: 3 Enter quit, print, width, or height: print Rectangle: #### # # #### Width = 4 Height = 3 Area = 12 Perimeter = 14 Diagonal = 5 Enter quit, print, width, or height: height Enter change in height: 2 Enter quit, print, width, or height: width Enter change in width: 1 Enter quit, print, width, or height: print Rectangle: ##### # # # #### Width = 5 Height = 5 Area = 25 Perimeter = 20 Diagonal = 7.07 Enter quit, print, width, or height: quit
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education