Activity1 PATIÑO M M
Activity1 PATIÑO M M
1. Create a java program to compute the area and perimeter of a rectangle given the
length and width (in centimeters). Output the area in sq. cm.; sq. m.; sq. in.; and sq. ft.
For perimeter in cm.; m.; in.; and ft.
2. Use:
a. BufferedReader to get input from the user and System.out to output the result.
b. JOptionPane to get input from the user and to output the result in message box.
c. Scanner Scan to get input from the user and System.out to output the result.
3. Use different inputs on each item on the above methods of getting input from the user.
4. Screenshot/Print Screen the outputs of your programs in #2a, #2b, and #3.
5. Submit the source code (Java Program codes) and 3 sample outputs in PDF format.
Screen Layout:
Enter Length of Rectangle : __________ cm.
Enter Width of Rectangle : __________ cm.
Activity1_Marcos_B_B.pdf)
A. BufferedReader to get input from the user and System.out to output the result.
Code:
import java.io.*;
public class
A_Activity1_Orge_A_A
{ public static void main(String[] args) throws
Exception
{
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader number = new BufferedReader(input);
Output:
B. JOpitonPane to get input from the user and to output the result in message box.
Code:
import javax.swing.JOptionPane;
public class
B_Activity1_Orge_A_A
{ public static void main(String[]
args)
{
String l_rectangle = JOptionPane.showInputDialog("Enter Length of Rectangle:
");
float length = Float.parseFloat(l_rectangle);
String w_rectangle = JOptionPane.showInputDialog("Enter Width of Rectangle:
"); float width =
Float.parseFloat(w_rectangle);
double area = length * width;
double a_meter = area / 1000;
double a_inches = area / 6.452;
double a_feet = area / 929;
Output:
C. Scanner Scan to get input from the user and System.out to output the result.
Code:
import java.util.Scanner;
public class
C_Activity1_Orge_A_A
{ public static void main(String[]
args)
{
Scanner size = new Scanner(System.in);
System.out.print("Enter Length of Rectangle: ");
Float length = size.nextFloat();
Output: