Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Tasks Develop a Java application that can be used to obtain and calculate important geometric properties such as area and perimeter of a rectangle

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Lab Tasks Develop a Java application that can be used to obtain and calculate important geometric properties such as area and perimeter of a rectangle The following sections explain the problem solving steps for this problem. Part 1: Practicing Problem Analysis and Design Step 1. Problem Statement Design and implement a class Rectangle in Rectangle.java to calculate the geometric properties (area and perimeter) for a Rectangle object. This class should have two input variables: length and width. Also, this class should have three public methods: readlnput(): Read the user input of length and width from console to create the Rectangle object getAreal): Calculate and print the area property of the rectange Area of rectangle = length x width getPerimeter(): Calculate and print the perimeter property of the rectange Perimeter of rectangle = 2 * (length + width) . Test your class definition by implementing a main() method that creates Rectangle instances from user input and displays their geometric properties. Your program should produce something like the following output in the Java console: Enter the length of the rectangle 1: 10 Enter the width of the rectangle 1: 4 Class name Author name and creation date . Problem Description: that defines your application - include name of the project and reason for the development work. Elaborate as you see fit - keeping the scope manageable (2 3 sentences) Enumerate (list) and write the goals of your application. State in a way so the end user knows what your software can do (can be used as). Enumerate all the inputs and outputs for your application (provide examples) List all the java packages that need to be imported - tools that will be needed for solving/coding the problem. Develop a Test-suite (known input values with corresponding expected outputs values) this should be used during testing. Any illegal inputs? Write a pseudo-code for the steps your application will execute to achieve its goal - outline of the steps that includes the process of receiving and handling input, processing of data, and the means of displaying output. A template for the above specification in a comment block is shown as follows. Please fill in right after the colon. * Class name: * Author: * Date: * Problem: * Goals: Date: Problem: * Goals: Inputs: * Outputs: * Required packages : * Test cases: * Pseudo code: Step 1: ... Step 2: ... * Step 3: ... */ Part 2: Practicing Implementation with Good Coding Styles and Testing of Part 1 Program Step 4: Problem Implementation (continue from Part 1) In this part we will practice implementing the program that we have designed in Part 1. These steps Part 2: Practicing Implementation with Good Coding Styles and Testing of Part 1 Program Step 4: Problem Implementation (continue from Part 1) In this part, we will practice implementing the program that we have designed in Part 1. These steps are conducted after a thorough review of the above steps. This way - we understand what needs to be done clearly, and unambiguously, before programming. Develop your application that conforms to the description you have developed. Do not add any new feature to your code other than prescribed in the above descriptions in part 1! We will use the stepwise refinement approach that we practiced last time to code and test the Rectangle class. Here's a sequence of appropriate steps, after each of which you should compile and run your program. 1. Code the initial comment block (purpose of your program, your name, lab section, etc) and the basic class definition. - 4.1a. Create a Eclipse project named Lab3 and saving the project on your workspace. Then, create the Rectangle class. If you can't remember how to do this, read Lab1 again. . 4.1b. Type the specification you developed in 3b into a Java comment block and save it in a file named Rectangle.java. This file will be the file you use for defining the Rectangle class. The comment will serve as documentation for the program. A comment block in Java begins with either "/*" or "/**" and ends with "*/". It can extend over multiple lines. As explained in Appendix A, comments that begin with "/**" are documentation comments, which can be automatically turned into documentation for the class by using software that comes with the Java Development Kit (JDK). Code the declarations for the classic instance variables as well as the constructor comes with the Java Development Kit (JDK). 2. Code the declarations for the class's instance variables as well as the constructor method. 3. Code the definition for each method, one at a time. 4. Declare the main() method. 5. Add code to the main method to create and use one Rectangle object. Write one access method at a time, as well as a method call in main() that tests the method. Here is the sample steps to read inputs and print the geometric properties: Rectangle rect1 = new Rectangle(); rect1.readInput(); rect1.getArea(); rect1.getPerimeter(); 6. Similarly, add code to the main method to create and use a second Rectangle object. 7. Complete the documentation for your program. Add useful comments to your code that will make your program more readable. A good rule might be that you should be able to read your program two years from now and still understand what it does. For example, add a one line comment after the declared variable to explain what is the variable used for, and add a comment block before the method definition such as method descriptions, inputs/outputs of methods, pseudocode if any. Also, try to add comment inside the method body. Example comments for variables and methods in a class are shown as follows (Note: only refer to green comments part. This is just an example for Square class. For Rectangle class in this lab, you need to write appropriate comments for the variables and methods in the Rectangle class). comment inside the method body. Example comments for variables and methods in a class are shown as follows (Note: only refer to green comments part. This is just an example for Square class. For Rectangle class in this lab, you need to write appropriate comments for the variables and methods in the Rectangle class). public class Square { private int eLen; // the edge length of a square * This method calculate the area of a square * Inputs: None * Outputs: the area of a square * Pseudocode: - Calculate the area of a square using the equation: area = edge length * edge length * - Return the value of area public int area() { return elen * elen; } } Step 5: Testing a. In this part, we will practice testing our developed program in the previous steps. You are required to run the compiled of your program with different set of inputs (length and width of rectangle) and capture the screenshots of the outputs of your program. b. Have you notice the problem if you input illegal values of length or width of the rectangle such as

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 Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions