Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface BiggerFinder {
- void fazerTeste();
- }
- --------------------------------
- import java.util.Scanner;
- public class BiggerFinderTest1 implements BiggerFinder {
- int valorAtual;
- int valorMaior;
- int qtd = 1;
- Scanner scanner = new Scanner(System.in);
- public void fazerTeste() {
- System.out.println("Digite quantos valores serão comparados:");
- int[] v = new int[scanner.nextInt()];
- for (int i = 0; i < v.length; i++) {
- System.out.println("Digite o "+qtd+"° valor a ser comparado:");
- valorAtual = scanner.nextInt();
- if(valorAtual>valorMaior){
- valorMaior = valorAtual;
- }
- qtd++;
- }
- System.out.println("O maior valor é: "+valorMaior);
- }
- }
- --------------------------------
- import java.util.Scanner;
- public class BiggerFinderTest2 implements BiggerFinder {
- int x, y, z, valorMaior;
- Scanner scanner = new Scanner(System.in);
- public void fazerTeste(){
- System.out.println("Digite o valo de x:");
- x = scanner.nextInt();
- System.out.println("Digite o valo de y:");
- y = scanner.nextInt();
- System.out.println("Digite o valo de z:");
- z = scanner.nextInt();
- System.out.println("O maior dentre eles é:");
- if(x>y&&x>z){
- valorMaior = x;
- System.out.println("Valor maior: "+valorMaior);
- } else if(y>x&&y>z) {
- valorMaior = y;
- System.out.println("Valor maior: "+valorMaior);
- } else {
- valorMaior = z;
- System.out.println("valor maior: "+valorMaior);
- }
- System.out.println("Fim Teste");
- }
- }
- --------------------------------
- import java.util.Scanner;
- public class BiggerFinderTest3 implements BiggerFinder {
- public void fazerTeste() {
- int posicao;
- int x = 10;
- int[] v = new int[9];
- Scanner scanner = new Scanner(System.in);
- System.out.println("Digite uma posição de 0 a 8 para descobrir o valor no vetor:");
- posicao = scanner.nextInt();
- for(int i = 0; i < v.length; i++ ){
- v[i] = x;
- x--;
- }
- System.out.println("O valor da posição "+posicao+" é: "+v[posicao]);
- }
- }
- --------------------------------
- public class FactoryTeste {
- public BiggerFinder createTest(String name){
- if(name=="teste1"){
- return new BiggerFinderTest1();
- } else if(name=="teste2") {
- return new BiggerFinderTest2();
- } else if(name=="teste3") {
- return new BiggerFinderTest3();
- } else{
- return null;
- }
- }
- }
- --------------------------------
- public class Main {
- public static void main(String[] args) {
- FactoryTeste factory = new FactoryTeste();
- BiggerFinder teste = factory.createTest("teste3");
- teste.fazerTeste();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement