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


ADVERTISEMENT

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

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

ToString Method Won't Work

Oct 4, 2014

So I'm working on a project and noticed that my toString() method won't work. This is just an example of the type of code that I have in my real project. THIS IS MY MAIN CLASS

XML Code:

package trialanderror;
import java.util.Scanner;
public class TrialAndError {
public static void main(String[] args) {
Scanner keys = new Scanner(System.in);
String name;
String phonenumber;

[code]....

View Replies View Related

Converting RGB Value Into Hexadecimal In ToString?

Jul 15, 2014

how to write the toString to convert this output :

List:
side: 14 color: java.awt.Color[r=0,g=0,b=255]
side: 18 color: java.awt.Color[r=255,g=0,b=0]
side: 12 color: java.awt.Color[r=255,g=255,b=0]
side: 18 color: java.awt.Color[r=255,g=0,b=0]
side: 16 color: java.awt.Color[r=0,g=255,b=0]
side: 10 color: java.awt.Color[r=255,g=200,b=0]
side: 10 color: java.awt.Color[r=255,g=200,b=0]

to this output

side:14 color:#0000FF
side:18 color:#FF0000
side:12 color:#FFFF00
side:18 color:#FF0000
side:16 color:#00FF00
side:10 color:#FFC800
side:10 color:#FFC800

here is how i have it written now

public String toString()
{
return "side: " + side + " color: " + color + "";
}

View Replies View Related

Converting Object ToString

Apr 21, 2014

I am trying to display the contents of my Object but when I compile it I get this:proj4.TellerQueue@1db9742

I am pretty sure it's because I havent created my own toString method but I could be wrong. If this is the case, what do I need to do to properly display the variables of my object? Right now my class, BankQueue, contains another object called Person, which contains a String and int variables. I want to do something like this:

class BankQueue{
Queue<Person> q = new LinkedList<Person>();
public String toString(){
return q.;//display contents of the q

[code]...

but Im not sure how to convert these into Strings.

View Replies View Related

How To Overwrite A ToString Method

Apr 12, 2012

How to overwrite a toString method

View Replies View Related

How To Implement ToString For Arrays

Mar 3, 2015

I really want to know it. When we write ...

>>> Student s = new Student("Roll No", "Name");
>>> System.out.println(s);

Then it gives output according to the way that toString() of Student is implemented,right ? What if I wanna do the same for arrays?? I mean to ask, let us say I have array int[] arr = { 1, 2, 3, 4, 5}. When I say System.out.println(arr), it should give the output as it gives for collections [1,2,3,4,5].

I know that Arrays.toString(int[]) can work for us in this regard. But my question is that can we write our own toString() method so that when I print the "arr" (an Object itself) it should call the toString() that we implemented like a callback function.

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

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 View Related

ToString Returning Last Character Doubled

Apr 27, 2015

To string Returns the last character doubled ... How do i stop it from doubling the last number?

public class CreditCard
{ char c = 0;
public CreditCard(String cardNumber)
{
for( int i=0; i<cardNumber.length(); i++)
{
c = cardNumber.charAt(i);

[Code] ....

View Replies View Related

Outputting 2 Classes - ToString Method

Apr 22, 2014

My current assignment involves me outputting these 2 classes. Yet I'm not really sure in what manner I should go about doing this. I have tried creating a separate class and outputting my toString methods there but for some reason I am getting an error. .

The error message is thus;

Exception in thread "main" java.lang.NullPointerException
at Vehicle.toString(Vehicle.java:91)
at Run.main(Run.java:17)
 Process completed.

import java.util.Calendar;
public class HireContract {
String reference;
Calendar startDate = null;
Calendar endDate = null;
Vehicle vehicle = null;;
String customerRef;
double rate;

[Code] .....

View Replies View Related

Each Class Should Override The ToString Method

Nov 10, 2014

Write TestCabAppointment,java class where you will instantiate new CabAppointment objects and read data from RandomAccessFile and create CabAppointment objects and save them in RandomAccessFile You may use FixedLengthStringIO,java class, ICabAppointmentRecord.java interface. Complete the ReadWriteRandomAccessFile.java

CabAppointment.java (this class extends Appointment class)
private int id;
private Address startAddress;
private Address destinationAddress;
private String terminal;
private String description;

[Code].....

View Replies View Related

Overriding ToString - Indicate Whether Coin Is Face Up Or Down

Jan 2, 2015

what im trying to do is modify the Coin class to override the toString() method so that it indicates whether the coin is face up or face down. For example, "The coin is face up." This is what i have so far:

public class Coin {
public static void main(String[] args) {
Coin coin = new Coin();
for (int i = 0; i < 1; i++) {
coin.flip();
System.out.println(coin);

[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

How To Pass A Loop In Method String ToString

Apr 7, 2014

I am looking to pass a long list of results in a String toString() method,this is my code

public void newlist(){
for(int i = 0 ; i <= nbComposant;i++){
System.out.print(ref+i+" (quantity "+quantity+i+")");
}
}
public String toString(){
return newlist();
}

View Replies View Related

Overriding Java ToString Method For Web Browser

Mar 14, 2014

How do i print override the toString for WebBrowser as i would like to print out the object bc. Tested the program and it is fine if i put it in the main method rather than the WebBrowser constructor.

import java.util.*;
class ListNode <E> { /* data attributes */
private E element;
private ListNode <E> next;
/* constructors */
public ListNode(E item)
{ this(item, null);

[code]...

View Replies View Related

Linked List Queue ToString Method

Oct 21, 2014

So I have to write all the methods for a LinkedListQueue. I've got isEmpty, enqueue and dequeue working correctly (I think) but I'm having trouble with the toString method. I tried to do it recursively and it works if there is only one element in the list, but with multiple elements it throws a StackOverflowerror exception. I've tried it multiple different ways, but I can't seem to figure out how to print it out with out clearing everything. We haven't been taught StringBuilder or .append yet, which I saw a lot of as I was looking for solutions, so I can't use those.

public class LinkedQueue<T>
{
protected LLNode<T> front; // reference to the front of this queue
protected LLNode<T> rear; // reference to the rear of this queue
private T info;
public LinkedQueue()
{
front = null;
rear = null;

[Code] ....

and this is the ITD used with it, for some reason it has the "empty the queue" function as a choice but we weren't assigned that function, so just ignore it.

import java.util.Scanner;
public class ITDLinkedQueue
{
public static void displayMenu()
{
System.out.println("(1) display menu");
System.out.println("(2) check isEmpty");
System.out.println("(3) enqueue");
System.out.println("(4) dequeue");

[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

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

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

Java Project - UPC Calculator / Calling ToString Method?

Feb 20, 2014

Our goal is to write a pretty simple program, one that takes the 12 digit UPC code entered by a user and to not only spit it back out in a format with dashes using toString, and also returns the first digit, a 2 more groups of digits numbering 2-6 and 7-11, and finally display the 12th digit. It then performs an equation to check the last digit and make sure the UPC code is correct.

However, being so new to java (I only learned visual basic before), with this I was introduced to two new concepts that for some reason I simply cannot grasp for the life of me: Using and calling the toString method, and calling on methods that are created in a completely different class file.

The first section of code is my UPC class, which is meant to contain all my methods as well as the toString to be called on:

public class UPC
{
// Instance variables
private int itemType; // digit 1
private int manufacturer; // digits 2,3,4,5,6
private int product; // digits 7,8,9,10,11
private int checkDigit; // digit 12

[Code] .....

View Replies View Related







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