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

Desafio Finalizado - Kayque A. Silveira #18

Open
wants to merge 1 commit 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
45 changes: 37 additions & 8 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import { CompanyAccount } from './class/CompanyAccount'
import { PeopleAccount } from './class/PeopleAccount'
import { CompanyAccount } from "./class/CompanyAccount";
import { PeopleAccount } from "./class/PeopleAccount";
import { AffiliateAccount } from "./class/AffiliateAccount";

const peopleAccount: PeopleAccount = new PeopleAccount(1, 'Nath', 10)
console.log(peopleAccount)
peopleAccount.deposit()
const companyAccount: CompanyAccount = new CompanyAccount('DIO', 20)
companyAccount.deposit()
console.log(companyAccount)
// TODO 1: Crie uma instância da classe CompanyAccount e execute os metodos
const companyAccount = new CompanyAccount("Kayque", 1);
companyAccount.getBalance();
console.log(companyAccount.deposit(10));
companyAccount.getBalance();
companyAccount.withdraw(5);
companyAccount.getBalance();
console.log(companyAccount.getName());
console.log(companyAccount.setName("Kayque Ambires"));
console.log(companyAccount.validateStatus());

// TODO 2: Crie uma instância da classe PeopleAccount e execute os metodos
const peopleAccount = new PeopleAccount(1, "Jorge", 2);
peopleAccount.getBalance();
console.log(peopleAccount.deposit(10));
peopleAccount.getBalance();
peopleAccount.withdraw(5);
peopleAccount.getBalance();
console.log(peopleAccount.getName());
console.log(peopleAccount.setName("Jorge Silva"));
console.log(peopleAccount.validateStatus());

// TODO 3: Crie uma instância da classe AffiliateAccount e execute os metodos
const affiliateAccount = new AffiliateAccount("Ruan", 3);
affiliateAccount.getBalance();
console.log(affiliateAccount.deposit(10));
affiliateAccount.getBalance();
console.log(affiliateAccount.depositExtra(20));
affiliateAccount.getBalance();
affiliateAccount.withdraw(10);
affiliateAccount.getBalance();
console.log(affiliateAccount.getName());
console.log(affiliateAccount.setName("Ruan Vieira"));
console.log(affiliateAccount.validateStatus());
18 changes: 18 additions & 0 deletions class/AffiliateAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DioAccount } from "./DioAccount";

export class AffiliateAccount extends DioAccount {
constructor(name: string, accountNumber: number) {
super(name, accountNumber);
}

// TODO: Criar um novo tipo de conta a partir da classe DioAccount
// Esta conta não deve receber novos atributos
// Esta conta terá um método de depósito, que acresce 10 a mais ao valor informado para depósito. (Ex: Um depósitio de R$ 100,00 ficaria R$ 110,00)

depositExtra = (value: number): string => {
if (this.validateStatus()) {
this.deposit(value + 10);
}
return "Voce depositou R$ " + value.toFixed(2) + " com o extra de R$ 10.00";
};
}
16 changes: 9 additions & 7 deletions class/CompanyAccount.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { DioAccount } from "./DioAccount"
import { DioAccount } from "./DioAccount";

export class CompanyAccount extends DioAccount {

constructor(name: string, accountNumber: number){
super(name, accountNumber)
constructor(name: string, accountNumber: number) {
super(name, accountNumber);
}

getLoan = (): void => {
console.log('Voce pegou um empréstimo')
}
getLoan = (value: number): string => {
if (this.validateStatus()) {
this.deposit(value);
}
return "Você pegou um empréstimo de R$ " + value.toFixed(2);
};
}
68 changes: 39 additions & 29 deletions class/DioAccount.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
export abstract class DioAccount {
private name: string
private readonly accountNumber: number
balance: number = 0
private status: boolean = true

constructor(name: string, accountNumber: number){
this.name = name
this.accountNumber = accountNumber
private name: string;
private readonly accountNumber: number;
private balance: number = 0;
private status: boolean = true;

constructor(name: string, accountNumber: number) {
this.name = name;
this.accountNumber = accountNumber;
}

setName = (name: string): void => {
this.name = name
console.log('Nome alterado com sucesso!')
}
setName = (name: string): string => {
this.name = name;
console.log("Nome alterado com sucesso!");
return this.name;
};

getName = (): string => {
return this.name
}
return this.name;
};

deposit = (): void => {
if(this.validateStatus()){
console.log('Voce depositou')
deposit = (value: number): string => {
if (this.validateStatus()) {
this.balance += value;
}
}

withdraw = (): void => {
console.log('Voce sacou')
}
return "Voce depositou R$ " + value.toFixed(2);
};

withdraw = (value: number): void => {
if (this.validateStatus()) {
if (this.balance >= value) {
this.balance -= value;
console.log("Voce sacou R$ " + value.toFixed(2));
} else {
throw new Error("Saldo insuficiente");
}
}
};

getBalance = (): void => {
console.log(this.balance)
}
getBalance = (): number => {
console.log("Saldo: R$ " + this.balance.toFixed(2));
return this.balance;
};

private validateStatus = (): boolean => {
validateStatus = (): boolean => {
if (this.status) {
return this.status
return this.status;
}

throw new Error('Conta inválida')
}
throw new Error("Conta inválida");
};
}
12 changes: 6 additions & 6 deletions class/PeopleAccount.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DioAccount } from "./DioAccount"
import { DioAccount } from "./DioAccount";

export class PeopleAccount extends DioAccount {
doc_id: number
doc_id: number;

constructor(doc_id: number, name: string, accountNumber: number){
super(name, accountNumber)
this.doc_id = doc_id
constructor(doc_id: number, name: string, accountNumber: number) {
super(name, accountNumber);
this.doc_id = doc_id;
}
}
}