You are on page 1of 2

De La Salle University - Dasmariñas 1

CEAT – Engineering Department

Name: Carampot, Jhune Jarlo S.


Course/Year/Sec: ECE51
Date: November 18, 2020 Rating:

ACTIVITY 6: OOP Design using Methods


Objective: Apply OOP principles of Methods using UML and Java program.
Instructions: Satisfy the conditions using a Java Program. Compile your code using any Java IDE,
with your instructor for checking. Write the JAVA code in the yellow pad. Attach your answer sheet
with the activity sheet.

1. Create a program that will input three numbers and display the largest and smallest number.
Use the UML diagram below as a guide. The following methods are as follows.

Input First Number: The Largest Number is:


Input Second Number: The Smallest Number is:
Input Third Number:

import java.util.Scanner;
public class Main{

public static void main (String args []){

Scanner scanner = new Scanner (System.in);


System.out.println("Welcome in Java program to find largest and
smallest of three numbers");
System.out.println("Please enter first number :");
int first = scanner.nextInt();
System.out.println("Please enter second number :");
int second = scanner.nextInt();
System.out.println("Please enter third number :");
int third = scanner.nextInt();

int largest = largest(first, second, third); int smallest =


smallest(first, second, third);

CPET415L
Object Oriented Programming
De La Salle University - Dasmariñas 2
CEAT – Engineering Department

System.out.printf("largest of three numbers %d, %d, and %d is :


%d %n", first, second, third, largest);
System.out.printf("smallest of three numbers %d, %d, and %d is :
%d %n", first, second, third, smallest);
scanner.close();
}

public static int largest(int first, int second, int third) {

int max = first;

if (second > max) { max = second; }


if (third > max) { max = third; }

return max;
}

public static int smallest(int first, int second, int third) {

int min = first;


if (second < min) {
min = second; }
if (third < min)

{ min = third;
}

return min;

}
}

CPET415L
Object Oriented Programming

You might also like