Arrays To Solve And Print A Kakuro Board

Feb 11, 2015

I am working on and am stuck on an assignment where we draw and then solve a Kakuro game.we have been given DrawingPanel.java and DrawGrid.java which should draw the board game grid then we need to pass a .txt document which has the game information

I tried getting my readGrid function to read the input file and store it in arrays but it is not working?

//main -get arguments -make grid -solve it
import java.io.File;
import java.util.Scanner;
import java.util.Arrays;
public class Kakuro {
static File gridFile; // The input file describing the grid

[code]...

View Replies


ADVERTISEMENT

Solve Quadratic Equations With Arrays

Feb 14, 2014

I am suppose to write a method for solving a quadratic equation using the following header:

public static int solveQuadratic(double[] eqn, double[] roots)

I have entered 1, -3 and -4. The answer I get is "The solution is:0.0" .

import java.util.Scanner;
public class QuadratilEq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[3];
double[] roots = new double[4];

[Code] .....

View Replies View Related

Developing Tetris Based Characters - Can't Print The Piece Within Board

Dec 18, 2014

I post the code I'm developing for a tetris-based characters. The problem I have is that I can't print the piece within the board. I haven't any error.

Class Piezas

Java Code:

public class Piezas {

public Piezas() {}
//atributos
private int i;
private int j;
private char m[][];
private int formaPieza;

[Code] ....

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Code Will Not Calculate Or Print Intersection And Difference Of Two Sets Using Arrays

Nov 19, 2014

As part of the instructions we are required to use loops and methods to solve to program this code. We are not allowed to use any set functions that are already built in java.The methods for intersection and difference MUST return int value.

import java.util.Scanner;
public class setPractice {
public static Scanner kbd;
public static final int MAXSIZE = 20;
public static void main(String[] args) {
kbd = new Scanner(System.in);

[code]...

View Replies View Related

Arrays And Number Generator - Determine And Print Largest And Smallest Values

Dec 4, 2014

/*
Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate.
*/

import java.util.Scanner;
import java.util.Random;
public class LNFI_2DArray
{
public static void main(String[] args) {
int guess;
int[] array = new int[4];

[Code] ....

I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.

View Replies View Related

Implementing Search Algorithm To Solve 8 Puzzle

Oct 4, 2014

I have been working on a program that takes in a 2d array (there is a method to convert to 1d as necessary) and uses it as an 8 puzzle, which the program then solves (if it is solvable) using the A* Search algorithm, outputting each solution move. It needs error checkers/traps/exception handlers, and be able to create an 8 puzzle from user input, create an 8 puzzle from file input, and create an 8 puzzle from file input and then output to another file the solution move sequence. I have gotten nearly everything done except for implement the algorithm itself and the methods for handling input from files or output to files (the input/output file methods are a minor problem that I can probably solve fairly easily, I just want to be able to test the a* with the puzzle created from user input first.

I have taken several cracks at it, but I am not really good with Java in this type of situation and this is hurting me a lot. I have put in a method to determine if a puzzle is solvable, but the A* algorithm still eludes me. I understand the concept of the algorithm, you have a heuristic function, a cost function (each move equals 1 in this case), and you add the two together to get f(n), choosing the move that will get you the closest to your goal (best first search basically). here is what I have so far that works:

import java.io.File;
import java.io.IOException;
import java.util.Queue;
import java.util.Scanner;
public class Puzzle {
public static void main(String[] args) throws IOException {

[Code] ....

I have it outputting things to make sure all that works already, I have all the error handlers, but I think that before I can even implement the A*search algorithm, there may be something else I need. Conceptually, I understand I need Nodes, States and Stacks, and Queues (I think, I am not sure about this), but with the way my code has been made so far, I am not sure how to implement those and then implement them with the A* algorithm. What I should do next? I have looked at the code of other uses of A* algorithm(that is how I found out I might need Java data structures like queue and stack and list), but I am not sure exactly where to go to from where I am.

View Replies View Related

How To Solve No Suitable Method Found For Write (String) Error

Sep 1, 2014

I wrote this program to prompt user to enter his choice to do a i/o operation in a file. It shows error. How to clear the error. My code is:

import java.io.*;
import java.util.*;
class Files {
public static void main(String args[]) {
String n;

[Code] ....

error:
E:java>javac Files.java
Files.java:26: error: no suitable method found for write(String)
fos.write(n);

[Code] ....

View Replies View Related

What Is The Difference Between Regular Arrays And Multi Dimensional Arrays

Jun 28, 2014

I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.

View Replies View Related

Board Of Colors And Players

Sep 14, 2014

My assignment is for a game where there is a board of colors and each player draws a color and moves to that position on the board. It will then output how many cards total in the game it took whichever player to win. If no winner it outputs the number of cards that none won by going through. I attached the file that corresponds with my code.

This is the desired output:

Player 1 won after 7 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 2 won after 4 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 4 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.

import java.io.*;
import java.util.Scanner;
public class ProgrammingAssignment1 {
/**
* @param args the command line arguments
*/
public static int players;
public static int cards;
public static int boardlength;
public static String board;

[Code] .....

The output that I get is:

Player 1 won after 3 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 1 won after 3 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 3 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.I guess I'm supposed to set the playerPos[] to -1, but I'm unsure how.

Attached File(s) : colors.in.txt (1.5K)

View Replies View Related

Randomly Filling Tic Tac Toe Board

Oct 19, 2014

So I an assignment in Java to write a code which will randomly populate squares in a Tic Tac Toe Board. I pretty much have it I think, but I cannot get the 'O' to appear on the board, some squares will be blank. We were told to use the Random utility to generate the squares. I am attaching the .gif's which are used. Here is my code:

import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class LandryTicTacToe extends JFrame
{
/**
*
*/
private static final long serialVersionUID = -8781512780135301721L;
private final int HEIGHT = 450;//Set value for Height
private final int WIDTH = 500;//Set value for Width
private static JButton [] button = new JButton[9];//Declare array of Buttons

[Code] .....

[attachment=37084:TicTac0.gif][attachment=37085:TicTacX.gif]

Instructions Given to me:

Display a frame that contains nine labels, arranged like a Tic Tac Toe board. A label may display an image icon for X, an image icon for O, or nothing. Display images randomly in each label. Use the Random class to generate 0, 1, or 2, which corresponds to displaying an X image, an O image, or nothing.

Attached image(s)

View Replies View Related

Tic Tac Toe Game - X And O Do Not Show In The Board

Apr 12, 2014

I have a tic tac toe game and when i run it it works and there are no errors. but the X's and O'x do not show in the board. I know the problem is in the "gameBoard" method and its cause i am telling the code to print the same board every time but i dont know how to do it the right way....

package chap7MDA;

import java.util.Scanner;
public class chapexe7we {
public static void main(String[] args) {
char[][] board = new char [3][3];//make a game board
gameBoard(board);// call the method game board to make the board

[Code] ....

View Replies View Related

Android App Battleship Board

Nov 11, 2014

I want to make the board for the game, I want it to be a two-dimensional array of buttons.I know how to make a array but is there a class of buttons that I need to use? and how do I connect it to the xml?I am using eclipse.

View Replies View Related

Make A ToString That Returns A Board

Jan 26, 2015

I've been trying to make a class that has a toString method that displays the board at the same time displays the value of each index of a 2d character array inside of the code. My professor has made the client print the method. I assumed since he was printing it on the client we had to return a string that gives us this.The number 2 is part of the 2d character array while the rest of the index values are just space characters.

___________
| | | |
|___|___|___|
| | | |
|___|___|___|
| | | |
|___|___|___|
| | | |
|___|___|___|
| 2 | | |
|___|___|___|

I had trouble figuring out how to return this so I started testing it out in another file.

public static void main(String[] args) {
// TODO Auto-generated method stub
char[][] myHidingPlaces;
myHidingPlaces = new char[5][3];
myHidingPlaces[0][0] = 'p';
char play = '1';
for (int i = myHidingPlaces.length-1; i >= 0 ; i--) {

[code]...

View Replies View Related

Boggle Board Is Not Showing Up When Run The Program?

Jan 18, 2015

I'm making a Boggle game, but the issue here is that the boggle board is not showing up when i run the program.

Here is the code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Boggle {
public static void main(String[] args) {

[code]....

View Replies View Related

Creating Java Based Message Board?

Jan 4, 2015

I'm trying to create java based fairly simple forum.

The task is as following:-

• each user may post exactly one research topic;

• each each may see all research topics posted by other users;

• each each may read all messages contributed by all users on a particular research topic;

• each user may post a new message to contribute to the discussion on any of the topics posted.

Something like below:-

User topic: Intrusion Detection Systems
Posted by: John
[22/10/11 14:00] John wrote I am building a new IDS based
on neural networks. …………….Comments ………….?
[22/10/11 14:12] Kate wrote there could be too many false positives!

View Replies View Related

Bingo Board - Having Array To Fill A Grid

Dec 16, 2014

I am attempting to make a 5x5 bingo board. My array generates 75 numbers(15 per bingo letter) and displays them in a random order. What I am having trouble figuring out is how to fill the 5x5 grid with 25 numbers from my array. And yes, my code is probably much longer and much more redundant than it needs to be. Also, I think I'm using cells and grids terribly wrong (possibly the entire java language) but I'm not sure.

import java.util.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.event.*;
import java.util.ArrayList;
import java.awt.GridLayout;
import javax.swing.JButton;
public class bingoboard extends JFrame

[code]...

View Replies View Related

Score Board - Constructor Null Pointer Exception

Sep 7, 2014

I'm getting constructor null pointer exception but i don't know what has gone wrong...

private int capacity; // maximum capacity of the board
private double minimum; // minimum distance of the flyer
private SortedLinkedList sortedList;
private int size = 0;
public ScoreBoard() {
capacity = 10;
minimum = 0.0;
sortedList = new SortedLinkedList();

[Code] ....

View Replies View Related

Keeping Track Of Player Position In Monopoly Board Game

Jun 28, 2014

I am trying to design a monopoly board game with a class and a main program. I can not make the method to keep track of the player's position after every roll. After every roll it prints "Previous position: 0".The player should also not go over 14th spot because the board is just 15 including 0. That is what I have (just the particular method and the part from the main program which call it).

public int getpospl1()
{
System.out.println( getplayer1name() + " Rolls "
+ "Dice 1: " + getrolld1() + "" + "Dice 2: " + getrolld2() + "" );
int spot1 = 14; //The end spot
int start = 0;
int previousPosition = start;

[Code] .....

View Replies View Related

Game Loop Freezing - Reset Button To Clear Board

Nov 9, 2014

I'm back with a question about the Black Jack assignment. I've created a working game that works for one round, as well as a reset button that's able to clear the board of the old hand. However the runGame() loop, which checks whether a player has played his hand seems to freeze the program the second time around

private void initNewGame(){
dealer.addCard();
for(int i = 0; i < numberofplayers; i++){
players[i].addCard(); //draws card, adds score and paints card to the board
players[i].setStatus(false); //makes the buttons usable in the players[] class

[Code] .....

I know it's probably not optimal having an while loop constantly running to check the status, but I can't seem to figure out why it freezes.

View Replies View Related

Comparing Characters Of A Word To Puzzle Board - Diagonal Search Algorithm

Feb 7, 2015

Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].

I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.

Here's the search algorithm format I have to use:

for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess

I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.

Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)

//diagonal search
for(String word : guessWords) {//for each guess word
 int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
 
[Code] ....

View Replies View Related

Build Backtracking Algorithm To Place N Queens On Chess Board Of Nxn With No Threat To Any Queen

Nov 17, 2014

Having some trouble coding this exercise in JAVA:

Build a backtracking algorithm to place n queens on a chess board of nxn, with no threat to any queen.

Using F=parameter, Print only the first result.

Using the same C=parameter, print every possible inlays.

This should work when running with a 4x4 board and an 8x8 board basically.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Constructor For Arrays

Apr 23, 2015

I'm wonder about the issue of constructor for arrays. Let say I have a class tablica, and one component int[] tab. If I get it right until now tab is nothing more than empty reference to some unexisting array?

import java.util.Random;
class tablica{
int[] tab;
tablica (){ // i wish it was constructor

[code]....

Then, I'm trying to build the constructor for class tablica. What can be the parameter of such constructor? Is it fields of array? It is simple forf for basic variable

- I liken values defined in constructor with those global defined in class. But how to do it with array component tab.

If I create array object in main method then how can I use this constructor?

View Replies View Related

Resizing 2D Arrays

Sep 19, 2014

How do i increase the size of a 2D array from 2X2 to 4X4 where only the boundary elements are zeroes and the rest of them remain the same?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved