Last active
November 29, 2019 16:15
-
-
Save williamlagos/a588bde9fada0e779dbc34771d8fa771 to your computer and use it in GitHub Desktop.
Exemplo de código em Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Classe abstrata Abstrata - escreva a descrição da classe aqui | |
* | |
* @author (seu nome aqui) | |
* @version (versão ou data) | |
*/ | |
public abstract class Abstrata | |
{ | |
// variáveis de instância - substitua o exemplo abaico pelo seu código | |
int x; | |
/** | |
* Um exemplo de método - substitua este exemplo pelo seu código | |
* | |
* @param y um exemplo de parâmetro de método | |
* @return a soma de x com y | |
*/ | |
public int sampleMethod(int y) | |
{ | |
// ponha seu código aqui | |
return x + y; | |
} | |
public abstract int novoMetodo(int param); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da classe AbstrataFilho aqui. | |
* | |
* @author (seu nome) | |
* @version (número de versão ou data) | |
*/ | |
public class AbstrataFilho extends Abstrata | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private int x; | |
/** | |
* COnstrutor para objetos da classe AbstrataFilho | |
*/ | |
public AbstrataFilho() | |
{ | |
// inicializa variáveis de instância | |
x = 0; | |
} | |
/** | |
* Exemplo de método - substitua este comentário pelo seu próprio | |
* | |
* @param y exemplo de um parâmetro de método | |
* @return a soma de x com y | |
*/ | |
public int sampleMethod(int y) | |
{ | |
// ponha seu código aqui | |
return x + y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
public class Buffer | |
{ | |
private int numero; | |
public Buffer(int num) { | |
this.numero = num; | |
} | |
public int calculaNumero() { | |
this.numero = this.numero + 1; | |
return this.numero; | |
} | |
public static void teste() { | |
System.out.println("Hello World!"); | |
} | |
public static void main(String[] argumentoLista) throws IOException | |
{ | |
for(String argumento: argumentoLista) { | |
if(argumento.equals("ajuda")) { | |
System.out.println("Manual de instruções"); | |
} else { | |
System.out.println(argumento); | |
} | |
} | |
int[] numeros = { 0, 10 }; | |
int[] novoArray = new int[10]; | |
int contador = 0; | |
while(contador < numeros.length) { | |
System.out.println(numeros[contador]); | |
novoArray[contador] = numeros[contador]; | |
contador = contador + 1; | |
} | |
novoArray[2] = 2000; | |
for(Integer num: numeros) { | |
System.out.println(num); | |
} | |
int count = 0; | |
do { | |
System.out.println(novoArray[count]); | |
count++; | |
} while(count < novoArray.length); | |
// Enter data using BufferReader | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
// Reading data using readLine | |
String number = reader.readLine(); | |
// Convertendo string para numero | |
int num = Integer.parseInt(number); | |
switch(num) { | |
case 1: | |
System.out.println("Igual a 1"); | |
break; | |
case 2: | |
System.out.println("Igual a 2"); | |
break; | |
case 3: | |
System.out.println("Igual a 3"); | |
break; | |
default: | |
System.out.println("Diferente de 1, 2 ou 3"); | |
break; | |
} | |
if (num == 1) { | |
System.out.println("Igual a 1"); | |
} else if (num == 2) { | |
System.out.println("Igual a 2"); | |
} else if (num == 3) { | |
System.out.println("Igual a 3"); | |
} else { | |
System.out.println("Diferente de 1, 2 ou 3"); | |
} | |
for(int c = 1; c <= 15; c++) { | |
System.out.println(c); | |
} | |
if (num > 15) { | |
System.out.println("Maior que 15"); | |
} else if (num > 10) { | |
System.out.println("Maior que 10"); | |
if (num == 13) { | |
System.out.println("Igual a 13"); | |
} else { | |
System.out.println("Diferente de 13"); | |
} | |
} else if (num >= 5) { | |
System.out.println("Maior que 5"); | |
} else { | |
System.out.println("Menor que 5"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da classe Classe1 aqui. | |
* | |
* @author (seu nome) | |
* @version (número de versão ou data) | |
*/ | |
public class Classe1 extends ClassePai | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private int x; | |
/** | |
* COnstrutor para objetos da classe Classe1 | |
*/ | |
public Classe1() | |
{ | |
// inicializa variáveis de instância | |
super(); | |
x = 0; | |
} | |
public void teste() { | |
System.out.println(this.sampleMethod(1)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da classe Classe2 aqui. | |
* | |
* @author (seu nome) | |
* @version (número de versão ou data) | |
*/ | |
public class Classe2 extends ClassePai | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private int x; | |
/** | |
* COnstrutor para objetos da classe Classe2 | |
*/ | |
public Classe2() | |
{ | |
// inicializa variáveis de instância | |
x = 0; | |
} | |
/** | |
* Exemplo de método - substitua este comentário pelo seu próprio | |
* | |
* @param y exemplo de um parâmetro de método | |
* @return a soma de x com y | |
*/ | |
public int sampleMethod(int y) | |
{ | |
// ponha seu código aqui | |
return x + y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da classe ClassePai aqui. | |
* | |
* @author (seu nome) | |
* @version (número de versão ou data) | |
*/ | |
public class ClassePai | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private int x; | |
/** | |
* COnstrutor para objetos da classe ClassePai | |
*/ | |
public ClassePai() | |
{ | |
// inicializa variáveis de instância | |
x = 0; | |
} | |
/** | |
* Exemplo de método - substitua este comentário pelo seu próprio | |
* | |
* @param y exemplo de um parâmetro de método | |
* @return a soma de x com y | |
*/ | |
protected int sampleMethod(int y) | |
{ | |
// ponha seu código aqui | |
return x + y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Exemplo | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private Buffer buf1; | |
private Buffer buf2; | |
public Exemplo() | |
{ | |
// inicializa variáveis de instância | |
this.buf1 = new Buffer(15); | |
this.buf2 = new Buffer(20); | |
} | |
public void calculaNumeros() | |
{ | |
// ponha seu código aqui | |
Buffer.teste(); | |
int v1 = this.buf1.calculaNumero(); | |
int v2 = this.buf2.calculaNumero(); | |
System.out.println(v1 + " " + v2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da classe Implementacao aqui. | |
* | |
* @author (seu nome) | |
* @version (número de versão ou data) | |
*/ | |
public class Implementacao implements Padrao | |
{ | |
public void metodo(int param) { | |
Rota sul = Rota.SUL; | |
switch(sul) { | |
case SUL: | |
break; | |
case NORTE: | |
break; | |
case LESTE: | |
break; | |
case OESTE: | |
break; | |
} | |
System.out.println("Hello World!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Escreva a descrição da interface Padrao aqui. | |
* | |
* @author (seu nome) | |
* @version (número da versão ou data) | |
*/ | |
public interface Padrao | |
{ | |
/** | |
* Exemplo de um cabeçalho de método - substitua este comentário pelo seu | |
*/ | |
int variavel = 0; | |
public void metodo(int param); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Propriedades | |
{ | |
// variáveis de instância - substitua o exemplo abaixo pelo seu próprio | |
private int x; | |
private int y; | |
public Propriedades() | |
{ | |
// inicializa variáveis de instância | |
this.x = 0; | |
this.y = 0; | |
} | |
public int getX() { | |
return this.x; | |
} | |
public int getY() { | |
return this.y; | |
} | |
public void setX(int novoX) { | |
this.x = novoX; | |
} | |
public void setY(int novoY) { | |
this.y = novoY; | |
} | |
public String toString() { | |
return "x: " + this.getX() + " y: " + this.getY(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enumeration class Rota - write a description of the enum class here | |
* | |
* @author (your name here) | |
* @version (version number or date here) | |
*/ | |
public enum Rota | |
{ | |
SUL, OESTE, LESTE, NORTE; | |
Rota() { | |
} | |
void metodo(int param) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Usos | |
{ | |
public static void testeGetterSetter() { | |
Propriedades prop = new Propriedades(); | |
System.out.println("Prop - x: " + prop.getX() + " y: " + prop.getY()); | |
prop.setX(10); | |
prop.setY(70); | |
System.out.println("Prop - x: " + prop.getX() + " y: " + prop.getY()); | |
Propriedades propNovo = new Propriedades(); | |
System.out.println("PropNovo - x: " + propNovo.getX() + " y: " + propNovo.getY()); | |
propNovo.setX(20); | |
propNovo.setY(60); | |
System.out.println("PropNovo - x: " + propNovo.getX() + " y: " + propNovo.getY()); | |
System.out.println(propNovo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment