Professional Documents
Culture Documents
Laboratory Activity #3
1. Write a program that will declare as literals your age, first name, last name, 1st messages
Code (Screenshot):
Text-based Code:
package prelimactivities;
import java.util.Scanner;
System.out.println("\t _______________________________________________________");
System.out.println("\t|-----------------STUDENT AVERAGE SCORE-----------------|");
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
System.out.println("\t MARKS: ");
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
Sample Output:
2. (Area and perimeter of a circle) write a program in Java that displays the area and
perimeter of circle that has a radius of 7 using the following formula:
Perimeter = 2 * radius * pi
Note: use concatenation to clearly define the given radius and the perimeter and area
results.
Code (Screenshot):
Text-based Code:
package prelimactivities;
import java.util.Scanner;
//scanner object
Scanner input = new Scanner(System.in);
System.out.println("\t _______________________________________________________");
System.out.println("\t|-------AREA AND PERIMETER OF A CIRCLE CALCULATOR-------|");
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
System.out.printf("\n\t CIRCLE ");
System.out.printf("\n\n\t\tEnter Radius: ");
//Computation of area
double area = radius * radius * 3.14159;
//Computation of perimeter
double perimeter = 2 * radius * 3.14159;
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
//Display Area
System.out.printf("\t Area = %.2f \n", area);
//Display perimeter
System.out.printf("\t Perimeter = %.2f \n", perimeter);
}
}
Sample Output:
3. (Area and perimeter of a rectangle) write a program that displays the area and perimeter
of a rectangle with the width of 4.5 and height of 7.9 using the following formula:
Area = width * height
Perimeter =?
Note: use concatenation to clearly define the given radius and the perimeter and area
results.
Code (Screenshot):
Text-based Code:
package prelimactivities;
import java.util.Scanner;
System.out.println("\t
_________________________________________________________________________");
System.out.println("\t|--------------AREA AND PERIMETER OF A RECTANGLE -
CALCULATOR-------------|");
System.out.println("\t|
_________________________________________________________________________|");
System.out.println("\t|
|");
System.out.println("\t|
_________________________________________________________________________|");
System.out.println("\t|
|");
}
}
Sample Output:
" I affirm that I have not given or received any unauthorized help in this assignment, and that
this work is my own “