Maze Backtracking From Text File

Dec 15, 2014

im having 2 simple problems that are for somereason going above my head right now.

1: i need to start the program at the first possible position (row 0 col 0)
2: i need to be able to read multiple mazes in one file.

Code:

import java.io.*;
public class Driver {
private File mapFile = new File("map.txt");
private char[][]maze;
private char pathMarker = '2';
private int row,col,ndx=0;
public static void main(String[] args) {
Driver d = new Driver();

[code]....

View Replies


ADVERTISEMENT

Sudoku Solver Backtracking Algorithm

Dec 5, 2014

It's about a backtracking algorithm trying to solve a sudoku, represented by an array of integer arrays. For testing matters, the start field is empty.

static boolean solve(int[][] field, int i, int j) {
if (filled(field)) {
return legal(field);
} else {
for (int k = 1; k <= 9; k++) {
field[i][j] = k;

[Code] ....

View Replies View Related

How To Make A Text File Only Use Lines In A Text File Beginning With A Certain Letter

Mar 15, 2015

I have a program that reads lines of text, but some of the lines of text aren't applicable and break the program. I'd like to put a letter in front of the lines in the .txt file I want to use, such as a #.

I need to make an if loop that'll check for the first letter on the line being #, and use the line in the program if true and skip if false. I'm guessing a boolean variable would be useful here to be true or false depending on the presence of #, but I don't know how to only read the first letter of each line, how can I do this?

View Replies View Related

Rat And Maze Protocol

Apr 17, 2014

So far i've built an array of char W= wall, O=open, R= rat, and P= path

I have another class "RAT" which will navigate through the maze. so im having trouble with the method to get the position of the rat when it is navigating through maze. this is what i have.

public class FinalMaze {
static char[][] mazeArray = new char[][] {
{'o','o','o','o','o','o'},
{'o','w','w','r','w','o'},
{'o','w','p','p','w','o'},
{'o','w','p','w','w','o'},
{'o','w','p','p','w','o'},
{'o','w','w','p','w','o'},
{'o','w','w','p','w','o'},
{'o','o','o','o','o','o'},
};

[Code] .....

View Replies View Related

Recursive Backtracking Solution - How To Cache Answers Into Appropriate Array

Jan 23, 2014

I can often write a recursive backtracking solution, but don't know how to cache the answers into an appropriate array.

For example:

Java Code:

public static int max(int[] costs, int index, int total, int shares) {
if(index >= costs.length) {
return total;
}
int buy = max(costs, index + 1, total - costs[index], shares + 1); // buy one stock
int sell = max(costs, index + 1, total + shares * costs[index], 0); // sell all stocks
return Math.max(total, Math.max(buy, sell)); // compares between buy, sell, and doing nothing
} mh_sh_highlight_all('java');

This is a dynamic programming exercise, but I have no idea what dimensions the dp array should be (I was thinking maybe dp[index][total][shares], but that seemed like overkill). Is this just because my understanding of recursion isn't solid enough or am I missing something else?

View Replies View Related

Ball Stopping At The Edge Of Maze

Mar 7, 2015

I am doing an assignment which involves creating a maze and a ball that needs to go through the maze to an end tile then stop the scenario. The maze is made up of 208 buttons in a Jbutton Grid layout. I am replacing certain buttons with a brown tile icon to make up the maze. The ball needs to run along those brown tiles as its path and not be able to move off the brown tile icon images.

I have built the maze and have got quite far with this but now I am stumped on the concept of keeping the ball within the boundary edges and on the brown tiles. I have been told to use if statements, but not had the process explained to me in a way I can understand.

View Replies View Related

How To Find A Path Through Array Maze

Mar 4, 2015

So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far

private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){
boolean solved = true;
for(int i=fromRow; i<toRow; i++){
for(int j=fromCol; j<toCol; j++){
if (x[i][j] == ('*')){
//do something
}
}
}
return false;
}

the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Maze Game - Tracking Objects / Limit Movement

Jan 26, 2015

I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.

I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement

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

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

Read Text File Into Object Array And Creating Random Access File

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code] .....

And then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19

These continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quantity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Create Random Access File

Dec 9, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code]...

these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Creating Random Access File?

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )

[code]....

and then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34

Mustard Seed,100,64

Coriander Powder,924,18

Turmeric,836,80

Cinnamon (Ground Korintje),951,10

Cinnamon (Ground) Xtra Hi Oil (2x),614,31

Cinnamon (Ground) High Oil (1X),682,19

these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Read Text File Into Array Ask User To Save File And Print Data

Jul 14, 2014

New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows

(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.

[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

[Code]....

View Replies View Related

Creating A System That Will Ask User To Create A File That Will Store To Text File

Mar 9, 2015

I am new to java and I am creating a system that will ask the user to create a file that will store to a text file, Once the user created the file I have a class that will let the user input the subject name that has been created, However, I keep on getting this java.util.nosuchelementexception.Here's my code:

public void display_by_name()
{
String id, name,total;
String key[]=new String[30];
String value[]=new String[30];
int i=0;

[code]....

View Replies View Related

File Handling - Display Path Of The File In Text Field

May 6, 2014

I am facing a problem while executing a task. My task is to make such a code which will search for my source code file (abc.java) in all directories and then displays the code in textarea inside frame and along with that i also have to display the path of the file in text field. I have coded something but i am really not getting anywhere near my task.

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*
 
public class Lab extends JFrame {

[Code] ....

View Replies View Related

Program For Adding One Text File Into Zip File Without Extracting

Apr 9, 2015

java code for adding one text file into the zipped file without extracting It is possible in java code ?

View Replies View Related

I/O / Streams :: Retrieving File Directories From A Text File?

Jun 25, 2014

Let's say I have a text file and in the text file exists file directories as such:

'assets/picture1.png'
'assets/picture2.png'

And so on...

How would I then read from this text file and then create those files using 'new File()'?

Here is my code:

private void getFiles() throws IOException{
files = new File[10];
Scanner scan = new Scanner(new File("files.dat"));
int count = -1;

[Code]....

It does print out those files, but it doesn't create them.

View Replies View Related

How To Create Jar File Of Program With Text File

Jan 29, 2015

i have made one desktop application with swing and i have uses one textfile (File) in it. i want to handover to another friend to use it . How to create jar file of that program with that text file so that my friend use it without any issue . I have made it in NetBeans

View Replies View Related

Conversion Of Excel File Into Text File

Oct 28, 2014

I am a beginner in Java and I have a task of reading excel document and converting it into a text file.

View Replies View Related

Creating Simple Text Editor - Delete Selected Text Inside Text Area

May 13, 2015

This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....

Here is the code..

package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

I/O Of Text File

Aug 20, 2014

i have to make this program that will read a message from another text file and surround each occurence of an abbreviation with <> brackets. and the write the marked message to a different file. The program must beable to read from a text file that contains the abbreviations and a text file that contains the message.

package abbreviationstest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.util.Scanner;
import java.io.FileNotFoundException;

[code]....

View Replies View Related

Can Never Get Whole Set To Appear In Text File

Oct 27, 2014

I'm having 2 problems. The most important one is when I get the multiplication for a number the only thing that goes into the text file is the very last multiplication. I can never get the whole set to appear in the text file. The other issue I'm having is making my program loop so that when i get my first answers i will be able to enter another number.

package multiplicationFile;
import java.util.Scanner;
import java.io.*;
public class Multiplication {
public static void main(String args[]) throws IOException {

[code]....

View Replies View Related

How To Create A Text File

May 10, 2014

File f=new File("c:/FilePractice/text.txt");
f.mkdirs();

and it creates only the folder text.txt.i am trying to create a blank txt file int this folder?what is the easiest way to do it? i try this one also:

[CODE]

PrintWriter writer = new PrintWriter("test.txt");
writer.close();

[CODE]

and its work but the test.txt file created in sort of default folder in my project folder.how can i make it in a folder that i want?

View Replies View Related







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