Skip to content
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
Empty file modified gradlew
100644 → 100755
Empty file.
34 changes: 17 additions & 17 deletions src/main/java/br/com/project/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void main(String[] args) {
System.out.println("| |");
System.out.println("-------------------------------------");

while (sc.hasNext()){
while (true){
System.out.println("Selecione a operação desejada:");
System.out.println("1- Criar uma conta");
System.out.println("2- Criar um investimento");
Expand All @@ -44,16 +44,11 @@ public static void main(String[] args) {
System.out.println("13- Histórico de conta");
System.out.println("14- Sair");

try {
var option = sc.nextInt();
sc.nextLine();

if (!sc.hasNextInt()) {
System.out.println("Entrada inválida. Encerrando.");
break;
}

var option = sc.nextInt();
sc.nextLine();

switch (option){
switch (option){
case 1 -> createAccount();
case 2 -> createInvestment();
case 3 -> createInvestmentWallet();
Expand All @@ -76,11 +71,14 @@ public static void main(String[] args) {
}
default->
System.out.println("Opção inválida!");
}
} catch (java.util.InputMismatchException e) {
System.out.println("Entrada inválida. Por favor, insira um número.");
sc.nextLine(); // Limpa o buffer do scanner
} catch (Exception e) {
System.out.println("Ocorreu um erro: " + e.getMessage());
}
}


sc.close();
}

private static void createAccount() {
Expand Down Expand Up @@ -158,7 +156,7 @@ private static void createInvestmentWallet(){
System.out.println("Informe o id do investimento:");
var investmentId = sc.nextInt();
sc.nextLine();
var investment = investmentRepository.initInvestiment(account,investmentId);
var investment = investmentRepository.initInvestment(account,investmentId);
System.out.println("Carteira de investimento criada: "+investment);
}

Expand All @@ -170,7 +168,8 @@ private static void incInvest(){
var pix = sc.next();
sc.nextLine();
try{
accountRepository.deposit(pix,amount);
investmentRepository.deposit(pix,amount);
System.out.println("Investimento realizado com sucesso!");
} catch (WalletNotFoundException | AccountNotFoundException e) {
System.out.println(e.getMessage());
}
Expand All @@ -184,8 +183,9 @@ private static void rescueInvestment(){
var pix = sc.next();
sc.nextLine();
try {
accountRepository.withdraw(pix, amount);
} catch (NoFundsEnoughException | AccountNotFoundException e) {
investmentRepository.withdraw(pix, amount);
System.out.println("Resgate realizado com sucesso!");
} catch (NoFundsEnoughException | AccountNotFoundException | WalletNotFoundException e) {
System.out.println(e.getMessage());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/br/com/project/model/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.UUID;
import java.util.stream.Stream;

@ToString
public abstract class Wallet {
@Getter
private final BankService service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Investment create(final long tax, final long initialFounds) {
return investiment;
}

public InvestmentWallet initInvestiment(final AccountWallet account, final long id){
public InvestmentWallet initInvestment(final AccountWallet account, final long id){
if(!wallets.isEmpty()) {
var accountsInUse = wallets.stream().map(InvestmentWallet::getAccount).toList();
if (accountsInUse.contains(account)) {
Expand Down