Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create and use an object 2. 3. Create a class named Rectangle and store it in the murach.rectangle package. In the Rectangle class, add instance

image text in transcribedimage text in transcribed

Create and use an object 2. 3. Create a class named Rectangle and store it in the murach.rectangle package. In the Rectangle class, add instance variables for length and width. Then, code the get and set methods for these instance variables. If possible, use your IDE to generate the get and set methods. With Eclipse, you can get started by selecting the Source Generate Getters and Setters command. Add a zero-argument constructor that initializes the length and width to 0 Add a get method that calculates the area of the rectangle and returns a double value for the result. If you want, you can copy the code that performs this calculation from the Main class. 4. 5. 6. Add a get method that returns the area as a String object with standard numeric formatting and a minimum of three decimal places. To make it easy to refer to the NumberFormat class, you should add an import statement for it. Repeat the previous two steps for the perimeter 7. 8. Open the Main class. Then, add code that creates a Rectangle object and sets 9. Modify the code that displays the calculations so it uses the methods of the 10. Remove any leftover code from the Main class that's unnecessary including 1. Run the application and test it with valid data. It should calculate the area and its length and width. Rectangle object to get the area and perimeter of the rectangle. any unnecessary import statements. perimeter for a rectangle. Overload the constructor 12. Open the Rectangle class. Then, overload the constructor by supplying a second constructor that accepts two arguments: length and width. This constructor should set the length and width of the rectangle to the values supplied by these arguments. 13. Open the Main class. Then, modify its code so it uses this constructor instead of the zero-argument constructor package che3_ex2 rineter import java,text NumberFormat; import java,util.Scanner public class Main t public static void main(String args) [ //displays welcone message Task #2) Systen.out.printIn("Welcome to the Area and Perimeter Calculator"; Systen.out.println); Scanner sc new Scanner(System.in); string choice-"y". // (Task #5) //Prompts the user for the length and width (Task #3) Systen.out.print("Enter Length: "); double length Double.parseDouble(sc.nextLine )) Systen.out.print("Enter width: "); double widthDouble.parseDouble(sc.nextLine()); //calculate and displays the area and perimeter (Task #4) double area -width * length; double perimeter-2 width 2 *length; NumberFormat number NumberFormat.getNumberInstance); number.setMininumFractionDigits(3) String areaFormatted number. format(area); String perimeterFormatted number.format(perimeter) Systen.out.println("Area: Systen.out.println("Perimeter:"+perineterFornatted); " areaFormatted) while (choice.equalsIgnoreCase("y")) Systen.out.print"Enter length: "; double length Double.parseDouble(sc.nextline)) System.out.print("Enter width: double width-Double.parseDoublelsc.nextLine)

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

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago