xmauron avatar

Mastering the Basics of Java 👨‍💻 [ENG/PT]

xmauron3

Published: 29 Aug 2024 › Updated: 29 Aug 2024Mastering the Basics of Java 👨‍💻 [ENG/PT]

Mastering the Basics of Java 👨‍💻 [ENG/PT]

Hello my friends,

Today I want to share with you a little bit more of my learning progress with Java.

Banking Application (for learning and fun purposes)

alt

This program simulates a banking app where you can 'play' and learn a bit more about Java commands. I'm still at a beginner level, so every progress is a victory!

As you will se below, in this lesson I was learning how to use the "if", "else", and "else if" statements.
I met a friend of mine last weekend, and he also taught me how to use the "while" command, which makes the program rerun automatically. You will see that every time I wrote "stop = false;", the program stopped rerunning automatically.

If you are into learning Java, follow me and I will keep you updated with my progress!

Have a great day and let's code together!


PORTUGUESE 🇧🇷 PORTUGUÊS 🇵🇹

Eai meus amigos da Hive,

Esse programa simula um aplicativo de banco, onde é possível "brincar" e aprender um pouco mais sobre os comando de Java. Ainda estou num nível principiante, portanto cada progresso é uma vitória!

Aplicativo Bancário (para fins de aprendizado e diversão)

Como você verá abaixo, nesta lição eu estava aprendendo a usar as instruções "if", "else" e "else if". Encontrei um amigo meu no último fim de semana, e ele também me ensinou a usar o comando "while", que faz o programa ser executado automaticamente. Você verá que toda vez que escrevi "stop = false;", o programa parou de ser executado automaticamente.

Se você está interessado em aprender Java, siga-me e eu vou mantê-lo atualizado com meu progresso!

Tenha um ótimo dia e vamos codar juntos!



import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean stop = true;

    while (stop) {

        System.out.println("Welcome to the banking application");
        System.out.println("Our Operations:");
        System.out.println("Click 1 for cash transfer");
        System.out.println("Click 2 to transfer from balance");
        System.out.println("Click 3 to get money");
        System.out.println("Click 4 for return");
        System.out.println("Click 5 to HACK");
        int operation = sc.nextInt();
        //1 for example

        if (operation == 1) {
            System.out.println("How much money do you want to transfer?");
            System.out.println("Click 1 to transfer from $1 to $100");
            System.out.println("Click 2 to transfer from $101 to $1000");
            System.out.println("Click 3 to transfer more than $1000");

            stop = false;
            int operation3 = sc.nextInt();
            if (operation3 == 1) {
                System.out.println("Enter bank details");
             } else if (operation3 == 2) {
            System.out.println("Transactions above $100 need fingerprint authentication");
             } else if (operation3 == 3) {
            System.out.println("You must allow face recognition for transactions above $1000");
             } else {
            System.out.println("Invalid option selected.");
        }

// o else if da primeira operacao tem que ter sua chave condizendo com a abertura do "if"
        } else if (operation == 2) {
        System.out.println("How much money do you have?");
        stop = false;
        int balance=sc.nextInt();

            System.out.println("How much money do you want to transfer?");
            int transfer=sc.nextInt();
            System.out.println("You transferred your money");
            System.out.println("Your current balance is: " + (balance-transfer));
            System.out.println("Congratulations");
        } else if (operation==3) {
            System.out.println("Enter your bank balance");
            stop = false;
            int bankbalance = sc.nextInt();
            System.out.println("How much money do you want to take?");
            int money = sc.nextInt();
            System.out.println("You have withdrawn: " + (money));
            System.out.println("Your bank balance is now: " + (bankbalance - money));
            System.out.println("Do you wish to return to the main page?");
            System.out.println("Enter 1 to YES and 2 to Exit");

            int operation5 = sc.nextInt();
            if (operation5 == 1) {
            stop = true;
            }else if (operation5 == 2){
                stop = false;
            }else{
                System.out.println("Invalid operation, computer will explode");
            }
        } else if (operation==4) {
            System.out.println("Exit");

        } else if (operation==5) {
            System.out.println("WELCOME TO THE HACKER MENU...");
            System.out.println("WELCOME TO THE HACKER WORLD...");
            System.out.println("Choose your option, 1 to return to the main page or 2 to go deeper");
            int operation2=sc.nextInt();
            if (operation2==2) {

                stop = false;
            }
        } else {
            System.out.println("Invalid operation");
        }
    }
}

}

// Examples below:
// System.out.println("Welcome to the banking application");
// System.out.println("Our Operations:");
// System.out.println("Click 1 to exit from system");
// System.out.println("Click 2 for money transfer");
// System.out.println("Click 3 to get money");
// int operation=sc.nextInt();//1 for example
//
// if (operation1){
// System.out.println("Exiting from system");
// }else if (operation2) {
// System.out.println("Your money is transferring");
// }else if (operation==3) {
// System.out.println("You got your money");
// }else{
// System.out.println("Invalid operation");
//
//
// }

// the difference here from the exam program is that "else if" is
// related to a specific condition, while in the exam program
// else means ANYTHING ELSE THAN THE MINIMUM EXAM RESULT.
// in this banking program, we are giving an ORDER for the computer to OBEY.
// I can use a lot of IFs, but i need to remember that all of them will run at the same time. for example:
// if MALE=true,
// run the following orders: offer t-shirts, shorts, and shaving accessories.
// if olderthan40 = true, offer viagra, etc. take it easy for now


Esse foi outro ótimo post de:

This was another great post by:

xmauron3Hive account@xmauron3

alt

"O Futuro é incrível"

"The Future is Awesome"

Leave Mastering the Basics of Java 👨‍💻 [ENG/PT] to:

Written by

Certified Cybercitizen

Read more #coding posts


Best Posts From xmauron

We have not curated any of xmauron3's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From xmauron