SET=settare un'oggetto
GET=richiamarci l'oggetto
All'interno del nostro oggetto inseriremo gli attributi che ci serviranno per differenziarlo da altri oggetti,in questo caso nome del prodotto, ditta del prodotto e prezzo del prodotto...l'unica variabile che ho fatto è stato mettere float al prezzo di int,dopo vi spiegherò le differenze...
Inserite questi 2 righi,che serviranno per l'acquisizione da tastiera di un certo dato:
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader tastiera = new BufferedReader(input);
adesso arriva la parte più difficile del nostro file, l'utilizzo dell'oggetto creato in precedenza, per utilizzare l'oggetto iniziamo digitando la classe di appartenenza, subito dopo il nome dell'oggetto seguito da =new di nuovo il nome della class e due parentesi aperte e chiuse, il risultato dovrò essere così:
Classe_6 prodotto1 = new Classe_6();
in questo modo abbiamo completato il nostro oggetto, per settarlo basterà digitare il nome del nostro oggetto con .set(quello che volete),nel nostro caso potremmo settare nome, ditta e prezzo, completiamo il tutto e avremo un risultato del genere.
in questo caso per contenere l'oggetto creato abbiamo proceduto con la creazione di un array...
Cos'è un array?
un array è un contenitore di dati strutturato in posizioni, ogni posizione contiene un dato, abbiamo due tipi di array, l'array classico nella quale bisogna inserire anche la posizione del array, e un array dinamico nella quale ogni volta che andremo a inserire un dato, ci calcolerà automaticamente la posizione successiva.
1.AGGIUNGI PRODOTTO
2.RIMUOVI PRODOTTO
3.MODIFICA UN PRODOTTO
4.VEDI PRODOTTI
creato il menù di scelta il risultato sarà così:
Dopo aver creato il nostro menù di scelta procediamo con la costruzione del primo caso, ovvero L'AGGIUNTA DI UN PRODTTO,partiamo subito inserendo le nuove variabili nella quali assoceremo la tastiera per prende un dato in input dall'utente, create le 3 variabili, digitiamo la funzione che ci permette di associare alla variabile il valore preso da tastiera(non dimentichiamoci il try e il catch, è fondamentale per la lettura del nostro dato, una volta fatto tutto ciò creiamo un nuovo oggetto seguendo i passaggi di prima,ma cambiando il nome dell'oggetto, se prima il nome era prodotto1,questa volta lo chiameremo prodotto2,e andiamo a inserire nei vari set le variabili create...come ultima cosa andiamo a inserire l'oggetto in una nuova posizione dell'array, il risultato sarà qualcosa del genere:
listaProdotti.remove(i) i=posizione dell array da elminare.
SET=set an object
GET=retrieve the object
Inside our object we will insert attributes that we will need to differentiate it from other objects,in this case product name,product company and product price...the only variable I did was put float to int price,later I will explain the differences...
Insert these 2 lines,which will be used for keyboard acquisition of some data:
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader keyboard = new BufferedReader(input);
now comes the most difficult part of our file, the use of the object created earlier, to use the object we start by typing the class it belongs to, immediately after the name of the object followed by =new again the name of the class and two open and closed parentheses, the result should look like this:
Class_6 product1 = new Class_6();
in this way we have completed our object, to set it we will just type the name of our object with .set(whatever you want),in our case we could set name, company and price, we complete it and we will have a result like this.
In this case to contain the created object we proceeded to create an array...
What is an array?
an array is a container of data structured in positions, each position contains a piece of data, we have two types of arrays, the classic array in which we must also enter the position of the array, and a dynamic array in which every time we go to enter a piece of data, it will automatically calculate us the next position.
1.ADD PRODUCT
2.REMOVE PRODUCT
3.EDIT A PRODUCT
4.SEE PRODUCTS
created the choice menu the result will look like this:
After having created our choice menu we proceed with the construction of the first case, that is THE ADDING OF A PRODUCT,we start right away by inserting the new variables in which we will associate the keyboard to take an input data from the user, created the 3 variables, we type the function that allows us to associate to the variable the value taken from the keyboard(let's not forget the try and catch, it is essential for reading our data, once all this is done we create a new object following the steps from before,but changing the name of the object,if before the name was product1,this time we will call it product2,and we go to insert in the various sets the variables created. ..as a last thing we are going to insert the object in a new array position,the result will be something like this:
listProducts.remove(i) i=position of the array to be elminated.
Translated with www.DeepL.com/Translator (free version)