How To Make A Simple Connect Four Program Without GUI
Nov 19, 2014
My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...
Java Code:
public class Connect
final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){
[code]....
View Replies
ADVERTISEMENT
Mar 11, 2015
i am working on my assignment in Compro 2, we are ask to make a simple calculator program
here's my code;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;
[code]...
View Replies
View Related
May 12, 2015
So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.
For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.
Here is the code:
public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;
[Code].....
View Replies
View Related
Nov 17, 2014
I have to make the connect 4 game be connect 3. Ive edited a code but I the math is over my head. These loop methods check the ways someone can win.
for (int j=0;j<7;j+=2)//need to change
{
if ((f[i][j+1] != " ")
&& (f[i][j+3] != " ")
&& (f[i][j+5] != " ")
&& (f[i][j+7] != " ")
&& ((f[i][j+1] == f[i][j+3])
&& (f[i][j+3] == f[i][j+5])
&& (f[i][j+5] == f[i][j+7])))
//end of loop
[code]....
View Replies
View Related
Sep 17, 2014
I am doing an assignment in my Java class and I need to connect the nodes to make a 12 pointed star. I have already drawn out the star and figured out which nodes to connect together. The only thing I cannot get is to show all of the nodes in the order they connect. I can only get the first 3 nodes to show up. I need it to wrap around and basically keep adding 5 to the last node until all numbers 0-11 are used.
public class StarWinding {
public static void main(String[] args) {
for (int i = 0 ; i < 12; i+=5) {
System.out.print(i + " ");
}
}
}
And the out put so far is: 0 5 10
I need it to be: 0 5 10 3 8 1 6 11 4 9 2 7
View Replies
View Related
May 31, 2014
I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.
import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
[code]...
View Replies
View Related
Jun 18, 2014
I am developing a number of Data Structures in Bluej. Iv created a nice little arraylist program, and want to add a password generator to this program. People are already prestored within the arraylist, and contain attributes such as ID, name, password, etc. I can search a persons name within the list and then view their ID, password, and encrypted password. I want to add a field which will show password strength, bare in mind the password is already stored within the program and will not be entered via the user.
I understand that this could be done via a regular expression, or using some count method where certain goals/sets of characters increase the count which determine strength.
View Replies
View Related
Sep 9, 2014
I want to create simple java application which has 3 text fields and the application will have database connection. Once done, I want to run this application on other systems without using any IDE. So how do I do this? How can I make an application installable on other system so that on clicking on it, it will start executing?
View Replies
View Related
Jan 21, 2014
I'm trying to make a simple Caesar cipher that takes in a String as the first argument and a integer shift as the second argument. Namely, there appears to be a problem with the loop and how I have declared the array - I want the converted characters to be put into a new array called newCharacterArray, converted back to a String and displayed in the command prompt window.
public class Caesar {
public static void main(String inString, int k) {
System.out.println("String: " + inString);
char inStringArray[] = inString.toCharArray();
[code]....
View Replies
View Related
May 24, 2015
I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back
import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
[code]....
View Replies
View Related
Apr 21, 2015
For the latest assignment, my instructor has asked us to create a program where we create lines of at least for integers and if the program registers there being four of the same integer horizontally, vertically, or diagonally it returns true. For example:
1 1 1 1 1 2 3 4 1 2 3 4
4 3 6 2 2 1 4 5 1 5 6 7
8 2 0 3 3 2 1 6 1 3 5 7
4 7 9 3 5 7 4 1 1 8 9 0
If the program doesn't see four integers of the same value anywhere, it is supposed to return false. I've got it so it returns true for the lines above, 6x6 lines of integers and lines where only four out of six+ integers are equal. However, I cannot get my code to return false if there are only three matching integers in a row/column/diagonal nor can I get the program to print out either true or false for lines that do not start at the top left corner. (i.e 2 3 1 1 1 1) For the former I get this error message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at ConnectFour.is4Consecutive(ConnectFour.java:41)
at ConnectFour.main(ConnectFour.java:32)
For the latter:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at ConnectFour.is4Consecutive(ConnectFour.java:43)
at ConnectFour.main(ConnectFour.java:34)
The answer to fixing my code is probably something small or something that will make me wonder why I hadn't thought of it myself... Here is my code:
import java.util.Scanner;
public class ConnectFour {
private static Scanner sc;
public static void main(String[] args)
{
sc = new Scanner(System.in);
System.out.print("Enter the height: ");
int h = sc.nextInt();
System.out.print("Enter the width: ");
[Code] .....
1 1 1 1
4 3 6 2
8 2 0 3
4 7 9 3
1 2 3 4
2 1 4 5
3 2 1 6
5 7 4 1
1 2 3 4
1 5 6 7
1 3 5 7
1 8 9 0
View Replies
View Related
Apr 5, 2014
I want to connect java program with Ms access.
View Replies
View Related
Feb 16, 2014
I started with Eclipse and wrote the basic "Hello World" app and added a few other lines of a=5, b=9, println (a*b) etc. and ran the program in the screen.
Then I thought that perhaps I could move it onto my nexus 7 and see what it looks like there. [I have a lot to learn I suppose].
The first issue is that I can't connect my Nexus 7 tablet to me macbook pro without using "android file transfer" and then the computer does not show the device in the finder because it is running through the file transfer program.
I have done some research and changed the settings in the nexus to connect as a camera rather than storage but that doesn't work either.
So my main issue now is being able to get the program onto the device - can it simply be copied and pasted into one of the files on the device using the file transfer screen?
View Replies
View Related
Nov 23, 2014
I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)
I've created two classes
import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;
[code]....
View Replies
View Related
Dec 14, 2014
I have my program set up I thought correctly. When I click the buttons, nothing is happening.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RobertMaloneChapter18 extends JFrame
{
//set final sizes for window
private static final int WIDTH = 300;
private static final int HEIGHT = 200;
[code]....
View Replies
View Related
Jun 28, 2014
I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result.
package asgn2;
import acm.graphics.*;
import acm.program.*;
public class pyramid extends GraphicsProgram {
private static final int BRICK_WIDTH = 30;
private static final int BRICK_HEIGHT = 12;
private static final int BASE_BRICKS =14;
[code]...
View Replies
View Related
Apr 9, 2014
This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:
- 1st Class
import java.util.Scanner;
public class Main {
public static int num;
public static int total = 0;
public static int average;
[Code].....
Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.
View Replies
View Related
Mar 26, 2015
I'm trying to read lines from a textfile and count all the words using String Tokenizer. However I keep getting an error "Unhandled exception type FileNotFoundException" on my IDE(Eclipse) referring to lines 13 and 8. When I let the IDE automatically, and I've even tried typing this manually, insert a try-catch block more errors show up concerning inputFile. When I insert the throws FileNotFoundException for each method it compiles but after running it gives me a FileNotFoundException for textfile.txt. What's even more interesting is that when I copy the .java file out of the IDE project folder, place it in a random empty folder on the Desktop with the textfile.txt, and try running it through command line, it gives a NoSuchElementException: No line found.
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
[Code].....
View Replies
View Related
Nov 1, 2014
I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far. I'm kind of lost on what to do next in the code.
import java.util.Scanner;
/*Program that encrypts then decrypts a sentence
Encryption
*/
public class Encryption extends java.swing.JFrame{
[code]....
View Replies
View Related
Jan 22, 2014
I am having a difficult time writing what started out as a simple vending machine program. As I go on though, it seems that I'm overcomplicating it and it is getting messy, so I have resorted to the forum before I really get off the path. how to clean it up? I'm going to list a few of the problems I am having with the code below:
1. The user is supposed to enter his/her money and the program is to read each value separately (Do-While loop) and keep a running total of the money entered. I can't seem to get the right code format to do this. I was trying to do this with the variable total and so that is why the total exists in the switch statement, but it did not work.
2. In the second Do-While statement, is there a way to kick back an error when their are insufficient funds to purchase an item? Instead of getting a negative change return.
package practice;
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double count, total;
int item;
//Display Available Options To Customer
Scanner input = new Scanner(System.in);
System.out.println("*VENDING MACHINE*");
[code]....
View Replies
View Related
Sep 13, 2014
I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.
Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.
Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg
I wrote 7 classes:
Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.
What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:
Intersection sec = new Intersection(ray,(Mirror)obj);
creates an intersection with a null point.
I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).
I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.
I've found out that my function:
public PVector getNormal(PVector D){
D.normalize();
return new PVector(D.y,-D.x);
}
Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!
The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:
Optics: (note line 64. this line returns a null intersection when it shouldn't)
package ofer.davidson;
import java.util.ArrayList;
public class Optics {
//Arrays to store all the optics objects and rays that are created
ArrayList<Object> objects;
ArrayList<Ray> rays;
[Code] .....
Also why doesn't my background turn white??
View Replies
View Related
Apr 26, 2015
Write a program to simulate the operation of a simple robot. The robot moves in four directions: Forward, backwawrd, left, and right. The job of the robot is to move items and place it in the right slots in each station. There are 8 stations plus the pickup station. Pick up station is the initial start where the robot picks the items. 8 items can be placed on each station. The nearest station must be filled before placing items on the next station. The items are marked with identification or serial numbers. The items with odd serial number go to the right and items with even number go to the eft. The last slot, number 7 is reserved for light items which are less than 80kg. The serial number is a five digit number, the MSB digit 5 indicates that the product must be placed in the fifth station which is keeping the product at 20 degree F.
View Replies
View Related
Aug 12, 2014
I need getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).
With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).
The requirements of this program are:
-Create a class that will hold methods to calculate the interest. Do not include the main method in this class.
-In the class that is used to calculate the interest, include a method to print to the screen, by interest period, the starting amount for the period, the interest earned for the period, and the total amount at the end of the period. Note that each period represents the time frame for how often it is updated. If annual is selected the period is every year. If it is semi-annual it is every six months. If it is quarterly it is every three months.
-Create a demo class that will use your interest calculation class. Prompt the user for the original amount, the type of interest (simple or compound), the annual interest rate, and whether it is updated annually, semi-annually, or quarterly. Use method calls to your calculate interest class to do all calculations and display the result. Loop the program until the user chooses to quit.
Sample output ($10000 initial investment, 10% simple interest, annual, for 4 years):
Period Beginning Amount Interest Earned Ending Amount
1 10000.00 1000.00 11000.00
2 11000.00 1000.00 12000.00
3 12000.00 1000.00 13000.00
4 13000.00 1000.00 14000.00
View Replies
View Related
Feb 13, 2015
When I Start Server and login from client everything goes fine but as soon as I want to send amessage or use showIn or even logOut .
Get below error
Exception creating new Input/output Streams: java.io.EOFException
View Replies
View Related
Mar 21, 2015
I am creating a simple ArrayList program that would enable one to input their username to it using a scanner. However, i am getting this error: "Exception in thread "main" java.lang.NullPointerException
at home.Members.addUser(Members.java:16)
at home.Main.main(Main.java:14)"
Here is the code! :
Main.java class
Java Code: import java.util.Scanner;
public class Main {
[code]....
View Replies
View Related
Feb 8, 2015
I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.
This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY
Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:
public class SimpleEncryption {
/**
* @param args the command line arguments
*/
static int answer;
public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses"
+ " a basic cipher shift.");
[code]....
View Replies
View Related