Last active
September 23, 2021 21:24
-
-
Save InacioCarvalhoOliveira/18d10a4e735839e706f001ba916b529e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Questão 5 | |
O que faz um método construtor? | |
Crie uma classe Pessoa e defina | |
seu construtor padrão. | |
---------------------------------- | |
1° CLASSE PUBLICA OBJ Pessoa; | |
2º ATRIBUTO CRIADO DENTRO DA CLASSE; | |
3° CONSTRUTOR DE CLASSE PARA O class Pessoa; | |
4° VALOR SETADO INCIALMENTE PARA O ATRIBUTO usrUm; | |
5° CRIA UM OBJETO DA CLASSE Pessoa, ESTE COMANDO QUEM CHAMARÁ O CONSTRUTOR; | |
6° IMPRIME O VALOR DE usrUM; | |
*/ | |
/*1º*/ public class Pessoa { | |
/*2°*/ int usrUm; | |
/*3°*/ public Pessoa() { | |
/*4°*/ usrUm = 5; | |
} | |
public static void main(String[] args) { | |
/*5°*/ Pessoa myObj = new Pessoa(); | |
System.out.println(myObj.usrUm); | |
} | |
} |
This file contains hidden or 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
/* | |
Reescreva a questão 8 da Lista 3 usando POO "Escreva um programa | |
que lê nome, peso e altura de 5 pessoas, calcula o IMC de cada | |
um e ao final informa se alguém está fora do peso ideal (o IMC | |
ideal é entre 18,5 e 25)."/* | |
*/ | |
package br.com.letscode.java; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Imc { | |
public final String[] Nome = new String[5]; | |
private float Altura;//-- | |
private float Peso; | |
private double IMC;//-- | |
public Imc() { // método de 1° | |
this.IMC = IMC; | |
this.Peso = Peso; | |
this.Altura = Altura; | |
float[] Peso = {70.6F, 95.4F, 102.35F, 124.78F, 64.5F}; | |
float[] Altura; | |
Altura = new float[5]; | |
Altura[0] = 1.70F; | |
Altura[1] = 1.54F; | |
Altura[2] = 1.20F; | |
Altura[3] = 1.95F; | |
Altura[4] = 1.45F; | |
String[] Nome = {"Joao", "Jose", "Jota", "Junior", "Janio"}; | |
for (int i = 0; i < Nome.length; i++) { | |
double IMC = Peso[i] / Math.pow(Altura[i], 2); | |
if (IMC < 18.5 || IMC > 25) { | |
System.out.printf("%s está fora do peso ideal, com IMC = %.2f.%n", Nome[i], IMC); | |
} | |
} | |
} | |
public static void main(String[] args) {// recebe os comandos | |
Imc myOjb = new Imc(); | |
System.out.println(Arrays.toString(myOjb.Nome)); | |
} | |
} | |
This file contains hidden or 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
/* | |
Crie uma classe para representar a estrutura de dados para uma Pessoa, | |
contendo os atributos de nome, idade. ok | |
Defina os métodos construtor padrão e completo, e os acessadores e | |
modificadores para cada atributo. | |
Também escreva o método "toString" para essa classe. | |
*/ | |
public class Profile { | |
String nome; | |
int idade; | |
int ID ; | |
public Profile(){ | |
nome = "Inacio Carvalho de Oliveira"; | |
idade = 20; | |
ID = 3015076; | |
} | |
public Profile(String nome, int idade, int ID) { | |
this.nome = nome; | |
this.idade = idade; | |
this.ID = ID; | |
} | |
public String toString() { | |
return this.nome; | |
} | |
public static void main(String[] args) { | |
Profile myObj = new Profile(); | |
System.out.println(myObj.toString()); | |
System.out.println(myObj.idade); | |
System.out.println(myObj.ID); | |
} | |
} |
This file contains hidden or 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 Pessoa { // classe e objetos setados | |
private String[] nome; | |
private int[] idade; | |
private int indiceMaiorIdade = 0; | |
private int indiceMenorIdade = 0; | |
// ----------------------------------------------------------- | |
public Pessoa(String[] nome, int[] idade) { // metodos dos objetos | |
this.nome = nome; // atributo | |
this.idade = idade; // atributo | |
} | |
public String maisVelho() { // metodo indiviudal, vaz um cáculo e morre | |
for (int i = 0; i < 5; i++) { | |
if (idade[i] > idade[indiceMaiorIdade]){ | |
indiceMaiorIdade = i; | |
} | |
} | |
return "\nO(a) mais velho(a) é '" + nome[indiceMaiorIdade] + "', idade de " + idade[indiceMaiorIdade]; | |
} | |
public String maisNovo() {// metodo indiviudal, vaz um cáculo e morre | |
for (int i = 0; i < 5; i++) { | |
if (idade[i] < idade[indiceMenorIdade] || indiceMenorIdade == 0) { | |
indiceMenorIdade = i; | |
} | |
} | |
return "\nO(a) mais novo(a) é '" + nome[indiceMenorIdade] + "', idade de " + idade[indiceMenorIdade]; | |
} | |
public String mediaIdade() {// metodo indiviudal, vaz um cáculo e morre | |
int somatorio = 0; | |
for (int i = 0; i < 5; i++) { | |
somatorio += idade[i]; | |
} | |
return "\nA média de idades é " + somatorio / idade.length; | |
} | |
} |
This file contains hidden or 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 Tela { // classe principal | |
public static void main(String[] args) {// classe estática | |
String[] nomes = {"Renan", "Marco", "Buben", "Caio", "Zé"};//atributo | |
int[] idades = {4, 6, 10, 12, 25};//atributo | |
Pessoa pessoa = new Pessoa(nomes, idades);// chama o método pessoa ( int , int) | |
System.out.println(pessoa.maisNovo());// coleta os métodos do file pessoa | |
System.out.println(pessoa.maisVelho());//-- | |
System.out.println(pessoa.mediaIdade());//-- | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment