Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help coding this Java program. This is what i have so far but i only get error outputs. Thank you. CENGAGE MINDTAP Q

i need help coding this Java program. This is what i have so far but i only get error outputs. Thank you.

image text in transcribedimage text in transcribedimage text in transcribed
CENGAGE MINDTAP Q Search Creating a Programmer-Defined Class in Java |Creating a MyRectangleClassPro... Rectangle.java + Programmer-Defined 1 / / This program uses the programmer-defined Rectangle class. N Class in Java 3 public class MyRectangleClassProgram 4 { 5 public static void main(String args) Summary 6 7 / / Create rectanglel and rectangle2 objects here. In this lab, you will create a 8 Rectangle rectanglel = new Rectangle( ); programmer-defined class and then 9 Rectangle rectangle2 = new Rectangle( ); 10 use it in a Java program. The / / Set the length of rectanglel to 10.0 here. 11 program should create two rectanglel . setLenght (10.0) ; 12 / / Set the width of rectanglel to 5.0 here. Rectangle objects and find their 13 rectanglel . setWidth(5.0) ; area and perimeter. 14 15 / / Print the area and perimeter of rectanglel here. 16 Instructions 17 / / Set the length of rectangle2 to 7.0 here. 18 rectangle2 . setLenght (7.0) ; 1. Make sure the class file named 19 / / Set the width of rectangle2 to 3.0 here. Rectangle.java is open. 20 rectangle2 . setWidth(3.0) ; 21 2. In the Rectangle class, create 22 / / Print the area and perimeter of rectangle2 here. two private attributes named 23 System. out . printIn( "Rectangle l's area is: " + rectanglel. calculateArea( ) ); length and width . BothCENGAGE MINDTAP Q Search this cours Creating a Programmer-Defined Class in Java m Creating a Programmer- MyRectangleClassPro... Rectangle.java + 7/ set the length of rectanglel to 10.0 nere. Defined Class in Java 11 rectanglel . setLenght (10.0) ; 12 3. Write public set methods to set the / / Set the width of rectanglel to 5.0 here. chl 13 rectanglel . setWidth(5.0) ; values for length and width . 14 15 / / Print the area and perimeter of rectanglel here. 4. Write public get methods to retrieve the 16 values for length and width . 17 // Set the length of rectangle2 to 7.0 here. 18 5. Write a public calculateArea( ) rectangle2 . setLenght (7.0) ; 19 / / Set the width of rectangle2 to 3.0 here. method and a public 20 rectangle2 . setWidth(3.0); calculatePerimeter ( ) method to 21 22 / / Print the area and perimeter of rectangle2 here. calculate and return the area of the 23 System . out . println( "Rectangle l's area is: " + rectanglel. calculateArea( ) ); rectangle and the perimeter of the 24 System . out . println("Rectangle l's perimeter:" + rectanglel . calculatePerime rectangle. 25 System . out . printIn("Rectangle 2's area is: " + rectangle2. calculateArea( ) ); 26 System . out . printIn( "Rectangle 2's perimeter is: " + rectangle2. calculatePer 6. Open the file named 27 MyRectangleClassProgram.java. 28 29 System . exit(0); 7. In the MyRectangleClassProgram 30 class, create two Rectangle objects 31 } (? 32 named rectanglel and rectangle2 . 8. Set the length of rectanglel to 10.0a Programmer-Defined Class in Java Creating a Programmer- MyRectangleClassPro... Rectangle.java + Defined Class in Java 1 class Rectangle 2 { MyRectangleClassProgram.java. 3 public class Rectangle { 4 7. In the MyRectangleClassProgram 5 private double lenght, width; class, create two Rectangle objects 6 7 named rectanglel and rectangle2. // Length of this rectangle. 8 public void setLength(double 8. Set the length of rectanglel to 10.0 9 this . lenght = lenght; 10 and the width to 5.0. Set the length of 11 / / Width of this rectangle. rectangle2 to 7.0 and the width to 12 public void setWidth(double 3.0. 13 this . width = width; 14 9. Print the value of rectanglel 's 15 public double getLength( ) { perimeter and area, and then print the 16 return length; 17 value of rectangle2's perimeter and 18 public double getwidth( ) { area. 19 return width; 20 O. Execute the program. 21 public double calculateArea( ) { 22 return lenght*width; Grading 23

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+c. Assuming velocity remains constant,

Answered: 1 week ago

Question

Goals of Education System?

Answered: 1 week ago

Question

What is privatization?

Answered: 1 week ago

Question

What is wastage?

Answered: 1 week ago

Question

Environmental education explain?

Answered: 1 week ago