The point of this assignment is to cover a few of the basic principles of encapsulation.
Using the IDE
Remember that all code must be submitted in text format.
Initial Code & Output
Load the following code into the online compiler:
https://www.jdoodle.com/online-java-compiler/
Please copy the following code into the IDE, compile and run it.
// calculate area of rectangle using class in java
import java.io.*;
import java.util.Scanner;
public class EncapsulationDemo
{
public static void main(String[] args)
{
// Create object of Rectangle class
System.out.println(A09 Written by Matt Weisfeld
);
Scanner console = new Scanner(System.in);
// Input Strings
String len=null, wid=null;
int l=0,w=0;
// Remove Comment to Create the Rectangle
// Rectangle rect = new Rectangle(0, 0);
// Begin while() loop here
System.out.println(
Bye);
}
}
This code covers a lot of programming concepts. Please take this opportunity to study the code and determine what is going on.
When you execute the code it will look something like this:
Problem
Note that this is simply a shell to get you started with a clean compile.
The task is to create a Rectangle class that follows the following UML specification.
Here are the constraints that you must include in your program.
- Include an output statement at the beginning of the program with the assignment number and your name:
- Create a single Rectangle object called rect.
- Implement a while() loop to accept User input for multiple area calculations (reset rect).
- Implement a break statement to terminate the loop.
- Each time through the loop, accept user input for 2 integer variables, length (first) and width.
- Terminate the loop when the user enters x for the length (no need to enter width).
- Calculate the area of the current rect.
- Print the area to the console (using rectss getArea() method).
- Print out an exit greeting (Bye) when exiting the application.
Final Output
Once completed, your output (in the following test case) should look like this:
Note the input box

![[Solved] IT2650 Assignment9-Encapsulation](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] IT2650 Assignment13](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.