I am a student in an intro to computer science class working on my final project. This is essentially a game of connect 4, but only requiring 3-in-a-row for victory. We were given the base game and a sample file to work with to make an AI that beats our professor's ai in the base game. Here is the base game
Our assignment is to make a version of the classic 'Connect Four' game, where we need to construct a GUI that shows the current state of the game and instead of having a winner once a player has four chips in a row, the game needs to continue until no chips can be placed anymore.We currently get stuck in the GUI part. Running it right now results in a board with empty spaces only. Also after choosing a column to place, the board remains empty.
Our question: How do we get the board filled with the right color of chips at the right place?We know the 'ArcsPanel'-class (almost at the bottom of the code) is wrong, but we don't know what to do to make it right.
Most of my code is done for making this Jeopardy game, the only problem I seem to have is to have variables that retain values after going through a loop, in this case the variables counter and score in the method responsePrompt
After going through the 25 questions, the value counter remains at 1, and score is either 1 or -1, nothing more, nothing less. I've had the variables initialized at 1 both inside and outside of the for loop. Full code below just in case it's something outside the method
import java.util.*; import java.io.*; public class Project10 { public static void main(String[] args) throws java.io.IOException
I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.
So, Iv'e been trying to make a simple Text Based RPG with Java, and it is going quite well, and my friends want to play it too but they aren't very tech savvy, so it's hard to tell them to get an IDE or use the CMD, so I wanted to know if there was a way to make my text-based game into a window, like using JFrame or something. All i need is a window that displays the text, and a bar on the bottom that lets the user input what they want (Kind of like a CMD).
I want make a math equation game. usually math game use equation for the question and we answer that equation. ex : what is the result of 2*5 / 2+2/ 2^2 etc. and we answering that. but i want to make it different so i want to make the equation answer as the question and the equation as the answer of the game. Ex : the question is 54 so we can answer it with 9*6 or 24+30. and this is my java code
package coba; import java.util.Scanner; public class Coba {
public static void main(String[] args) { double angka = Math.random()*70;
[Code] ....
but when i run it the error code show like this : Quote
Ok, so I'm making a game with a space ship that flies around the universe and discovering new planets. It works fine so far, but I'm looking to make it perform better and be better compatible with lesser-processors.So, I'm trying to put in an FPS counter and an entirely new game loop so that my game can decide for me what FPS I should use.
I have two classes. Heres the big, main one: [Java] package cyentw.game.src; import java.awt.Color; import java.awt.Font; impor - Pastebin.com *I want to change the loop and put an FPS counter in around line 456, you can scroll past the rest if you'd like*And heres the init frame one, in case you'd like to see it for some reason.
Java Code:
package cyentw.game.src; import javax.swing.JFrame; public class Start extends JFrame{ public static JFrame frame; public static int WIDTH = 500; public static int HEIGHT = 500; public Start() {
[code]....
how to make my game loop as quickly (or a bit slower) as it can, and my FPS is static.
I have a question related to the code below, that I do not understand. The aim is to count all files and subdirectories in an ArrayList full of files and subdirectories. So I have to count every file and every subdirectory.
The code concerning counting files is clear to me - every time d is of the type file I have to increment n by one. However I thought that I have to do the same thing in case d is a directory, so I would have written the same code for directories.
So what does "n += ((Directory) d).countAllFiles();" mean? In my understanding the method countAllFiles() is applied again on the object Directory ( as Directory is the class that contains this method), but how is n incremented by this? I thought n should be incremented by one as we did with files.
public int countAllFiles() { int n = 0; for(SystemFile d : content) { if(d instanceof File) { n++;
This is the code I have written so far. This program calculates tax from multiple tax payers.
import javax.swing.JOptionPane; public class CalcutateTax { public static void main (String [] args)
[code]....
The problem is I cant think how to ask the use if he wants to calculate tax due for another taxpayer. If the user says yes, keep calculating, otherwise exit from the program. And how do I keep count of how many people got their tax calculated? Say for example,
JOptionPane.showMessageDialog (null, " We calculated tax for " + xnumber + " number of people.");
This is the question asked on my assignment ask the user if he wants to calculate the tax due for another taxpayer if so, do it again.At the end of the main method, output a message in a dialog box that says: Hello, We calculated taxes for [number of taxpayers].replace [number of taxpayers] with the actual number of taxpyers you calculated taxes for.
I'm having trouble with my program for my class. The program just has to be able to have a button and show how many times a user has clicked it.
Every time I compile it I get errors such as:
unable to find symbol x where the code is executed when the button is clicked
What can I do?
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JPanel; public class Program { public static void main(String[] args){ int x = 0;
I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and how to get it to work correctly.
public void run() { long currentTime,timeDiff; prevTime = System.nanoTime(); accumulator = 0; boolean TRUE = true;
[code]...
When I print the fps variable to the terminal window, it show a value of ~59.9998 - very close to the frameRate of 60. That is to be expected, and works well. The problem is that when I deliberately make the game go really slow, by spamming a bunch of enemies, the game looks slow, but the FPS is still apparently ~59.9998. I thought that maybe the paint() method was not calling when it was supposed to, but that might not be the case.
This FPS counter should be working, I can't see where I have gone wrong. Is there a problem with the code, or is there another problem that might cause the screen to be redrawn 10 times a second with an FPS of 60?
Create a WordCounter class with a constructor that takes a file name as a parameter. The class should have two fields: one for the file name and one for a HashMap to store word count information. The constructor should call a private method, countWords, that reads in the file and counts the word frequencies. The class should contain a get method for each field, as well as a print method that prints out the map in the following format:word:frequency. When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)You should include the sample text file on Blackboard
import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class WordCounter
I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?
The point of this program is to search for a specific character in a text file. I want the program to find a character in the file "letterCounter.txt".
I have to create a code that can calculate the number of upper case letters in a string that is entered by the user (below.)
Java Code:
import javax.swing.JOptionPane; public class mainClass { public static void main (String [] args) { String userInput; userInput = JOptionPane.showInputDialog("Enter a string.");
[Code] ....
My issue is that I would like the program to be able to function properly when spaces are entered into the string. As it is right now, I believe it is only processing the first string entered into the input box.
We are writing our own classes and methods. My instructor has provide the code
/*------------------------------------------------------------------------- import java.util.*; public class Assignment5 { public static void main (String[] args) {
[Code].....
I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.
I believe I have this program CounterTester.java down but in my output the program is increasing the way I want it to but it is not decreasing the way I want it to.
public class CounterTester { static int myCount; static int myCount2; public CounterTester(int inti) { myCount = 1; myCount2 = 10;
While reading head first java i encountered a problem(Pg. 90 chapter 4 - mixed messages).
Suppose in a class(say A) outside main() a counter variable is declared and initialized to 0.
In main() declared the array of objects of the class A.
Consider a while loop in which we increment the counter as follows:
public class A{ int counter = 0; public static void main(String[] args){ A[] arr = new A[20]; int x = 0; while(x<4){ arr[x] = new A(); //arr[] is array object arr[x].counter += 1; x++; } } };
what is the final value of counter ? will it be the same for all array objects.