Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

, height Write a class called Rectangle with the following attributes and methods. (All attributes should be declared as private.) x-> int width y->int width>

image text in transcribed

image text in transcribed

, height Write a class called Rectangle with the following attributes and methods. (All attributes should be declared as private.) x-> int width y->int width> int height -> int Methods get and set methods for all attributes. getPerimeter() method retums the perimeter of the rectangle. .getArea() method returns the area of the rectangle. You can use the following template for your Rectangle.java file: return x; public class Rectangle private double x; // write other attributes public Rectangle(double xe, double ye, double w, double h){ x = x; y = ye; width = w; height-h; } public double getX(){ ) public void setX(double x){ X = x; ) // write other get and set methods public double getPerimeter(){ // compute and return the perimeter } public double getArea(){ // compute and return the area ) ) Test your class by creating another file 01.java in addition to your Rectangle.java file. Then copy and complete the following code: import java.util.Scanner; public class 01{ public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter x y width height: "); // here, read 4 doubles from user and // create a rectangle object using these 4 doubles // then output as in the following examples below } You should get the following outputs with the following inputs when you run Q1.java: Input: Enter x y width height: 0.0 0.2 5. 8.0 Output: The perimeter is: 26.0 The area is: 40.0 Input: Enter x y width height: -1.0 6.0 3.0 5.0 Output The perimeter is: 16.0 The area is: 15.0 You should submit 2 files for this question: 21.java and Rectangle.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Define sampling error.

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago