id
stringlengths
36
36
text
stringlengths
1
1.25M
fcf031b3-2d69-40d9-95be-95ee39a1fe3f
public Hand() { cards = new ArrayList<Card>(); }
01794bb9-57a9-494d-a6c1-5b9e637c4d0f
public void addCard(Card card) { cards.add(card); }
5a2e3de6-422a-4843-813f-310073348be7
public void clear() { cards.clear(); }
2ef21e31-b0d8-4cca-8b40-1961d2fff756
public int getTotalHandValue() { log.debug("Calculating hand value..."); int totalWithAcesLow = 0; int numberOfAces = 0; // Sum up value of all cards. Aces are 1 by default. Allow one ace to be // 11 if it will not cause bust. for (Card card : cards) { int cardValue = card.getCardValue(true); tota...
8ffcd689-87e0-46c9-8098-83b72f225d9b
public String toString() { StringBuilder sb = new StringBuilder(); for (Card card : cards) { sb.append(card + " "); } String hand = sb.toString(); log.debug("Printing hand: " + hand); return hand; }
2973fea1-ec33-4ae5-870c-3db526fe5608
public String toStringShowingTopCardOnly() { StringBuilder sb = new StringBuilder(); boolean firstCard = true; for (Card card : cards) { if (firstCard) { sb.append(card + " "); // First card is face-up firstCard = false; } else { sb.append("X "); // Face-down card } } String han...
2ecdc868-2899-483e-86d2-434052dfcebc
public Card(int card) { this.card = card; }
fe9728e0-b210-458c-992b-d788c30cdf70
public int getCardValue(boolean acesLow) { if (card >= FIRST_FACE_CARD_ID) return FACE_CARD_VALUE; // All face cards are worth 10 if (card == ACE_ID) // Ace has value of 1 or 11 if (acesLow) { log.debug("Using low ace"); return LOW_ACE_VALUE; } else { log.debug("Using high ace"); re...
f403caa8-19d3-4638-97bc-cce27066ff17
public String toString() { switch (card) { case ACE_ID: return "A"; case JACK_ID: return "J"; case QUEEN_ID: return "Q"; case KING_ID: return "K"; default: return Integer.toString(card); } }
ad865ec1-4833-4452-90a5-2e02c7a6df6c
public abstract void takeBet(HumanPlayer currentPlayer) throws GameQuitException;
34e4ef1f-d809-4fbe-b092-21f722cf9955
public abstract String getUserInput();
be705da7-3ca1-494a-89e1-276ae072a195
public abstract void playerStatus(Player currentPlayer);
942beaac-a31c-471c-9e35-ad420c997e04
public abstract void playerStatusWithCoveredCards(Player currentPlayer);
fb0b57e7-931c-4e59-86d7-e6a070f52309
public abstract Action getUserActionChoice();
5b3c2a29-c406-464d-80ad-2dad40b54681
public abstract void playerWinsRound();
cb44b0da-5d2b-4c97-af81-ede71c71e0b1
public abstract void dealerWinsRound();
fc7399f6-1e36-4aec-a4dd-db3818f5e26c
public abstract void roundIsPush();
a17dc3a6-15b9-47f3-9db1-ff6776297c0b
public abstract void playerActionTaken(Player player, Action action);
c369b5fe-04e7-43b9-bb27-fac99db347ee
public abstract void endRound();
c97541d2-7a36-4fb9-bc7b-ac6ddc74439e
public abstract void quitMessage();
4df1f0ad-8185-432d-bb72-8fdd6b99954f
public abstract void introMsg();
7eeac935-c6d7-4cb3-8a6c-c2f63c094cb5
public abstract void exitMsg();
9fbed506-465f-46c3-b406-a14b508e61cb
public ConsoleUI() { this(System.in, System.out); }
15a6f103-fcd1-490d-83e1-5f02c790cbb5
public ConsoleUI(InputStream in, PrintStream out) { this.in = in; this.out = out; }
2bc317c3-648e-4f0c-b477-323245bf7ca1
@Override public void takeBet(HumanPlayer currentPlayer) throws GameQuitException { log.info("Taking bet from " + currentPlayer.getName()); int bet = HumanPlayer.INVALID_BET_FLAG; while (bet < Game.MIN_BET || bet > Game.MAX_BET) { // If we made it in the loop without bet of -1, we had an invalid // bet ...
f70b32d4-25fd-42c1-a05e-2f7a414fd8f4
@Override public Action getUserActionChoice() { log.info("Asking user to choose action to take"); int choice = INITIAL_ACTION_FLAG; while (choice < MIN_ACTION_KEY || choice > MAX_ACTION_KEY) { // If we made it in the loop with a choice of something other than // INITIAL_ACTION_FLAG, the user made an inv...
afd887e0-288a-4d0a-b676-3af569db821b
@Override public String getUserInput() { InputStreamReader input = new InputStreamReader(in); BufferedReader reader = new BufferedReader(input); String inputString = ""; try { inputString = reader.readLine(); } catch (IOException e) { log.error("Error getting user input", e); } return inputSt...
5d1d6d63-d800-4fde-949a-8dbe311006c0
@Override public void playerStatus(Player currentPlayer) { out.println(currentPlayer); }
cdf25745-978e-4da0-b8ac-a6f059605ec9
@Override public void playerStatusWithCoveredCards(Player currentPlayer) { out.println(currentPlayer.toStringShowingTopCardOnly()); }
bd04744e-50b0-4e89-bf6c-9a0bd7f31ab6
@Override public void playerWinsRound() { out.println("Player wins the round."); }
3c861cb2-4a08-499d-bf19-54d572812774
@Override public void dealerWinsRound() { out.println("Dealer wins the round."); }
678cdbc3-c6bd-4de7-a27b-2fe64c07d26d
@Override public void roundIsPush() { out.println("This round is a push."); }
f7efd253-b3d7-4eb6-b22c-91191bb0d1b9
@Override public void playerActionTaken(Player player, Action action) { out.println(player.getName() + " " + action.toString() + "s."); }
cc1cfdf0-91e3-446b-92df-afacc7d80090
@Override public void endRound() { out.println("----------------\n"); }
d692f1fe-bcd7-4f4e-89c9-39508d73c2ae
@Override public void quitMessage() { out.println("Leaving table to get a drink."); }
8f19c8a4-1b37-44a8-bce8-4083d26b9a9e
@Override public void introMsg() { out.println("Welcome to the BlackJack table."); out.println("Please have a seat."); }
196ea196-3038-47a5-a1d8-b21627698c29
@Override public void exitMsg() { out.println("Thanks for playing BlackJack."); out.println("Come again soon!"); }
61cd5caf-0e66-4129-bbc8-da0bab4e0efd
public AtcConfigServlet(PluginSettingsFactory settingsFactory, TemplateRenderer templateRenderer) { this.settingsFactory = settingsFactory; this.templateRenderer = templateRenderer; }
40d722e6-7f95-4280-8dc4-9336c7cbb7e6
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PluginSettings settings = settingsFactory.createGlobalSettings(); HashMap<String, Object> context = new HashMap<String, Object>(); context.put...
3c375357-047e-4e58-bbb0-4dd9581aba56
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PluginSettings settings = settingsFactory.createGlobalSettings(); settings.put("atc.phprojekt.dsn", request.getParameter("dsn")); doGet(request, res...
a9859120-5e50-4fef-a1ad-dc100d227eb0
public AtcTimeProjCreateServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory) { super(applicationProperties, settingsFactory); }
215868ed-464a-4825-bc5a-517b7624a3f9
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String project = request.getParameter("project"); String date = request.getParameter("date"); String hours = request.getParameter("hours"); ...
d7375bd5-846e-4c6b-9efb-c9ec7a6053d4
public AtcTimeCardModifyServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory) { super(applicationProperties, settingsFactory); }
fdce7d9d-59bc-4583-9263-c5b8cbdf3556
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if ("delete".equals(action)) { this.deleteEntry(request); } else if ("update".equals(acti...
93838720-1f47-44b2-a7d0-17d698ba76fd
protected void deleteEntry(HttpServletRequest request) { String id = request.getParameter("id"); try { this.getSqlConn() .createStatement() .executeUpdate("DELETE FROM phpr_timecard" + " WHERE ID=" + id); } c...
d319b993-0238-4775-b460-9dd5cfa3c19f
protected void updateEntry(HttpServletRequest request) { String id = request.getParameter("id"); String begin = request.getParameter("begin"); String end = request.getParameter("end"); try { this.getSqlConn() .createStatement() .execu...
ec789c8d-f733-4cbf-b303-f9c0e87316d2
public AtcTimeCardCreateServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory) { super(applicationProperties, settingsFactory); }
12705f56-cda7-42a4-98b2-568b79054ce9
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String date = request.getParameter("date"); String begin = request.getParameter("begin"); String end = request.getParameter("end"); try { ...
0f09643b-e00b-44e5-a7f7-3eda11ccc40a
public AtcTimeProjModifyServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory) { super(applicationProperties, settingsFactory); }
850ff765-7e0d-4bf5-a2dc-e8eaba307ac5
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if ("delete".equals(action)) { this.deleteEntry(request); } else if ("update".equals(acti...
de64b028-2406-421d-9951-420c94382e6b
protected void deleteEntry(HttpServletRequest request) { String id = request.getParameter("id"); try { this.getSqlConn() .createStatement() .executeUpdate("DELETE FROM phpr_timeproj" + " WHERE ID=" + id); } c...
f0601e65-934d-4bfd-984b-40efea2dfe46
protected void updateEntry(HttpServletRequest request) { String id = request.getParameter("id"); String hours = request.getParameter("hours"); String minutes = request.getParameter("minutes"); String note = request.getParameter("note"); try { this.getSq...
ed0f537c-5768-4380-b36d-899d71d28772
public AtcServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory) { this.applicationProperties = applicationProperties; this.settingsFactory = settingsFactory; }
7b6df2c1-b2f3-4215-a4f7-8a5f66aa10c7
@Override public void init(ServletConfig config) throws ServletException { this.atcContext = config.getServletContext().getInitParameter("atimecard-context"); }
86211b5d-77d5-4a59-aa8f-653e9833e5b3
protected String getAtcContext() { return this.atcContext; }
a616c398-560c-448c-93b3-34cbdd043aac
protected String getBaseUrl() { return this.applicationProperties.getBaseUrl(); }
2b5fa342-4823-4b1d-aa90-1aea4530e26c
protected Connection getSqlConn() { if (null != this.sqlConn) { return this.sqlConn; } try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) { } try { PluginSettings settings = settingsFactory.createGlobalSett...
03381668-99bf-456e-9c78-e32dd684b950
public AtcMainServlet(ApplicationProperties applicationProperties, PluginSettingsFactory settingsFactory, TemplateRenderer templateRenderer, WebResourceManager webResourceManager) { super(applicationProperties, settingsFactory); ...
ede20a2d-888b-4ffb-b019-8d5dca0eea9b
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HashMap<String, Object> context = new HashMap<String, Object>(); Vector<HashMap<String, Object>> timecard = this.getTimeCardEntries(); Vector<...
e9b551a0-fc3b-4d2c-800a-a6ed3b692667
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.curDate = request.getParameter("date"); doGet(request, response); }
80cbd37e-6f85-4cec-9f56-877f8fb09dc9
private HashMap<String, Integer> calculateTimeCardTotal(Vector<HashMap<String, Object>> timecard) { HashMap<String, Integer> total = new HashMap<String, Integer>(); Integer hours = 0; Integer minutes = 0; if (!timecard.isEmpty()) { Integer clocked = 0; ...
51af4cd7-3d09-4062-8d44-0d33c5d1eac7
private HashMap<String, Integer> calculateTimeLeftOver(Vector<HashMap<String, Object>> timecard, Vector<HashMap<String, Object>> timeproj) { HashMap<String, Integer> total = new HashMap<String, Integer>(); Integer clockCard = 0; Integer clockPro...
9f1a12e0-0ac4-47f0-8095-26e46aa23e52
private String getCurrentDate() { if (null != this.curDate && !this.curDate.isEmpty()) { return this.curDate; } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); this.curDate = dateFormat.format(date); retur...
9c62d9f9-f814-49a7-a752-494cd0d23fea
private Vector<HashMap<String, Object>> getProjects() { Vector<HashMap<String, Object>> projects = new Vector<HashMap<String, Object>>(); Statement stmt = null; ResultSet rs = null; try { stmt = this.getSqlConn().crea...
4e593c08-d674-46e1-9ca1-f176fb7f8a8c
private Vector<HashMap<String, Object>> getTimeCardEntries() { Vector<HashMap<String, Object>> timecard = new Vector<HashMap<String, Object>>(); Statement stmt = null; ResultSet rs = null; try { stmt = this.getSqlConn...
9b90a339-6444-4a7f-ae73-55b7582ccd6c
private Vector<HashMap<String, Object>> getTimeProjectEntries() { Vector<HashMap<String, Object>> timeproj = new Vector<HashMap<String, Object>>(); Statement stmt = null; ResultSet rs = null; try { stmt = this.getSqlC...
89360f4a-695f-4adf-9949-3ba4622b4a3c
public void testGaussJacobi() { assertArrayEquals(resposta1, ja.executar(matriz1, x01, 0.05)); }
7d5c19f3-d1b3-4d2b-ad76-a9b6a270372d
public void testGaussSeidel() { assertArrayEquals(resposta2, se.executar(matriz2, x02, 0.05)); }
45842829-5536-44e5-b48b-598e79654b3f
private void assertArrayEquals(double[] d, double[] d0) { for(int i=0;i<d.length;i++) { assertTrue(d[i]-d0[i]==0); } }
3d3ab703-5dac-44f6-86b2-45f4fc0fb8fe
public void testGauss7() { assertArrayEquals(resposta7,gauss.executar(m7)); }
2897c92a-5d01-428d-938d-2c57e5bcff94
public void testGauss2() { assertArrayEquals(resposta2,gauss.executar(m2)); }
a091aa8c-3fb1-423d-87bb-6736132d1ced
public void testGauss3() { assertArrayEquals(resposta3,gauss.executar(m3)); }
1d8a332f-2a6f-4dd9-a9de-cf346c661036
public void testGauss4() { assertArrayEquals(resposta4,gauss.executar(m4)); }
91a1d04e-3890-4e07-b1b5-4fc6f8152470
public void testVerificador1() { assertEquals("Determinado",m1.verificador()); }
0c6be7c2-6662-48de-81e0-ba87f275cbde
public void testVerificador2() { assertEquals("Determinado",m2.verificador()); }
5cfe1eb9-9a24-4c1f-bc67-130a9a1f5d65
public void testVerificador3() { assertEquals("Determinado",m3.verificador()); }
8c131c83-dcf1-44f1-a388-e9f5812b4980
public void testVerificador4() { assertEquals("Determinado",m4.verificador()); }
b7bfe94f-a058-4280-a9e1-2ab3873f4cdf
public void testVerificador5() { assertEquals("Indeterminado",m5.verificador()); }
edb68b8a-4d7a-44d2-8119-6b9559eb0f17
public void testVerificador6() { assertEquals("Incompativel",m6.verificador()); }
5aea742d-b74f-43eb-8569-9abd8f424d2c
private void assertArrayEquals(double[] d, double[] d0) { for(int i=0;i<d.length;i++) { assertTrue(d[i]-d0[i]==0); } }
42cbfeea-fd15-44a7-a86e-c6d75b2150af
public GaussJacobi () { }
c7fcbb8d-532c-44a8-8f9c-5129405b718f
public double[] executar (Matriz m, double[] vetor, double erro) { this.matriz = new Matriz(m.linhas, m.colunas); this.matriz.setMatrizAmpliada(m.matrizAmpliada); this.resultado = new double[m.linhas]; if (!this.verificarConvergencia()) { for(int i = 0; i < this.matriz.linhas; i++) { this.resultado[i]...
703a72b0-bc3e-4fe8-8059-237c31e1a72d
protected void calcular(double[] vetor) { double[] anterior = new double[this.matriz.linhas]; System.arraycopy(vetor, 0, this.resultado, 0, vetor.length); do { System.arraycopy(this.resultado, 0, anterior, 0, this.resultado.length); for(int i = 0; i < this.matriz.linhas; i++) { this.resultado[i...
74b677e2-e09c-4557-972b-ec59ad2d8f10
public double[] getResultado() { return this.resultado; }
6e856b3e-7db4-49d6-b019-099007b4e773
public int getIteracoes() { return this.iteracoes; }
7815a748-c5ac-4f11-a84d-c9932aa8aa07
public double getErro() { return this.erro; }
51a47658-a090-4a7c-a6de-505cce7aca46
protected void printaResultados(String str) { NumberFormat formatacaoSaida = new DecimalFormat("0.00000000"); System.out.println("\n"+str); for(int i = 0; i < this.resultado.length; i++) { System.out.println("x"+i+" = "+formatacaoSaida.format(this.resultado[i])); } System.out.println("Número de it...
75fab6d6-a2b9-4243-9720-9ef70599f3df
protected boolean verificarConvergencia() { boolean converge = false; for (int i = 0; i < this.matriz.linhas && !converge; i++) { for (int j = i + 1; j < this.matriz.linhas && !converge; j++) { converge = criterioLinhas(); if(!converge) { trocarLinhas(i,j); ...
cafba7e5-5451-4dde-87e0-dd1580e5fbb8
protected boolean criterioLinhas() { double alfa = 0; for(int i = 0; i < this.matriz.linhas; i++) { for(int j = 0; j < this.matriz.linhas; j++) { if (i != j) { alfa = alfa + Math.abs(this.matriz.matriz[i][j]); } } alfa = alfa / Math.abs(this.matriz.matriz[i][i]); ...
38c2c615-a9f5-4498-a184-b1325dd5d5fd
protected boolean testeParada(double []atual, double []anterior) { double maior = atual[0] - anterior[0]; for (int i = 1; i < atual.length; i++) { maior = Math.max(maior, Math.abs(atual[i] - anterior[i])); } if (maior < this.erro) { return true; } else { return false; } }
a6d29290-565b-490f-bd5a-3dd197e8b2c8
protected void trocarLinhas (int linha1, int linha2) { double temp; for (int j = 0; j < this.matriz.linhas; j++) { temp = this.matriz.matriz[linha1][j]; this.matriz.matriz[linha1][j] = this.matriz.matriz[linha2][j]; this.matriz.matriz[linha2][j] = temp; } temp = this.matriz.termosI...
54462656-75f8-43e7-a2d6-97256c9edf3c
public double[] executar(Matriz m) { linhas = m.linhas; resultados = new double[linhas];//cada linha vai ter um resultado termosIndependentes = new double[linhas]; tempMat = new double[linhas][m.colunas-1]; System.arraycopy(m.termosIndependentes, 0, termosIndependentes, 0, li...
b8a02dac-123c-4ca5-8928-e99b3e670fe6
public void calcularTriangularSuperior() { for(int k = 0; k < (linhas - 1); k++){ // Percorre linhas secundárias... Até o fim da matriz ou seja... até n for(int i = (k + 1); i < linhas; i++){ // Escolher como pivô o elemento de maior múdulo entre os termosIndependente...
eda6fb49-91ef-4263-a377-2feb5231032c
private void TrocarLinhas(int linha1, int linha2) { double aux = 0.00; // Troca elementos das linhas na matriz: a for (int i = 0; i < linhas; i++) { aux = tempMat[linha1][i]; tempMat[linha1][i] = tempMat[linha2][i]; tempMat[linha2][i] = aux; } ...
aa0cb796-cd4c-424e-a216-0052fcd1ee55
private void calcularResultado() { linhas--; // para facilitar os cáculos já que o indece de matrizes em java começam em zero! resultados[linhas] = termosIndependentes[linhas] / tempMat[linhas][linhas];//calcula o ultimo x, ja que o resultado e praticamente direto for (int k = linhas; k > -1;...
8bb57e26-f4a2-4cc3-8cb7-f9ddd990b2ab
public GerenciaArquivo(int tamanho) { this.tamanho = tamanho; try { new File(System.getProperty("user.home")+"/CNRelatorio/").mkdir(); this.relatorioSaida = new BufferedWriter(new FileWriter(System.getProperty("user.home")+"/CNRelatorio/"+this.geraNome())); } catch (IOException e) { e.printStackTrace(); ...
0837b237-f29a-49fa-95e4-3baea0d3712c
public void escreveRelatorio(double[] resultado, String nomeMetodo) { int i; try { this.relatorioSaida.write(nomeMetodo); this.relatorioSaida.newLine(); for(i = 0; i < this.tamanho - 1; i++) { this.relatorioSaida.write("Caminhão ("+(i+1)+")"); this.relatorioSaida.write(','); } this.relator...
0a1ef914-a902-430e-a38b-d0864ea0065e
public void encerrar() { try { this.relatorioSaida.close(); } catch (IOException e) { e.printStackTrace(); } }
cae883d0-3c30-4489-98a7-7af48d3ff689
private String geraNome() { Locale locale = new Locale("pt","BR"); GregorianCalendar calendar = new GregorianCalendar(); SimpleDateFormat formatador = new SimpleDateFormat("yyyyMMddHHmmss",locale); return "Relatorio_"+formatador.format(calendar.getTime())+".csv"; }
3e5ad734-f2b1-4545-8eda-33c81386c3ae
public ResolucaoSistemas(Matriz m) { this.matriz =m; ga = new Gauss(); cho= new Cholesky(); lu = new LU(); jo = new GaussJacobi(); gs = new GaussSeidel(); formatacaoSaida = new DecimalFormat("0.00000000"); }