Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.metadata/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Testar/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Testar/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Testar</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions Testar/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Binary file added Testar/bin/module-info.class
Binary file not shown.
Binary file added Testar/bin/teste/FizzBuzz.class
Binary file not shown.
Binary file added Testar/bin/teste/MarvinMusicAnalyzer.class
Binary file not shown.
2 changes: 2 additions & 0 deletions Testar/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Testar {
}
23 changes: 23 additions & 0 deletions Testar/src/teste/FizzBuzz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package teste;

public class FizzBuzz {

public static void main(String[] args) {
printFizzBuzz();
}

public static void printFizzBuzz() {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}
}

}
53 changes: 53 additions & 0 deletions Testar/src/teste/MarvinMusicAnalyzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package teste;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MarvinMusicAnalyzer {

public static int[] getRareNotes(int[] notes) {
Map<Integer, Integer> noteFrequency = new HashMap<>();

// Count the frequency of each note
for (int note : notes) {
noteFrequency.put(note, noteFrequency.getOrDefault(note, 0) + 1);
}

// Find the rare notes
List<Integer> rareNotes = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry : noteFrequency.entrySet()) {
if (entry.getValue() == 1) {
rareNotes.add(entry.getKey());
}
}

// Convert the List<Integer> to int[]
if (rareNotes.isEmpty()) {
return null;
} else {
int[] rareNotesArray = new int[rareNotes.size()];
for (int i = 0; i < rareNotes.size(); i++) {
rareNotesArray[i] = rareNotes.get(i);
}
return rareNotesArray;
}
}

public static void main(String[] args) {
int[] notes = {1, 2, 3, 2, 2, 1, 5, 5};
int[] rareNotes = getRareNotes(notes);

if (rareNotes == null) {
System.out.println("No rare notes in the song.");
} else {
System.out.print("Rare notes: ");
for (int note : rareNotes) {
System.out.print(note + " ");
}
System.out.println();
}
}

}
19 changes: 18 additions & 1 deletion jogo-oito/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand All @@ -23,5 +23,22 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions jogo-oito/.settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
7 changes: 4 additions & 3 deletions jogo-oito/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=18
org.eclipse.jdt.core.compiler.compliance=18
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=18
org.eclipse.jdt.core.compiler.source=17
40 changes: 40 additions & 0 deletions jogo-oito/src/main/java/chat/gpt/Celula.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package chat.gpt;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

public class Celula extends JButton{
private int valor;

public Celula(int valor) {
this.valor = valor;
setFont(new Font("Arial", Font.BOLD, 36));
setText(getValorFormatado());
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Implemente a ação de clique na célula aqui
Tabuleiro tabuleiro = new Tabuleiro();
tabuleiro.reiniciar();
}
});
}

public void setValor(int valor) {
this.valor = valor;
setText(getValorFormatado());
}

private String getValorFormatado() {
if (valor == 0) {
return "";
} else {
return String.valueOf(valor);
}
}



}
82 changes: 13 additions & 69 deletions jogo-oito/src/main/java/chat/gpt/JogoDosOito.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class JogoDosOito extends JFrame implements KeyListener {

private int[][] tabuleiro = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 0 } };
private JButton[][] botoes = new JButton[3][3];
private Tabuleiro tabuleiro;
private JButton[][] botoes;
private JButton botaoReiniciar;

public JogoDosOito() {
Expand All @@ -24,6 +24,9 @@ public JogoDosOito() {
setSize(300, 300);
setLayout(new GridLayout(4, 3));

tabuleiro = new Tabuleiro();
botoes = new JButton[3][3];

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
JButton botao = new JButton();
Expand Down Expand Up @@ -53,16 +56,16 @@ public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_UP:
mover(1, 0);
tabuleiro.mover(1, 0);
break;
case KeyEvent.VK_DOWN:
mover(-1, 0);
tabuleiro.mover(-1, 0);
break;
case KeyEvent.VK_LEFT:
mover(0, 1);
tabuleiro.mover(0, 1);
break;
case KeyEvent.VK_RIGHT:
mover(0, -1);
tabuleiro.mover(0, -1);
break;
}
}
Expand All @@ -73,75 +76,16 @@ public void keyTyped(KeyEvent e) {
public void keyReleased(KeyEvent e) {
}

private void mover(int linha, int coluna) {
int linhaVazia = -1;
int colunaVazia = -1;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (tabuleiro[i][j] == 0) {
linhaVazia = i;
colunaVazia = j;
}
}
}
int novaLinha = linhaVazia + linha;
int novaColuna = colunaVazia + coluna;
if (novaLinha < 0 || novaLinha > 2 || novaColuna < 0 || novaColuna > 2) {
// movimento inválido
return;
}
tabuleiro[linhaVazia][colunaVazia] = tabuleiro[novaLinha][novaColuna];
tabuleiro[novaLinha][novaColuna] = 0;
atualizarTabuleiro();
if (jogoConcluido()) {
JOptionPane.showMessageDialog(this, "Parabéns, você venceu!");
reiniciarJogo();
}
}

public static void main(String[] args) {
new JogoDosOito();
}

private boolean jogoConcluido() {
int count = 1;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (tabuleiro[i][j] != count % 9) {
return false;
}
count++;
}
}
return true;
}

private boolean movimentarPeca(int linha, int coluna) {
if (linha > 0 && tabuleiro[linha - 1][coluna] == 0) {
tabuleiro[linha - 1][coluna] = tabuleiro[linha][coluna];
tabuleiro[linha][coluna] = 0;
return true;
} else if (linha < 2 && tabuleiro[linha + 1][coluna] == 0) {
tabuleiro[linha + 1][coluna] = tabuleiro[linha][coluna];
tabuleiro[linha][coluna] = 0;
return true;
} else if (coluna > 0 && tabuleiro[linha][coluna - 1] == 0) {
tabuleiro[linha][coluna - 1] = tabuleiro[linha][coluna];
tabuleiro[linha][coluna] = 0;
return true;
} else if (coluna < 2 && tabuleiro[linha][coluna + 1] == 0) {
tabuleiro[linha][coluna + 1] = tabuleiro[linha][coluna];
tabuleiro[linha][coluna] = 0;
return true;
}
return false;
}

private void atualizarTabuleiro() {
int[][] estadoTabuleiro = tabuleiro.getEstado();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
JButton botao = botoes[i][j];
int valor = tabuleiro[i][j];
int valor = estadoTabuleiro[i][j];
if (valor == 0) {
botao.setText("");
} else {
Expand All @@ -152,7 +96,7 @@ private void atualizarTabuleiro() {
}

private void reiniciarJogo() {
tabuleiro = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 0 } };
tabuleiro.reiniciar();
atualizarTabuleiro();
}
}
}
Loading