Last active
April 26, 2019 02:29
-
-
Save luscas/f1363fedd3ba60b93622d02ff4d3f157 to your computer and use it in GitHub Desktop.
UML -> Code
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.util.ArrayList; | |
public class Carrinho { | |
Cliente cliente; | |
double valor; | |
Pagamento pagamento; | |
ArrayList<Produto> produtos = new ArrayList<Produto>(); | |
Carrinho(Cliente cliente) { | |
this.cliente = cliente; | |
this.pagamento = new Pagamento(this.cliente); | |
} | |
void adicionaProduto(Produto produto) { | |
this.produtos.add(produto); | |
} | |
boolean finalizar() { | |
for(Produto produto : this.produtos) { | |
this.valor += produto.valor; | |
} | |
this.pagamento.valor = this.valor; | |
return this.pagamento.pagar(); | |
} | |
} |
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 Cliente { | |
String endereco, nome; | |
} |
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
class Pagamento { | |
double valor = 0.0; | |
Cliente cliente; | |
Pagamento(Cliente cliente) { | |
this.cliente = cliente; | |
} | |
boolean pagar() { | |
return this.cliente.saldo >= this.valor ? this.retira_saldo() : false; | |
} | |
private boolean retira_saldo() { | |
cliente.saldo = this.valor - this.cliente.saldo; | |
return true; | |
} | |
} |
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 Teste { | |
public static void main() { | |
Cliente lucas = new Cliente("Lucas", "Rua da Paz 3363 Picos Pi", 10000.0); | |
Produto iphonex = new Produto("iPhone X", 3500.0); | |
Produto iphone5s = new Produto("iPhone 5s", 900.0); | |
Carrinho carrinhoDeLucas = new Carrinho(lucas); | |
carrinhoDeLucas.adicionaProduto(iphonex); | |
carrinhoDeLucas.adicionaProduto(iphone5s); | |
if(carrinhoDeLucas.finalizar()) { | |
System.out.println("Pagou"); | |
} else { | |
System.out.println("Deixou fiado"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment