Package model

Class Statistics

java.lang.Object
model.Statistics

public class Statistics extends Object
The Statistics class represents a set of statistics for a blackjack game. Statistics are stored in a CSV file with the following format:
  • Column 1: number of wins
  • Column 2: number of losses
  • Column 3: number of pushes(ties)

The file is named statistics.csv and is stored in the db/ directory.

Author:
Michael Neuper michael@michaelneuper.com
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Statistics object with all statistics initialized to 0.
    Statistics(int wins, int losses, int pushes)
    Constructs a new Player object with the given statistics.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the number of losses.
    int
    Gets the number of pushes (ties).
    int
    Gets the number of wins.
    void
    Increments the number of losses by 1 and saves the new statistics to the CSV file.
    void
    Increments the number of pushes (ties) by 1 and saves the new statistics to the CSV file.
    void
    Increments the number of wins by 1 and saves the new statistics to the CSV file.
    static Statistics
    This static method loads the statistics from the CSV_FILE file located at the path defined by the CSV_FILE constant in the Statistics class.
    void
    setLosses(int losses)
    Sets the number of losses.
    void
    setPushes(int pushes)
    Sets the number of pushes (ties).
    void
    setWins(int wins)
    Sets the number of wins.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Statistics

      public Statistics()
      Constructs a new Statistics object with all statistics initialized to 0.
    • Statistics

      public Statistics(int wins, int losses, int pushes)
      Constructs a new Player object with the given statistics.
      Parameters:
      wins - the number of wins
      losses - the number of losses
      pushes - the number of pushes (ties)
  • Method Details

    • getWins

      public int getWins()
      Gets the number of wins.
      Returns:
      the number of wins
    • getLosses

      public int getLosses()
      Gets the number of losses.
      Returns:
      the number of losses
    • getPushes

      public int getPushes()
      Gets the number of pushes (ties).
      Returns:
      the number of pushes
    • setWins

      public void setWins(int wins)
      Sets the number of wins.
      Parameters:
      wins - the new number of wins
    • setLosses

      public void setLosses(int losses)
      Sets the number of losses.
      Parameters:
      losses - the new number of losses
    • setPushes

      public void setPushes(int pushes)
      Sets the number of pushes (ties).
      Parameters:
      pushes - the new number of pushes
    • incrementWins

      public void incrementWins()
      Increments the number of wins by 1 and saves the new statistics to the CSV file.
    • incrementLosses

      public void incrementLosses()
      Increments the number of losses by 1 and saves the new statistics to the CSV file.
    • incrementPushes

      public void incrementPushes()
      Increments the number of pushes (ties) by 1 and saves the new statistics to the CSV file.
    • load

      public static Statistics load() throws IOException

      This static method loads the statistics from the CSV_FILE file located at the path defined by the CSV_FILE constant in the Statistics class. The method uses a CSVReader object to read the data from the file.

      If the CSV_FILE file does not have the expected headers, an IOException is thrown. The method returns a Statistics object with the values read from the CSV_FILE file.

      If an IOException occurs during the file reading process, it is caught and printed to the standard error stream. If a CsvValidationException is thrown during the file reading process, it is handled internally and an empty Statistics object is returned.

      Returns:
      a Statistics object with the values read from the CSV_FILE file, or an empty Statistics object if there was a problem with the CSV file format
      Throws:
      IOException - if there is a problem with the file reading process or the CSV file headers are invalid