| JAVA-CREIAMO UN CODICE INSIEME |SIMULATORE BANCOMAT

avatar

image.png

Salve a tutti, ho deciso di intraprendere questo nuovo progetto perché lo ritengo molto interessante e perché penso possa servire a molti ragazzi che sono entrati da poco in questo mondo.

PREMESSE
il mio obbiettivo è quello di farvi imparare più cose possibili, per iniziare ci servirà un editor di testo, io personalmente consiglio Sublim text, ho sempre usato quello e devo dire che mi sono sempre trovato benissimo, lo potete scaricare da questo link:
https://download.sublimetext.com/Sublime%20Text%20Build%203211%20x64%20Setup.exe
Una volta scaricato possiamo procedere con la creazione del nostro codice.
Il file che andremo a realizzare oggi sarà una simulazione di un bancomant,ci permetterà di inserire dei soldi, di ritirarli e di visualizzare le ultime transazioni.
1 STEP
Aprite il nostro editor di testo, nel primo rigo andremo a inserire il nostro package, in poche parola dove si trova il nostro file, in modo tale che il promt lo possa leggere in seguito, nei righi successivi andremo a inserire tutte le nostre librerie che contengono le operazioni che possiamo eseguire, ovviamente senza librerie il nostro file non funzionerà.

image.png

2 STEP
dopo aver inserito tutte le librerie procediamo inserendo la classe, che non sarebbe altro che il nome del nostro file...seguito dall'INPUTSTREAMREADER E IL BUFFEREDREADER.

INPUTSTREAMREADER=creazione flusso da tastiera;
BUFFEREDREADER=tamponamento flusso da tastiera;

Dopo aver fatto ciò iniziamo con l'inserimento delle nostre variabili, il consiglio che vi do è quello di lasciare un pò di righi così da poterle aggiungere dopo essendo all'inizio molte poche le variabili da inserire.

3 STEP
Il consiglio che vi do io è quello di inserire all'inizio del nostro file una parte grafica, che faccia piacere agli occhi,sia per far capire di cosa si tratta il nostro file, sia per non rendere tutto il più pesante.
quindi procediamo inserendo una scritta creata in modo ASCII all'interno dei system out.

SYSTEM.OUT.PRINTLN= scritta stampata a schermo.

image.png

4 STEP

Adesso arriva la parte più complicata, iniziamo a implementare la parte logica.
Come detto prima questo codice ci permetterà di effettuare 3 scelte:
1)depositare
2)prelevare
3)visualizzare gli ultimi movimenti
quindi realizzeremo un menù di scelta con queste 3 scelte, questo sarà il risultato.

image.png
per acquisire la scelta del menù da effettuare creiamo 2 variabili, una di tipo int e una di tipo string per effettuare la conversione, a cui accoppieremo la scelta dell'udente attraverso "TASTIERA.READLINE()",quindi andiamo fino a sopra dove abbiamo lasciato i righi vuoi e inseriamo le 2 variabili, una cosa molto importante da sapere è che la conversione è obbligatoria, poiché il dato che noi andiamo ad acquisire di base è stringa, ma essendo inutile a noi, lo andiamo a convertire in intero tramite in converter.

5 STEP

una volta creato il menù e aver associato le 3 scelte a un numero, procediamo con la creazione dei vari casi.
Nel caso 1 ci chiede di depositare dei soldi, quindi per come fatto con l'acquisizione della scelta creiamo 2 variabili, una per tener conto di tutto il nostro saldo, una per l'acquisizione del dato che assoceremo alla tastiera.
Ci serviranno due array, che non sono altro che dei contenitori, un array lo utilizzeremo per tener traccia dei nostri depositi, entro un altro per tener traccia dei nostri prelievi, questi due array ci serviranno per i prossimi 2 casi, MOLTO IMPORTANTE è di aggiornare l'array ogni qual volta eseguiamo un operazione.
image.png

image.png

6 STEP

una volta finito il primo caso andiamo ad eseguire il secondo, che sono molto simili fra di loro, quindi andiamo a creare le 2 variabili del depositi, e.. invece di andare a sommare i soldi depositati con quelli che avevamo prima, andiamo a sottrarli grazie alla variabile creata prima per tener conto del nostro saldo.
Dopo di che andiamo ad aggiornare il nostro contatore ovvero il nostro array del prelievo e facciamo stampare a schermo sia il nostro saldo, sia i nostri movimenti.
Come ultimo step che riguardano il 3 e 4 caso, non ci resto altro che fare un for,per far cicalare tutto il nostro array e farlo stampare.
Nel terzo caso facciamo ciclare l'array dei nostri depositi, mentre nel quarto caso andiamo a far ciclare l'array dei nostri prelievi.

image.png

7 STEP

Come ultimissimo step, oserei dire anche quello più divertente, ci dirigiamo nel prompt,e dopo aver controllato se il nostro file non presentava errori, andiamo a effettuare i nostri controlli se il file funziona in modo corretto.

image.png

image.png

image.png




image.png

Hello everyone, I decided to undertake this new project because I think it is very interesting and because I think it can be of use to many guys who have recently entered this world.

PREMISES
my goal is to make you learn as much as possible, to start we will need a text editor, I personally recommend Sublim text, I have always used that one and I must say that I have always found myself very well, you can download it from this link:
https://download.sublimetext.com/Sublime%20Text%20Build%203211%20x64%20Setup.exe
Once downloaded we can proceed with the creation of our code.
The file we are going to make today will be a simulation of a bancomant,it will allow us to insert money, withdraw it and display the last transactions.
1 STEP
Open our text editor, in the first line we are going to enter our package, in a nutshell where our file is, so that promt can read it later, in the next lines we are going to enter all our libraries that contain the operations we can perform, obviously without libraries our file will not work.

image.png

2 STEP
after entering all the libraries we proceed by entering the class, which would be nothing more than the name of our file...followed by the INPUTSTREAMREADER AND THE BUFFEREDREADER.

INPUTSTREAMREADER=creating flow from keyboard;
BUFFEREDREADER=printing flow from keyboard;

After doing that we start with the insertion of our variables, the advice I give you is to leave a few lines so you can add them later being at the beginning very few variables to be inserted.

3 STEP
The advice I give you is to insert at the beginning of our file a graphic part, that pleases the eyes,both to make it clear what our file is about and not to make everything the heaviest.
so let's proceed by inserting a script created in ASCII mode inside systems out.

SYSTEM.OUT.PRINTLN= script printed on the screen.

image.png

4 STEP

Now comes the tricky part, let's start implementing the logic part.
As mentioned before this code will allow us to make 3 choices:
1)deposit
2)withdraw
3)view the last movements
so we will implement a choice menu with these 3 choices, this will be the result.

image.png
to acquire the choice of the menu to make we create 2 variables, one of type int and one of type string to make the conversion, to which we will couple the choice of the hearer through "KEY.READLINE()",then we go up to above where we left the lines want and we insert the 2 variables, a very important thing to know is that the conversion is mandatory, since the data that we are going to acquire basic is string, but being useless to us, we are going to convert it to integer through in converter.

5 STEP

once we have created the menu and associated the 3 choices with a number, we proceed to create the various cases.
Case 1 asks us to deposit money, so as done with the choice capture we create 2 variables, one to account for our entire balance, one to capture the data we will associate with the keyboard.
We will need two arrays, which are nothing but containers, one array we will use to keep track of our deposits, within another to keep track of our withdrawals, these two arrays will serve us for the next 2 cases, VERY IMPORTANT is to update the array whenever we perform an operation.
image.png

image.png

6 STEP

once we finish the first case we go to execute the second one, which are very similar to each other, so we go to create the 2 variables of the deposits, and.. instead of going to add up the deposited money with the money we had before, we go to subtract it thanks to the variable created before to account for our balance.
After that we go to update our counter that is our withdrawal array and have both our balance and our movements printed on the screen.
As a last step concerning the 3rd and 4th cases, all we do is to do a for,to cycle our whole array and have it printed.
In the third case we cycle the array of our deposits, while in the fourth case we go to cycle the array of our withdrawals.

image.png

7 STEP

As the very last step, dare I say also the most fun one, we head into the prompt,and after checking if our file had no errors, we go to do our checks if the file is working properly.
image.png

image.png

image.png



0
0
0.000
7 comments
avatar

!discovery 30

Bellissimo post , presto ti raggiungerò anche io!

0
0
0.000
avatar

ahahaha ti aspetto, se ti serve una mano non esitare a contattarmi, lo ritengo un'argomento molto importante ma soprattutto divertente che è una cosa ancora più importante,grazie mille per il supporto.

0
0
0.000
avatar

Mi hai riportato indietro nel tempo tra i banchi dell'università :)
Bel post anche se a me servirebbe il codice per prelevare senza carta dal bancomat vicino casa mia :) !LOL
Scherzi a parte Bravo!
!PGM
!PIZZA

0
0
0.000
avatar

Sent 0.1 PGM - 0.1 LVL- 1 STARBITS - 0.05 DEC - 15 SBT - 0.1 THG - tokens to @libertycrypto27

remaining commands 13

BUY AND STAKE THE PGM TO SEND A LOT OF TOKENS!

The tokens that the command sends are: 0.1 PGM-0.1 LVL-0.1 THGAMING-0.05 DEC-15 SBT-1 STARBITS-[0.00000001 BTC (SWAP.BTC) only if you have 2500 PGM in stake or more ]

5000 PGM IN STAKE = 2x rewards!

image.png
Discord image.png

Support the curation account @ pgm-curator with a delegation 10 HP - 50 HP - 100 HP - 500 HP - 1000 HP

Get potential votes from @ pgm-curator by paying in PGM, here is a guide

I'm a bot, if you want a hand ask @ zottone444


0
0
0.000
avatar

ahahahaa va bene!! fra poco arriva anche quello👀

0
0
0.000