You are on page 1of 10

Name: Clemente, Danielle Rose Date: May 13, 2021

CITE 003 / CS12S1 / M W F / 8:30am - 10:30am Professor: Mr. Alfio Regla

Laboratory Activity #3
1. Write a program that will declare as literals your age, first name, last name, 1st messages

(Score in Exercise 1 is ), (Score in Exercise 2 is ), (Score in Exercise 3 is ), (The average for


3 Exercises is = ) . These literals will be organized in details as an output. Note: you must
declare separate variables for storing scores in 3 Exercises as well as the average. The
output should looks like this:

Code (Screenshot):

Text-based Code:

package prelimactivities;

import java.util.Scanner;

public class LiteralsExercise {

public static void main(String[] args) {


//scanner object
Scanner input = new Scanner(System.in);

System.out.println("\t _______________________________________________________");
System.out.println("\t|-----------------STUDENT AVERAGE SCORE-----------------|");
System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");

//prompt the user to enter their age


System.out.printf("\t Age: ");
int age = Integer.parseInt(input.nextLine());

//prompt the user to enter their first name


System.out.printf("\t First Name: ");
String firstName = input.nextLine();

//prompt the user to enter their last name


System.out.printf("\t Last Name: ");
String lastName = input.nextLine();

System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");
System.out.println("\t MARKS: ");

//prompt the user to enter score in exercise 1


System.out.printf("\t\tScore in Exercise 1: ");
double scoreInExercise1 = input.nextDouble();

//prompt the user to enter score in exercise 2


System.out.printf("\t\tScore in Exercise 2: ");
double scoreInExercise2 = input.nextDouble();

//prompt the user to enter score in exercise 3


System.out.printf("\t\tScore in Exercise 3: ");
double scoreInExercise3 = input.nextDouble();

System.out.println("\t|_______________________________________________________|");
System.out.println("\t| |");

//Computation of the average of scores


double averageScore = (scoreInExercise1 + scoreInExercise2 + scoreInExercise3) / 3;
System.out.printf("\t Average Score is %.2f \n", averageScore);
System.out.println("\t|_______________________________________________________|");

//To terminate the scanner object


input.close();
}

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

Area = radius * 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;

public class AreaAndPerimeterOfACircle {


public static void main(String[] args) {

//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: ");

//User input for radius


double radius = input.nextDouble();

//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);

//For the verbal final answer


System.out.printf("\n\t FINAL ANSWER: For a circle with the radius of " + radius);
System.out.printf(",\n\t the area is %.2f and the perimeter is %.2f", area, perimeter);
System.out.printf(".\n");
System.out.println("\t|_______________________________________________________|");

//To terminate the scanner object


input.close();

}
}










































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;

public class AreaAndPerimeterOfARectangle {


public static void main(String[] args) {
//scanner object
Scanner input = new Scanner(System.in);

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.printf("\n\t RECTANGLE ");


System.out.printf("\n\n\t\tEnter Width: ");

//For width user input


double width = input.nextDouble();

//For height user input


System.out.printf("\t\tEnter Height: ");
double height = input.nextDouble();

//For computation of area


double area = width * height;

//For computation of perimeter


double perimeter = 2 * width + 2 * height;

System.out.println("\t|
_________________________________________________________________________|");
System.out.println("\t|
|");

//For displaying Area


System.out.printf("\t Area = %.2f \n", area);

//For displaying of Perimeter


System.out.printf("\t Perimeter = %.2f \n", perimeter);

//For the verbal final answer


System.out.printf("\n\t FINAL ANSWER: For a rectangle with the width of " + width + " and
height of " + height);
System.out.printf(",\n\t the area is %.2f and the perimeter is %.2f", area, perimeter);
System.out.printf(".\n");
System.out.println("\t|
_________________________________________________________________________|");

//To terminate the scanner object


input.close();

}
}















































Sample Output:

" I affirm that I have not given or received any unauthorized help in this assignment, and that
this work is my own “

You might also like