Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolução do desafio, criação de parametros, validações/invalidações #61

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class ProcessoSeletivo {
public static void main(String[] args) {

String[] candidatos = { "FELIPE", "MARCIA", "PAULO", "AUGUSTO" };

for (String candidato : candidatos) {
entrandoEmContato(candidato);
}
}

static void entrandoEmContato(String candidato) {

int tentativasRealizadas = 1;
boolean continuarTentando = true;
boolean atendeu = false;

do {

atendeu = atender();
continuarTentando = !atendeu;
if (continuarTentando)
tentativasRealizadas++;
else
System.out.println("CONTATO REALIZADO COM SUCESSO");

} while (continuarTentando && tentativasRealizadas < 3);

if (atendeu)
System.out.println("CONSEGUIMOS CONTATO COM " + candidato + " NA " + tentativasRealizadas + " TENTATIVA");
else
System.out.println("NÃO CONSEGUIMOS CONTATO COM " + candidato + ", NÚMERO MÁXIMO TENTATIVAS "
+ tentativasRealizadas + " REALIZADAS");
}

// método auxiliar

static boolean atender() {
return new Random().nextInt(3) == 1;
}

static void imprimirSelecionador() {
String[] candidatos = { "FELIPE", "MARCIA", "PAULO", "AUGUSTO" };

System.out.println("Imprimindo a lista de candidatos informando o indice de elemento");

for (int indice = 0; indice < candidatos.length; indice++) {
System.out.println("O candidato de n°" + (indice + 1) + " é o " + candidatos[indice]);
}

System.out.println("Forma abreviada de interação for each");

for (String candidato : candidatos) {
System.out.println("O candidato selecionado foi " + candidato);
}
}

static void selecaoCandidatos() {
String[] candidatos = { "FELIPE", "MARCIA", "PAULO", "AUGUSTO", "MONICA", "FABRICIO", "MIRELA", "DANIELA",
"JORGE" };

int candidatosSelecionados = 0;
int candidatosAtual = 0;
double salarioBase = 2000.0;

while (candidatosSelecionados < 5 && candidatosAtual < candidatos.length) {
String candidato = candidatos[candidatosAtual];
double salarioPretendido = valorPretendido();

System.out.println("O candidato " + candidato + " Solicitou este valor de salário " + salarioPretendido);

if (salarioBase >= salarioPretendido) {
System.out.println("O candidato " + candidato + " foi selecionado para a vaga");
candidatosSelecionados++;
}
candidatosAtual++;
}
}

static double valorPretendido() {
return ThreadLocalRandom.current().nextDouble(1800, 2200);
}

static void analisarCandidato(double salarioPretendido) {

double salarioBase = 2000.0;

if (salarioBase > salarioPretendido) {
System.out.println("LIGAR PARA O CANDIDATO");
} else if (salarioBase == salarioPretendido)
System.out.println("LIGAR PARA O CANDIDATO COM CONTRA PROPOSTA");
else {
System.out.println("AGUARDANDO O RESULTADO DOS DEMAIS CANDIDATOS");
}
}

}
109 changes: 109 additions & 0 deletions desafios/controle-fluxo/modelando_iphone_com_uml/Iphone POO.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<mxfile host="app.diagrams.net" modified="2024-07-16T17:57:52.429Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0" etag="X17f1dvkwOQt_cVC5IEs" version="24.6.5" type="github">
<diagram name="Page-1" id="929967ad-93f9-6ef4-fab6-5d389245f69c">
<mxGraphModel dx="1408" dy="699" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1.5" pageWidth="1169" pageHeight="826" background="none" math="0" shadow="0">
<root>
<mxCell id="0" style=";html=1;" />
<mxCell id="1" style=";html=1;" parent="0" />
<mxCell id="1672d66443f91eb5-1" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; margin-left: 10px ; text-align: left&quot;&gt;&lt;b&gt;req&lt;/b&gt;&amp;nbsp;[package] HSUVRequirements[HSUV Specification]&lt;/p&gt;" style="html=1;strokeWidth=1;shape=mxgraph.sysml.package;html=1;overflow=fill;whiteSpace=wrap;fillColor=none;gradientColor=none;fontSize=12;align=center;labelX=327.64;" parent="1" vertex="1">
<mxGeometry x="317" y="295" width="1120" height="650" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-2" value="HSUVSpecification" style="shape=folder;tabWidth=80;tabHeight=20;tabPosition=left;strokeWidth=1;html=1;whiteSpace=wrap;align=center;fontSize=12;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="437" y="355" width="160" height="90" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-3" value="&lt;b&gt;RefinedBy&lt;/b&gt;&lt;div&gt;&amp;lt;&amp;lt;&amp;gt;useCase&amp;gt; HSUVUseCases : Accelerate&lt;/div&gt;" style="shape=note;size=15;align=left;spacingLeft=10;html=1;whiteSpace=wrap;strokeColor=#000000;strokeWidth=1;fillColor=#ffffff;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="867" y="365" width="300" height="60" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;jettySize=auto;orthogonalLoop=1;endArrow=circlePlus;endFill=0;" parent="1" source="1672d66443f91eb5-4" target="1672d66443f91eb5-2" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="477" y="485" />
<mxPoint x="517" y="485" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-4" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;Eco-Friendliness&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="397" y="535" width="160" height="80" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=circlePlus;endFill=0;jettySize=auto;orthogonalLoop=1;" parent="1" source="1672d66443f91eb5-5" target="1672d66443f91eb5-2" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="717" y="485" />
<mxPoint x="517" y="485" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-5" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;Performance&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="637" y="535" width="160" height="70" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-21" style="edgeStyle=none;rounded=0;html=1;dashed=1;endArrow=none;endFill=0;jettySize=auto;orthogonalLoop=1;" parent="1" source="1672d66443f91eb5-6" target="1672d66443f91eb5-9" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-6" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;Power&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="1107" y="535" width="160" height="70" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=circlePlus;endFill=0;jettySize=auto;orthogonalLoop=1;entryX=0.25;entryY=1;" parent="1" source="1672d66443f91eb5-7" target="1672d66443f91eb5-5" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="627" y="635" />
<mxPoint x="677" y="635" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-7" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;Braking&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="547" y="655" width="160" height="70" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-17" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=circlePlus;endFill=0;jettySize=auto;orthogonalLoop=1;entryX=0.5;entryY=1;" parent="1" source="1672d66443f91eb5-8" target="1672d66443f91eb5-5" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="817" y="635" />
<mxPoint x="717" y="635" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-8" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;FuelEconomy&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="737" y="655" width="160" height="70" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-18" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=circlePlus;endFill=0;jettySize=auto;orthogonalLoop=1;entryX=0.75;entryY=1;" parent="1" source="1672d66443f91eb5-9" target="1672d66443f91eb5-5" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1017" y="625" />
<mxPoint x="757" y="625" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-22" style="edgeStyle=none;rounded=0;html=1;dashed=1;endArrow=none;endFill=0;jettySize=auto;orthogonalLoop=1;" parent="1" source="1672d66443f91eb5-9" target="1672d66443f91eb5-3" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-9" value="&lt;p&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;/p&gt;&lt;p&gt;Acceleration&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;align=center;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="937" y="655" width="160" height="70" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=circlePlus;endFill=0;jettySize=auto;orthogonalLoop=1;" parent="1" source="1672d66443f91eb5-10" target="1672d66443f91eb5-4" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="477" y="755" />
<mxPoint x="477" y="755" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="1672d66443f91eb5-10" value="&lt;p style=&quot;margin: 0px ; margin-top: 4px ; text-align: center&quot;&gt;&amp;lt;&amp;lt;requirement&amp;gt;&amp;gt;&lt;br&gt;&lt;b&gt;Emissions&lt;/b&gt;&lt;/p&gt;&lt;hr&gt;&lt;p style=&quot;margin: 0px ; margin-left: 8px ; text-align: left&quot;&gt;Id = &quot;R1.1.2&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px ; margin-left: 8px ; text-align: left&quot;&gt;text=&quot;The vehicle shall meet UltraLow Emissions Vehicle standards.&quot;&lt;/p&gt;" style="shape=rect;html=1;overflow=fill;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="427" y="785" width="290" height="120" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-19" style="rounded=0;html=1;endArrow=none;endFill=0;jettySize=auto;orthogonalLoop=1;dashed=1;" parent="1" source="1672d66443f91eb5-11" target="1672d66443f91eb5-9" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-11" value="&lt;b&gt;VerifiedBy&lt;/b&gt;&lt;div&gt;&amp;lt;&amp;lt;testCase&amp;gt;&amp;gt; MaxAcceleration&lt;/div&gt;" style="shape=note;size=15;align=left;spacingLeft=10;html=1;whiteSpace=wrap;strokeWidth=1;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="832" y="825" width="210" height="60" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-20" style="edgeStyle=none;rounded=0;html=1;dashed=1;endArrow=none;endFill=0;jettySize=auto;orthogonalLoop=1;" parent="1" source="1672d66443f91eb5-12" target="1672d66443f91eb5-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-12" value="&lt;b&gt;SatisfiedBy&lt;/b&gt;&lt;div&gt;&amp;lt;&amp;lt;block&amp;gt;&amp;gt; PowerSubsystem&lt;/div&gt;" style="shape=note;size=15;align=left;spacingLeft=10;html=1;whiteSpace=wrap;strokeWidth=1;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1082" y="825" width="210" height="60" as="geometry" />
</mxCell>
<mxCell id="1672d66443f91eb5-23" value="Title" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="120" y="40" width="1510" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
92 changes: 92 additions & 0 deletions desafios/controle-fluxo/modelando_iphone_com_uml/iPhone2007.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
public class iPhone2007 {

// iTunes (Reprodutor Musical)
public static class iTunes {
private String currentSong;
private boolean isPlaying;
private int volumeLevel;

public iTunes() {
this.currentSong = "";
this.isPlaying = false;
this.volumeLevel = 50;
}

public void play() {
}

public void pause() {
}

public void selectSong(String song) {
}

public void adjustVolume(int volume) {
}
}

// Telefone
public static class Telefone {
private String currentCallStatus;
private boolean isRinging;
private boolean isOnHold;

public Telefone() {
this.currentCallStatus = "";
this.isRinging = false;
this.isOnHold = false;
}

public void call(String number) {
}

public void answer() {
}

public void startVoiceMail() {
}
}

// Navegador de Internet
public static class NavegadorInternet {
private String currentURL;
private int numberOfTabs;

public NavegadorInternet() {
this.currentURL = "";
this.numberOfTabs = 1;
}

public void displayPage(String url) {
}

public void addNewTab() {
}

public void updatePage() {
}
}

// Exemplo de uso das classes
public static void main(String[] args) {
// Exemplo de uso do iTunes
iTunes iTunesPlayer = new iTunes();
iTunesPlayer.selectSong("Bohemian Rhapsody");
iTunesPlayer.play();
iTunesPlayer.adjustVolume(75);
iTunesPlayer.pause();

// Exemplo de uso do Telefone
Telefone phone = new Telefone();
phone.call("123456789");
phone.answer();
phone.startVoiceMail();

// Exemplo de uso do Navegador de Internet
NavegadorInternet browser = new NavegadorInternet();
browser.displayPage("https://www.youtube.com");
browser.addNewTab();
browser.displayPage("https://www.youtube.com");
browser.updatePage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*# DIO - Trilha Java Básico
www.dio.me

#### Autores
- [Gleyson Sampaio](https://github.com/glysns)

## Controle de Fluxo - Desafio

Vamos exercitar todo o conteúdo apresentado no módulo de Controle de Fluxo codificando o seguinte cenário.

O sistema deverá receber dois parâmetros via terminal que representarão dois números inteiros, com estes dois números você deverá obter a quantidade de interações (for) e realizar a impressão no console (System.out.print) dos números incrementados, exemplo:

* Se você passar os números 12 e 30, logo teremos uma interação (for) com 18 ocorrências para imprimir os números, exemplo: `"Imprimindo o número 1"`, `"Imprimindo o número 2"` e assim por diante.
* Se o primeiro parâmetro for MAIOR que o segundo parâmetro, você deverá lançar a exceção customizada chamada de `ParametrosInvalidosException` com a segunda mensagem: "O segundo parâmetro deve ser maior que o primeiro"


1. Crie o projeto `DesafioControleFluxo`
2. Dentro do projeto, crie a classe `Contador.java` para realizar toda a codificação do nosso programa.
3. Dentro do projeto, crie a classe `ParametrosInvalidosException` que representará a exceção de negócio no sistema.

Abaixo temos um trecho de código no qual você poderá seguir alterando as partes que contenham `??`

```java*/

//RESOLUCAO

import java.util.Scanner;

public class Contador {
public static void main(String[] args) {

Scanner oli = new Scanner(System.in);

System.out.println("Digite o primeiro parâmetro");
int parametroUm = oli.nextInt();

System.out.println("Digite o segundo parâmetro");
int parametroDois = oli.nextInt();

try {
// chamando o método contendo a lógica de contagem
contar(parametroUm, parametroDois);
} catch (ParametrosInvalidosException exception) {
// imprimir a mensagem: O segundo parâmetro deve ser maior que o primeiro
System.out.println(exception.getMessage());
}
}

static void contar(int parametroUm, int parametroDois) throws ParametrosInvalidosException {
// validar se parametroUm é MAIOR que parametroDois e lançar a exceção
if (parametroUm > parametroDois) {
throw new ParametrosInvalidosException("O segundo parâmetro deve ser maior que o primeiro");
}

int contagem = parametroDois - parametroUm;
// realizar o for para imprimir os números com base na variável contagem
for (int i = 1; i <= contagem; i++) {
System.out.println("Imprimindo o número " + i);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class ParametrosInvalidosException extends Exception {
// Construtor que recebe uma mensagem e a passa para a classe Exception
public ParametrosInvalidosException(String mensagem) {
super(mensagem);
}
}