$25
The point of this assignment is to cover a few of the basic principles of encapsulation.
Using the IDE
Initial Code & Output
Load the following code into the online 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\n");
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("\nBye");
}
}
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.
1) Include an output statement at the beginning of the program with the assignment number and your name:
A09 – Written by Matt Weisfeld
2) Create a single Rectangle object called rect.
3) Implement a while() loop to accept User input for multiple area calculations (reset rect).
4) Implement a break statement to terminate the loop.
5) Each time through the loop, accept user input for 2 integer variables, length (first) and width.
6) Terminate the loop when the user enters ‘x’ for the length (no need to enter width).
7) Calculate the area of the current rect.
8) Print the area to the console (using rects’s getArea() method).
9) 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