|
creating a cell class.
The first should be called Cell. It represents one cell (square) of the tic-tac-toe board. It should contain at least one property, the character which occupies the cell. You may use either a blank character (‘ ‘) or a null to indicate an empty Cell, but I think you will find that the blank works better. Cell must also contain the following methods:
Constructor - create the cell and initialize the letter in the cell.
void setCell( char letter) - set the value in the cell.
char getCell( ) - return the letter in the cell.
boolean isEmpty( ) - return true if the Cell holds a blank, false otherwise.
|
|
|
|
|
so, what's your question exactly ?
are you totally stuck with it ? or have you already started something ?
as you might know (you are not supposed to ignore the rules out there), we don't do homeworks...
|
|
|
|
|
I would start by creating a text file named after the class you are supposed to create, but with the appropriate extension for a source code file.
We will call this the source code file.
Inside that file, I would declare a class using the standard class declaration syntax, which you can find if you look at any Java HelloWorld program.
Inside that declaration, I would declare 4 methods (or 1 constructor and 3 methods, if you prefer) using standard constructor/method declaration syntax. Again, find a HelloWorld program. Better still, see the last 4 lines of your question, where you have everything but the braces {}.
You would also like to have at least one member variable (the property), which you can name Harvey. Harvey, I think you will find, works better than Fred. But you can call it Fred if you must. Never call it Farqhuat, because people will laugh at you.
The constructor should ponder the existence of itself, asking such things as "Why am I here?", "Who made me?", "Of what use am I?", and "Does peanut butter always have to have jelly to make a good sandwich?" You should not code any of that, but it must be implied. See Webster's Dictionary for an example of implying.
The setter method should ideally set something, and the getter method would, in a perfect world, get that thing. It's up to you to make the world perfect.
The test method, on the other hand, should not lie about the contents unless it is a Tuesday.
|
|
|
|
|
|
Hi to all, I need some help in getting the union of of 2 interacting polygons.
Currently I have managed to draw 2 polygons p1 and p2, and I got stuck on getting the unions between the 2 polygons. I have tried using the java.awt.geom, but later realized that the geom package can only be used for regular shapes.
This is part of my code:
Polygon p1 = new Polygon();
for (int i = 0; i < 5; i++)
p1.addPoint((int) (200 + 50 * Math.cos(i * 2 * Math.PI / 5)),
(int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));
g.drawPolygon(p1);
Polygon p2 = new Polygon();
for (int i = 0; i < 5; i++)
p2.addPoint((int) (160 + 50 * Math.cos(i * 2 * Math.PI / 6)),
(int) (60 + 50 * Math.sin(i * 2 * Math.PI / 6)));
g.drawPolygon(p2);
Please help. Thanks.
|
|
|
|
|
|
1) we don't do homework here.
2) read the forums posting guidelines
3) "the int type has a limitation: it can’t store integer values larger
than 231"
Where the f*ck does this come from ?????
|
|
|
|
|
I would assume that by 231 he means 2^31, which is the limitation for a signed int.;
As for the question, what you are going to have to do is remember back to gradeschool, when we did longhand arithmetic.
1001
2009
----
3010
Write out psuedo code on how to do this, then implement it. isValidBigInt should be easy.
|
|
|
|
|
TannerB wrote: I would assume that by 231 he means 2^31
this is fundamentaly different, and moreover, WRONG.
the higher value an unsigned int can take is (2^32)-1, which is 4 294 967 295.
|
|
|
|
|
Thanks, must of had a brain fart when I read it.
|
|
|
|
|
As far as I remember, there is only signed int in Java, so its maximum value would be (2^31)-1 (2,147,483,647).
My LinkedIn Profile
|
|
|
|
|
I've got this here code I just started today for an assigment, it is all working (so I'm not asking you to do it for me :P). What this code does is it considers any @ to be a backspace and deletes the character before it. I was supposed to use indexOf() and substring() but I thought using regular expressions would be simpler, and a learning experience at the same time. I think my problem right now is that I have stared at it for too long. What I want is for the loop in main to be ran atleast once but it seems weird to have the while(checkForError(input)); ran and then have it ran again in the method fixErrors . Any thoughts on what I could do to fix this would be welcome. Other comments and critiques are always welcome.
Thanks,
Tanner
EDIT: Update at bottom.
import javax.swing.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class bruce_tanner_A3Q3
{
public static void main(String [] args)
{
String input;
do
{
input = getString("Enter a string");
printOutput(fixErrors(input));
}while(checkForError(input));
}
public static boolean checkForError(String input)
{
Pattern pattern = Pattern.compile("@");
Matcher matcher = pattern.matcher(input);
return matcher.find();
}
public static String getString(String input)
{
String tempString = JOptionPane.showInputDialog(input);
return tempString;
}
public static void printOutput(String tempString)
{
System.out.println(tempString);
}
public static String fixErrors(String tempString)
{
if(checkForError(tempString))
{
Pattern pattern = Pattern.compile("[^@][@?+]");
Matcher matcher = pattern.matcher(tempString);
while(matcher.find())
{
tempString = matcher.replaceAll("");
matcher = pattern.matcher(tempString);
}
pattern = Pattern.compile("@");
matcher = pattern.matcher(tempString);
tempString = matcher.replaceAll("");
return tempString;
}
return "This string is error free";
}
}
I'm not sure whether this was a flash of brilliance or not but it works.
New main code:
public static void main(String [] args)
{
String input;
for(input = getString("Enter a string"); checkForError(input); input = getString("Enter a string"))
{
printOutput(fixErrors(input));
}
printOutput("This string is error free");
}
New fixErrors:
public static String fixErrors(String tempString)
{
Pattern pattern = Pattern.compile("[^@][@?+]");
Matcher matcher = pattern.matcher(tempString);
while(matcher.find())
{
tempString = matcher.replaceAll("");
matcher = pattern.matcher(tempString);
}
pattern = Pattern.compile("@");
matcher = pattern.matcher(tempString);
tempString = matcher.replaceAll("");
return tempString;
}
modified on Monday, November 3, 2008 2:57 PM
|
|
|
|
|
I have a Swing based application which consists of 5 classes.
Now I want to make the whole application as an exe file.
Can some one help me in this regard......
|
|
|
|
|
do you use an IDE ? if yes, which ?
|
|
|
|
|
you can download the jet engine exe file then u can attach the class files and then run which is very very useful jet is available at sun products
Ambedkar Golla
|
|
|
|
|
Use this tool:
JSmooth
The downlodad URL is:
http://www.ej-technologies.com/download/exe4j/files.php
If you don't know the package method send a mail to me. [soief@qq.com]
|
|
|
|
|
how to develop installation web application software using java(servlets,jsp),java script,mysql(database).
|
|
|
|
|
I have this problem,
I need to represent set in the following form
[L,R]
where L is the left hand-bound of the set , and R is the right hand-bound
each of L and R are a collection of sets
for example
L= [{1},{2},{2,3}]
R=[{1,2,3},{2,3,4}]
[L,R]= [{ {1},{2},{2,3} } , { {1,2,3},{2,3,4} }]
how can i do this in java
|
|
|
|
|
There are many ways that you could represent this depending on what you are trying to do. My initial thought is a 2 element array of sets of sets e.g.
Set s1 = new Set();
s1.add(1)
Set s2 = new Set();
s2.add(2)
Set s23 = new Set();
s23.add(3)
s23.add(2)
Set left = new Set{}
left.add(s1}
left.add(s2}
left.add(s23}
/*
* Prepare Right Side now
*/
Set[] allSets = new Set[2]()
allSets[0] = left;
allSets[1] = right;
Do the Sets in L and R have to be unique. Also why are you modelling the sets what do you expect to do with them. If it is a bit more rigid and you want to perform operations on the sets you may want to use a class to model them
e.g.
public Class LeftRightSet() {
private Set<set><string> left;
private Set<set><string>> right;
// Further manipulation classes
}
Hope this helps
|
|
|
|
|
Hi all,
I need to find the coordinates of the selected item in my JList. I'd expect this line of code to be defined in swing, but it's not.
selectedItemY = [JList Name].getSelectedValue().getY();
Any suggestion?
Thanks
Naz
|
|
|
|
|
How can I compile my java code without going to a DOS window?
Everything makes sense in someone's mind
|
|
|
|
|
I use NetBeans IDE where every function is visually available. So you never need to use the cmd. You can download it for free.
|
|
|
|
|
KMAROIS wrote: How can I compile my java code without going to a DOS window?
by using an IDE...
the best I ever used is definitely Eclipse:
Eclipse for J2SE[^]
Eclipse for J2EE[^]
|
|
|
|
|
The RAD is better.
but not free.
|
|
|
|
|
Hi,
I've followed this article (http://java.sun.com/developer/technicalArticles/J2EE/AJAX/[^]) to create a Java Servlet and retrieve data from it using AJAX. In this example the doGet method is automatically run and it gives me the required output, however I would like to have additional methods in this class returning different things that I can call on demand, how would I do this?
Thanks in advance
|
|
|
|