How to make this parameter builder [closed]

-2
  • Bet
  • Properties:
    • User ID, String type, searchable. Identifier of the user who makes the bet.
    • Date of the bet, of LocalDateTime type, consultable. Record the moment in which make the bet.
    • Match, type MatchFutbol (This comes in another class but does not affect much), consultable. Match for which the bet is made. Introduction to type design 11
    • Amount bet, Float type, consultable. Indicates the amount the user has wagered in the game.
    • Goals local, Integer type, consultable. The number of goals that the bettor believes will mark the local team.
    • Goals visitor, of Integer type, consultable. The number of goals that the bettor believes will mark the visiting team.
    • Winner, Boolean type. Derivative It is true if the bet is winning. A bet is winner if the number of goals of the local team and the visiting team of the bet coincide with the number of goals of the local team and visitor of the match.
  • Builders:
    • C1: receives a parameter for each basic property of the type.
    • C2: receives the id of the user who makes the bet, the amount he bets, the goals he believes which will score the home team, the goals you think the visiting team will score, the date in which the game is played, the goals scored by the home team and the goals marked the visiting team. Create a bet whose date is the date on which the object in the program.
  • Representation as a string: The date of the bet, followed by the id of the user placing the bet, the local team, the visitor and the amount wagered. "09-21-16 04: 15: 00: 00, demoUser, Sporting GijónBarcelona,
asked by Abde 15.10.2016 в 20:57
source

1 answer

0
public class Apuesta {
    private String id;
    private LocalDateTime fecha;
    private PartidoFutbol partido;
    private float cantidadApostada;
    private int golesLocal;
    private int golesVisitante;
    private boolean ganadora;



    public Apuesta(String id, LocalDateTime fecha, PartidoFutbol partido, float cantidadApostada, int golesLocal,
            int golesVisitante, boolean ganadora) {
        super();
        this.id = id;
        this.fecha = fecha;
        this.partido = partido;
        this.cantidadApostada = cantidadApostada;
        this.golesLocal = golesLocal;
        this.golesVisitante = golesVisitante;
        this.ganadora = ganadora;
    }

    public Apuesta(String id, float cantidadApostada, int golesLocal, int golesVisitante) {
        super();
        this.id = id;
        this.cantidadApostada = cantidadApostada;
        this.golesLocal = golesLocal;
        this.golesVisitante = golesVisitante;

        this.fecha = fecha.now();
    }

    @Override
    public String toString() {
        return fecha + ", " + id + ", " + partido.getEquipoVisitante() 
                     + " - " partido.getEquipoLocal() + ": " 
                     + cantidadApostada + " €";
    }
}

I imagine that what brings you more difficulties may be to generate the current time in the second constructor this.fecha = fecha.now(); because the rest is more or less standard. Notice that I assume you have getEquipoVisitante() and getEquipoLocal() methods in the Match class.

    
answered by 17.10.2016 / 11:31
source