I'm having trouble filling in the blank squares on a Minesweeper game. What I am trying to is, if a user clicks a square and that square(s) does not have a bomb in it, or adjacent to it, should be set to an empty square.
Here's my recursive method below:
public void revealZeros(){
for(int x = -1; x <= 1; x++)
for (int y = -1; y <= 1; y++){
Square zeroSquare = (Square)board.getSquareAt(xLocation+x, yLocation+y);
if (!(zeroSquare.SquareHasBomb)){
setImage("images/empty.jpg");
}
}
revealZeros();
}
I am traversing around the square that the user clicks on with the use of two for-loops. Getting the square at that location and then applying an empty square image. On that square.
The function should then recurse itself and go onto the next square, if the next square does not have a bomb or does not have an adjacent bomb.
I am trying to write to an output file that the user names. I have flushed and closed the printwriter, so now I am at a loss. The console output works fine with the formatting, and the file is created, but I cannot get the file to populate. I have the following:
public static void main(String[] args) {
try { Scanner kb = new Scanner(System.in); System.out.print("Input file: "); String inputFileName = kb.next(); System.out.print("Output file: "); String outputFileName = kb.next(); // Construct the Scanner and PrintWriter objects for reading and writing File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = new PrintWriter(outputFileName);
Recursion in a MineSweeper game. So far, when a user clicks on a square and it has a bomb on it, I reveal the bomb to the user - see clicked(). I also have the ability to show the user if the squares surrounding them have any adjacent bombs - see countAdjacentSquares().
However, I am having trouble with my fillZeros() recursive method. When a user clicks on a square that has zero bombs in its surrounding squares, it not only reveals that square, but also any adjacent squares (horizontally, vertically or diagonally adjacent) that also have zero bombs in its surrounding squares.
I don't have any recursion, if I click on a square with no bombs all it does it set the square to 0, but doesn't continue to check for other empty squares.
Java Code:
import javax.swing.*; import java.awt.*; import java.util.*; public class Square extends GameSquare { private boolean revealed = false; private boolean squareHasBomb = false; public static final int MINE_PROBABILITY = 10; public int mineCount = 0;
public class MineSweeper { public static void main(String[] args) { int n = Integer.parseInt(args[0]); //columns int s = Integer.parseInt(args[1]); //rows int p = Integer.parseInt(args[2]); //max number of bombs
Every time the compiler shows me this Array Index Out Of Bounds and shows me in the witch line i have error but i just don't get it how to fixed it and why compiler printing me this mistake because there is enough space in array field[][] because i provided a n+2 X s+2 fields in array and i am using just 1 to n ,including and 1 to s ,including m, so i have not used fields from field[0][0] to field[0][s+1] and field[0][0] to field[n+1][0], field[n+1][0] to field[n+1][s+1] ,field[n+1][s+1] to field[0][s+1] ,so i suppose i can check their values and do not get out of array bounds,but compiler claims otherwise!!!
I'm having some problems with the graphics of my hangman game. The graphic that's supposed to show up on the first guess (the hangman pole) doesn't show up until guess number 2. And on the eighth guess, no graphics show up (I just get a blank frame).
import java.awt.*; import javax.swing.*; public class HangmanFigure extends JPanel { private int guesses; private Image background; public HangmanFigure() { super();
so for my computer science class, we have the following problem:
In your documentation be sure to say which loop you thought was easier to implement for this program and why Write a program that produces the following outputs. The first line of output must be written using a For-Loop. The second, using a While-Loop and the third using a Do-Loop.
You look at the program and smile because you see that the series is just the numbers 1-10 squared...just one line is in reverse order. No problem! As you start typing you discover that the number 8 key on your keyboard is not working. For this program you are unable to use the multiplication key
So, back to the drawing board. By staring at the sequence a light comes on and you are able to quickly finish this program WITHOUT using mulitiplication (or the Math class/ solve with arithmetic operators +, - or / ) .
Sample output:
For Loop 1 4 9 16 25 36 49 64 81 100
While Loop 100 81 64 49 36 25 16 9 4 1
Do While Loop 1 4 9 16 25 36 49 64 81 100
I have the "for" done, but I did it with a "for" in the beginning but then had a multitude of nested "if" loops so that I could do 7*7=7+7+7+7+7+7+7
I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...
Here's my code:
package sqrroot;
public class SqrRoot { /** * @param args the command line arguments */ public static void main(String[] args) { double sroot, rerr; int count = 0; for(double num = 1.0; num <= 100.0; num++){
[Code] ....
and here is the output:
run: 0.0 1.0 is a perfect square. 0.0 4.0 is a perfect square.
[Code] ....
There are 49 perfect squares between 1 and 100. BUILD SUCCESSFUL (total time: 6 seconds)
Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?
So I need to create a 10x10 grid for a snakes and ladders board, the board loads but i cant figure out how to add numbers to the squares. Here is my code :
import java.awt.*; import javax.swing.*; public class Board { //Creating the array int[][] numbers=new int[10][10]; public static int rows = 10; public static int columns = 10; public static Color col1 = Color.green;
I know I can calculate the sum of squares as such:
// SumSquares.java: calculate the sum of two squares class SumSquares { static int sumSquares(int a, int B)/>/> { int asquare; int bsquare;
[Code] ....
But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.
import java.awt.*; public class Square { private double x,y; // Current position of the square. private Color color; // The color of the square. private int side; // The side of the square public Square() // constructor
[Code] .....
This is the square class, it draws an orange square that moves around in the applet viewer, works fine and as it supposed to do.
Ship:
package assignment1;
import java.awt.*; public class Ship { private Square[] fleetMembers; // declare fleetMembers as an array of Square private int total = 5; // Max number of squares in fleet private double x,y; Ship() // Constructor
[Code] ....
This is my FleetOfShips code. It is supposed to be a set of ships moving around together, but for unknown to me reasons it doesn't work. It does compile without any problems but when I run the applet it doesn't do anything.
I know I can calculate the sum of squares as such:
// SumSquares.java: calculate the sum of two squares class SumSquares { static int sumSquares(int a, int B)/>/> { int asquare; int bsquare;
[Code] .....
But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.
I am getting the blank value in the array and this code is passed in IVR for playing the values since the first value is blank the prompts arrangements is disturbed. I want to replace the blank space or value by zero.
I am getting blank page only. I created sample JSF project with Facelet in Eclipse. The source code contains basic page with header, content & footer. I refer the site Support-Eclipse . I deployed war into Tomcat. I am unable to find the problem.
why my sub class object just gives me a blank when it comes to the String. It works just fine for the super class but when I get to the sub class the program just gives me a blank. I won't let me input anything for the String. On line 24 of the client I attempt to input a new String but it doesn't ever let me enter one so then any call to getName is just a blank.
I have altered my super and sub class as well as the client to try to get it to work. I tried a local variable in the client, I tried using protected in the super class, I tried a handful of other things.
import java.util.*; public class TryingItOutClient { public static void main(String[] args) { Scanner input = new Scanner(System.in);
i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, tell me where i gone wrong.
import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Reservations extends Frame implements ActionListener { Color lightRed=new Color(255,90,90); Color lightGreen=new Color(140,215,40); Rooms room=new Rooms(5,3);
// 2009 nobelPrizeWinners.put("2009 Physics", new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"), new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")}); nobelPrizeWinners.put("2009 Chemistry", new PrizeWinner[] {new PrizeWinner("Venkatraman", "Ramakrishnan"),
[Code] .....
At the moment, my output is:
2008: Chemistry: Osamu Shimomura, Martin Chalfie, Roger Y. Tsien 2008: Economics: Paul Krugman 2008: Literature: Jean-Marie Gustave Le Clézio 2008: Medicine: Harald zur Hausen, Françoise Barré-Sinoussi, Luc Montagnier 2008: Peace: Martti Ahtisaari
[Code] .....
However, I need a blank line between the final entry of 2008 and the first entry of 2009.
I am aware that the default value of char is 0. But in this program I am getting some unexpected output
public class TestClass12{ static int[] ia = new int[1]; static char ch; public static void main(String args[]) throws Exception{ System.out.println("ch:"+ch+" ia[ch]:"+ia[ch]); } }
Output: ch: ia[ch]:0
If you see the above output ch is printed as a blank space instead of 0, while the array default value is correctly printed by taking the char default value as index. Why is ch printed as blank space?
While debugging everything is going through... even it passes through the last line. But the pdf is not launching... showing only a blank screen in its status bar as "Connecting"... Earlier it was launching.. but suddenly this issue is raising up. Is there any IE settings need to be checked?
In the program below I'm trying to read the contents of several .txt files in the same diretory and create a new .txt file containing all of the data from each file. My output is generated in the console however my .text file is blank.
public static void main(String[] args) throws IOException { String target_dir = "C:Files"; String output = "C:Filesoutput.txt"; File dir = new File(target_dir); File[] files = dir.listFiles();
What's wrong with my Java program? When I open it using appletviewer, the applet opens but stays blank and an error message appears in Terminal.
Java Code:
import java.applet.*; import java.awt.*; public class DemoColor extends Applet { Font littleFont = new Font("Helvetica", Font.ITALIC, 6); public void paint(Graphics gr)
[Code] ....
Error Message:
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
at java.awt.Color.testColorValueRange(Color.java:310) at java.awt.Color.<init>(Color.java:395) at java.awt.Color.<init>(Color.java:369) at DemoColor.paint(DemoColor.java:24)
I need to write a program but I am having hard time filling an array of triangles...we are suppose to have 3 different classes..1 class of points..1 class of triangles and 1 main method which apply all those..here what I have been come up so far for the point class which I believe is good..
public class Point { private float x; private float y; //Making x equal to the x coordinate and y equal to the y coordinate like on a graph public Point(float xCoordinate, float yCoordinate) { x = xCoordinate; y = yCoordinate;
[Code] ....
Now here is my question how I am suppose in the main method fill an array of triangles for 100 triangles or less?