Advertisement
luanhenriquer8

Untitled

Apr 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. public interface BiggerFinder {
  2.  
  3. void fazerTeste();
  4. }
  5. --------------------------------
  6. import java.util.Scanner;
  7.  
  8. public class BiggerFinderTest1 implements BiggerFinder {
  9.  
  10. int valorAtual;
  11. int valorMaior;
  12. int qtd = 1;
  13. Scanner scanner = new Scanner(System.in);
  14.  
  15. public void fazerTeste() {
  16.  
  17. System.out.println("Digite quantos valores serão comparados:");
  18.  
  19. int[] v = new int[scanner.nextInt()];
  20.  
  21. for (int i = 0; i < v.length; i++) {
  22.  
  23. System.out.println("Digite o "+qtd+"° valor a ser comparado:");
  24. valorAtual = scanner.nextInt();
  25. if(valorAtual>valorMaior){
  26. valorMaior = valorAtual;
  27. }
  28. qtd++;
  29. }
  30. System.out.println("O maior valor é: "+valorMaior);
  31. }
  32. }
  33. --------------------------------
  34. import java.util.Scanner;
  35.  
  36. public class BiggerFinderTest2 implements BiggerFinder {
  37.  
  38. int x, y, z, valorMaior;
  39. Scanner scanner = new Scanner(System.in);
  40.  
  41. public void fazerTeste(){
  42. System.out.println("Digite o valo de x:");
  43. x = scanner.nextInt();
  44. System.out.println("Digite o valo de y:");
  45. y = scanner.nextInt();
  46. System.out.println("Digite o valo de z:");
  47. z = scanner.nextInt();
  48. System.out.println("O maior dentre eles é:");
  49.  
  50. if(x>y&&x>z){
  51. valorMaior = x;
  52. System.out.println("Valor maior: "+valorMaior);
  53. } else if(y>x&&y>z) {
  54. valorMaior = y;
  55. System.out.println("Valor maior: "+valorMaior);
  56. } else {
  57. valorMaior = z;
  58. System.out.println("valor maior: "+valorMaior);
  59. }
  60. System.out.println("Fim Teste");
  61. }
  62. }
  63. --------------------------------
  64.  
  65. import java.util.Scanner;
  66.  
  67. public class BiggerFinderTest3 implements BiggerFinder {
  68.  
  69. public void fazerTeste() {
  70.  
  71. int posicao;
  72. int x = 10;
  73. int[] v = new int[9];
  74. Scanner scanner = new Scanner(System.in);
  75.  
  76. System.out.println("Digite uma posição de 0 a 8 para descobrir o valor no vetor:");
  77. posicao = scanner.nextInt();
  78.  
  79. for(int i = 0; i < v.length; i++ ){
  80. v[i] = x;
  81. x--;
  82. }
  83. System.out.println("O valor da posição "+posicao+" é: "+v[posicao]);
  84. }
  85. }
  86. --------------------------------
  87. public class FactoryTeste {
  88.  
  89. public BiggerFinder createTest(String name){
  90. if(name=="teste1"){
  91. return new BiggerFinderTest1();
  92. } else if(name=="teste2") {
  93. return new BiggerFinderTest2();
  94. } else if(name=="teste3") {
  95. return new BiggerFinderTest3();
  96. } else{
  97. return null;
  98. }
  99. }
  100. }
  101. --------------------------------
  102. public class Main {
  103.  
  104. public static void main(String[] args) {
  105.  
  106. FactoryTeste factory = new FactoryTeste();
  107.  
  108. BiggerFinder teste = factory.createTest("teste3");
  109. teste.fazerTeste();
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement