# Translate Java code into Processing

**URL:** <https://discourse.processing.org/t/translate-java-code-into-processing/5807>\
**Category:** Coding Questions\
**Created:** [November 21, 2018, 9:28pm UTC](https://discourse.processing.org/t/translate-java-code-into-processing/5807 "2018-11-21T21:28:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkSt0ne](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DarkSt0ne](https://discourse.processing.org/u/DarkSt0ne)\
**Post date:** [November 21, 2018, 9:28pm UTC](https://discourse.processing.org/t/translate-java-code-into-processing/5807/1 "2018-11-21T21:28:52Z")

</div>

Hello there, I was wondering if any of you could translate the following java code into processing:

`import` `java.util.Scanner;`

`public` `class` `AtmMachine{`

`` `private` `static` `Scanner in;`

`` `private` `static` `float` `balance =` `0` `;` `// initial balance to 0 for everyone`

`` `private` `static` `int` `anotherTransaction;`

`` `public` `static` `void` `main(String args[]){`

`` `in =` `new` `Scanner(System.in);`

`` `// call our transaction method here`

`` `transaction();`

`` `}`

`` `private` `static` `void` `transaction(){`

`` `// here is where most of the work is`

`` `int` `choice;`

`` `System.out.println(` `"Please select an option"` `);`

`` `System.out.println(` `"1. Withdraw"` `);`

`` `System.out.println(` `"2. Deposit"` `);`

`` `System.out.println(` `"3. Balance"` `);`

`` `choice = in.nextInt();`

`` `switch` `(choice){`

`` `case` `1` `:`

`` `float` `amount;`

`` `System.out.println(` `"Please enter amount to withdraw: "` `);`

`` `amount = in.nextFloat();`

`` `if` `(amount > balance || amount ==` `0` `){`

`` `System.out.println(` `"You have insufficient funds\n\n"` `);`

`` `anotherTransaction();` `// ask if they want another transaction`

`` `}` `else` `{`

`` `// they have some cash`

`` `// update balance`

`` `balance = balance - amount;`

`` `System.out.println(` `"You have withdrawn "` `+amount+` `" and your new balance is "` `+balance+` `"\n"` `);`

`` `anotherTransaction();`

`` `}`

`` `break` `;`

`` `case` `2` `:`

`` `// option number 2 is depositing`

`` `float` `deposit;`

`` `System.out.println(` `"Please enter amount you would wish to deposit: "` `);`

`` `deposit = in.nextFloat();`

`` `// update balance`

`` `balance = deposit + balance;`

`` `System.out.println(` `"You have deposited "` `+deposit+` `" new balance is "` `+balance+` `"\n"` `);`

`` `anotherTransaction();`

`` `break` `;`

`` `case` `3` `:`

`` `// this option is to check balance`

`` `System.out.println(` `"Your balance is "` `+balance+` `"\n"` `);`

`` `anotherTransaction();`

`` `break` `;`

`` `default` `:`

`` `System.out.println(` `"Invalid option:\n\n"` `);`

`` `anotherTransaction();`

`` `break` `;`

`` `}`

`` `}`

`` `private` `static` `void` `anotherTransaction(){`

`` `System.out.println(` `"Do you want another transaction?\n\nPress 1 for another transaction\n2 To exit"` `);`

`` `anotherTransaction = in.nextInt();`

`` `if` `(anotherTransaction ==` `1` `){`

`` `transaction();` `// call transaction method`

`` `}` `else` `if` `(anotherTransaction ==` `2` `){`

`` `System.out.println(` `"Thanks for choosing us. Good Bye!"` `);`

`` `}` `else` `{`

`` `System.out.println(` `"Invalid choice\n\n"` `);`

`` `anotherTransaction();`

`` `}`

`` `}`

`}`

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 21, 2018, 10:31pm UTC](https://discourse.processing.org/t/translate-java-code-into-processing/5807/2 "2018-11-21T22:31:51Z")

</div>

Oh geez. It’s another f%^&ing ATM machine. 🍋🍋🍋

You are the third person here today trying to cheat their way through properly developing an ATM machine.

Did no one tell you to write your own code? YOU SHOULD WRITE YOUR OWN CODE.

Start with something simple. Can you get a blank sketch working? Can you then draw a rectangle? Can you thenm put some text on it? Now can you detect a mouse press? How about checking if the mouse press was over the rectangle?

That’s a button. Now make several of those so you can enter a PIN number. Now, what other logic do you need to have an ATM machine? It probably needs some notion of being in different states, so your sketch probably needs a state variant and then to draw different information based on the state.

Then you need a balance variable that can be adjusted based on how much is deposited or withdrawn.
