-
Notifications
You must be signed in to change notification settings - Fork 35
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
Kauana tomb #22
Open
kauanatomb
wants to merge
2
commits into
reprograma:main
Choose a base branch
from
kauanatomb:kauana-tomb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kauana tomb #22
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//Exercicio Proposto: Considere um objeto que represente uma conta bancária, a conta possui o nome do titular, o saldo e o limite da conta. É possível fazer operações de consulta de saldo, saque e depósito. No caso de saque é necessário verificar se existe saldo suficiente para retirada, caso o cliente não tenha saldo suficiente para a operação, mas possua limite disponível (e suficiente), o saque poderá ocorrer, nesses casos o saldo do cliente ficará negativo após o saque. Além disso, o limite de uma conta pode ser reajustado (para mais e para menos) ou desativado. Use a abordagem Red - Green - Refactor para desenvolver essa aplicação. | ||
|
||
class Bank { | ||
constructor(nome, saldo, limite) { | ||
this.nome = nome | ||
this.saldo = saldo | ||
this.limite = limite | ||
} | ||
|
||
consultarSaldo() { | ||
return this.saldo | ||
} | ||
|
||
consultarLimite() { | ||
return this.limite | ||
} | ||
|
||
depositar(valor) { | ||
this.saldo = this.saldo + valor | ||
return this.consultarSaldo() | ||
} | ||
|
||
sacar(valor) { | ||
if (valor > this.saldo) { | ||
if (valor > this.limite) { | ||
throw new Error('Saldo insuficiente') | ||
} else { | ||
this.limite = this.limite - valor | ||
this.saldo = this.saldo - valor | ||
} | ||
} else { | ||
this.saldo = this.saldo - valor | ||
} | ||
return this.consultarSaldo() | ||
} | ||
|
||
reajustarLimite(valor) { | ||
this.limite = valor | ||
return this.consultarLimite() | ||
} | ||
|
||
desativarLimite() { | ||
this.limite = 0 | ||
return this.consultarLimite() | ||
} | ||
} | ||
|
||
module.exports = Bank |
32 changes: 32 additions & 0 deletions
32
exercicios/para-casa/entregas/kauana-tombolato/bank.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const bank = require("./bank") | ||
|
||
describe("test with bank", () => { | ||
// deposito | ||
let account | ||
beforeEach(() => { | ||
account = new bank("Kauana", 100, 50) | ||
}) | ||
test("validar deposito", () => { | ||
expect(account.depositar(200)).toEqual(300) | ||
}) | ||
|
||
// saque | ||
test("validar saque", () => { | ||
expect(account.sacar(50)).toEqual(50) | ||
}) | ||
|
||
// saque quando não tem saldo mas tem limite | ||
test("validar saque", () => { | ||
expect(() => { account.sacar(1200) }).toThrowError(); | ||
}); | ||
|
||
// reajustar limite | ||
test("validar reajuste de limite", () => { | ||
expect(account.reajustarLimite(100)).toEqual(100) | ||
}) | ||
|
||
// desativar limite | ||
test("validar desativar limite", () => { | ||
expect(account.desativarLimite()).toEqual(0) | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
exercicios/para-casa/entregas/kauana-tombolato/bankAccount.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//Exercicio Proposto: Considere um objeto que represente uma conta bancária, a conta possui o nome do titular, o saldo e o limite da conta. É possível fazer operações de consulta de saldo, saque e depósito. No caso de saque é necessário verificar se existe saldo suficiente para retirada, caso o cliente não tenha saldo suficiente para a operação, mas possua limite disponível (e suficiente), o saque poderá ocorrer, nesses casos o saldo do cliente ficará negativo após o saque. Além disso, o limite de uma conta pode ser reajustado (para mais e para menos) ou desativado. Use a abordagem Red - Green - Refactor para desenvolver essa aplicação. | ||
|
||
class BankAccount { | ||
constructor(nome, saldo, limite) { | ||
this.nome = nome | ||
this.saldo = saldo | ||
this.limite = limite | ||
} | ||
|
||
consultarSaldo() { | ||
return this.saldo | ||
} | ||
|
||
consultarLimite() { | ||
return this.limite | ||
} | ||
|
||
depositar(valor) { | ||
this.saldo = this.saldo + valor | ||
return this.consultarSaldo() | ||
} | ||
|
||
sacar(valor) { | ||
if (valor > this.saldo) { | ||
if (valor > this.limite) { | ||
throw new Error('Saldo insuficiente') | ||
} else { | ||
this.limite = this.limite - valor | ||
this.saldo = this.saldo - valor | ||
} | ||
} else { | ||
this.saldo = this.saldo - valor | ||
} | ||
return this.consultarSaldo() | ||
} | ||
|
||
reajustarLimite(valor) { | ||
this.limite = valor | ||
return this.consultarLimite() | ||
} | ||
|
||
desativarLimite() { | ||
this.limite = 0 | ||
return this.consultarLimite() | ||
} | ||
} | ||
|
||
module.exports = BankAccount |
32 changes: 32 additions & 0 deletions
32
exercicios/para-casa/entregas/kauana-tombolato/bankAccount.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const bankAccount = require("./bankAccount") | ||
|
||
describe("test with bankAccount", () => { | ||
// deposito | ||
let account | ||
beforeEach(() => { | ||
account = new bankAccount("Kauana", 100, 50) | ||
}) | ||
test("validar deposito", () => { | ||
expect(account.depositar(200)).toEqual(300) | ||
}) | ||
|
||
// saque | ||
test("validar saque", () => { | ||
expect(account.sacar(50)).toEqual(50) | ||
}) | ||
|
||
// saque quando não tem saldo mas tem limite | ||
test("validar saque", () => { | ||
expect(() => { account.sacar(1200) }).toThrowError(); | ||
}); | ||
|
||
// reajustar limite | ||
test("validar reajuste de limite", () => { | ||
expect(account.reajustarLimite(100)).toEqual(100) | ||
}) | ||
|
||
// desativar limite | ||
test("validar desativar limite", () => { | ||
expect(account.desativarLimite()).toEqual(0) | ||
}) | ||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esse arquivo pode ser excluído, já que os códigos estão nos outros arquivos. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//exercicios feitos pela profa aqui |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Olá Kauana, primeiramente parabéns pelo projeto, você validou todos os cenários. Como sugestão você poderia validar o saque em um único if.
if (valor > this.saldo && valor > this.limite){
throw new Error('Saldo insuficiente')
}
Outro ponto acredito que o Else ficou um pouco confuso usando saldo e limite
this.limite = this.limite - valor
this.saldo = this.saldo - valor
}
Mais uma vez parabéns pelo código e dedicação se precisar de ajuda, conte comigo!