-1
Guys I’m trying to create a system of numbers mega sena. Basically I have to have a client(id) that will generate 6 random numbers.
public class Cliente implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private String email;
private int numeros;
I created the client class that has name, email and numbers.
public class Random1 {
public static void main(String[] args) {
Random gerador = new Random();
for (int i = 0; i < 6; i++) {
System.out.println(gerador.nextInt(59));
}
And I created the Random class, the doubt and the following, as I do for each game created of 6 numbers, get attached to an ID in the client table?
Random1
is a bad name in terms of class modeling, says nothing about what the class is or does. 2) The way of generating is wrong, because it is letting repeat numbers. 3) In terms of object-relational mapping it makes no sense to have a fieldint numeros
, would be an array or list of numbers with fixed size at 6, and indeed even this is wrong because a customer could make several bets so should have the concept ofAposta
each with six numbers. Finally, by BD normalization it is not advisable to keep the six numbers in a single column of the table.– Piovezan
Anyway, object orientation is one thing, relational database another, orm is the idea of relating these two worlds (which in your case fatally will involve more than one table and foreign keys) and personally I think it should be studied after you already have a good idea of the first two. But each one is each one. Also one studied on how to raise requirements.
– Piovezan
Your biggest doubt is generating the 6 random numbers or is saving them in the database?
– Victor Stafusa
@Piovezan Thanks for the tips friend, as I’m still graduating, I lack enough knowledge even.
– Breno Rusciolelli
@Victorstafuses that friend, I can generate the numbers with the Andom class, but I can’t link the numbers generated to a client class understand?
– Breno Rusciolelli