Forum: Java Nov 17th, 2005 |
| Replies: 5 Views: 2,195 Did the professor tell you what the Gift class is supposed to represent?
If this program is about converting currency, what does a gift have to do with converting currency?
You mentioned that... |
Forum: Java Nov 13th, 2005 |
| Replies: 2 Views: 1,194 The scanner interface can be used to read lines, tokens, etc.
Suppose you want to open a file named "c:\test.txt" using the Scanner:
Scanner sc = new Scanner(new File("c:\\test.txt"));To read all... |
Forum: Java Nov 13th, 2005 |
| Replies: 17 Views: 13,708 You could create a batch file (.bat). This answer is for Windows computers. It is not an executable but it is very simple to make.
Suppose you main method is in the class MyTest. Then create a... |
Forum: Java Nov 10th, 2005 |
| Replies: 2 Views: 3,872 Take $123.30.
1. First you need to separate the dollars and the cents using the substring method of the String class (see code below).
2. How do you convert a hundreds digit? Just put... |
Forum: Java Nov 8th, 2005 |
| Replies: 2 Views: 1,800 Run this code below. See the comments for an explanation. This should help understand what you need to use.
import javax.swing.*;
import java.awt.*;
class TestPanel extends JPanel
{
//paint... |
Forum: Java Nov 8th, 2005 |
| Replies: 9 Views: 2,436 Here is an example that uses max_length.
import javax.swing.JOptionPane;
public class Test
{
public static void main(String[] a)
{
//get first string from user
String indata1 =... |
Forum: Java Nov 8th, 2005 |
| Replies: 5 Views: 1,573 glamo,
See Chapter 7 in this page: http://www.jeffheaton.com/ai/
You need to understand Neural Networks. I would suggest to read the other chapters.
:?: For more help,... |
Forum: Java Nov 8th, 2005 |
| Replies: 2 Views: 1,535 OllieFalle,
Here are a few things that seem incorrect to me (correct me if I am wrong):
1. Your method called userInput shown below has problems
public void userInput ()
{... |
Forum: Java Nov 8th, 2005 |
| Replies: 9 Views: 2,436 Melotron,
Here is an example of the code you need:
import javax.swing.JOptionPane;
public class Test
{
public static void main(String[] a)
{ |
Forum: Java Oct 11th, 2005 |
| Replies: 7 Views: 5,061 Suppose you want to generate 50 unique random numbers from 0 to 100.
//Create an array of size 100 that remembers which integers are taken
boolean[] taken = new boolean[100];
//start count at... |
Forum: Java Oct 11th, 2005 |
| Replies: 3 Views: 1,761 I would suggest to use a 3x3 two dimensional array. Maybe something like
char player[][] = new char[3][3];Then when player 1 wants to use cell (1,2) write:
player[1][2] = '1'; :?: For more... |
Forum: Java Oct 11th, 2005 |
| Replies: 4 Views: 1,250 To check if someone is already in the room use the following code:
boolean isRoomOccupied(int floor, int room)
{
if( array[floor][room] == null )
return true;
else
return... |
Forum: Java Oct 5th, 2005 |
| Replies: 2 Views: 6,637 To add a new node to the end of the linked list you should try:
Node newNode = new Node(characterObject);
if(length == 0)
{
firstNode = tailNode = newNode;
}
else
{
tailNode.next =... |
Forum: Java Sep 30th, 2005 |
| Replies: 3 Views: 4,435 Here is a working example of what you need. Basically it takes commands like 'add node' with name "Child1" to node with name "Parent1". The root must always be referred to as "root".
Run the code... |
Forum: Java Sep 27th, 2005 |
| Replies: 4 Views: 4,416 The while loop only runs one time because of the statement
return itemNo ;Once that statement executes the loop (and the entire method) are ended.
Take out the return and it should work. Why... |
Forum: VB.NET Sep 24th, 2005 |
| Replies: 3 Views: 1,582 Have you tried this code:
Dim strBinary As String = "11111111"
Dim intValue As Integer
Dim iPos As Integer
Dim iVal As Integer
For iPos = 0 To strBinary.Length - 1
iVal =... |
Forum: Java Sep 24th, 2005 |
| Replies: 1 Views: 1,215 There are many problems:
1. Fix mispelling/case errors.
2. There is no unsigned keyword
3. main must be public static
4. f has no return type
5. readLine() returns String not int
6. I have no... |
Forum: Java Sep 18th, 2005 |
| Replies: 4 Views: 20,099 Try this code
double num = 1001.27124;
double newNum = Math.round(num*100.0)/100.0;
System.out.println (newNum); //prints 1001.27
It works because *100 shifts the numbers to the... |
Forum: Java Sep 16th, 2005 |
| Replies: 2 Views: 2,422 Override the paint method and use the translate method of the Graphics object. Remember that translate(100,100) doesn't mean goto point 100,100. It means move to the right 100 and move down 100.
... |
Forum: Java Sep 15th, 2005 |
| Replies: 2 Views: 1,561 Check out these two links. Hope it helps.
http://www.falkhausen.de/en/diagram/html/javax.swing.JComponents.html
http://www.falkhausen.de/en/diagram/html/java.awt.Components.html
For more... |
Forum: Java Sep 14th, 2005 |
| Replies: 3 Views: 8,881 You can use the String classes replaceAll method. Here is an example:
String str = "Hello blank";
String newStr = str.replaceAll("blank", "Jim") ;
System.out.println(newStr); //prints "Hello... |
Forum: Java Sep 14th, 2005 |
| Replies: 4 Views: 1,351 Firstly,
The line with the code
if((tokens.hasMoreTokens()) );is basically useless. This checks if there are tokens and does nothing. What you want is
if((tokens.hasMoreTokens()) )
{
//put... |
Forum: Java Sep 14th, 2005 |
| Replies: 3 Views: 1,574 You received a NullPointerException because the array possibleseq is always null and you end up using it in your code.
The best solution is to create an ArrayList by writing
ArrayList... |
Forum: Java Sep 12th, 2005 |
| Replies: 8 Views: 8,135 Your image is not being found. Probably the directory "C:/MyDocuments/MemoryGame/woodTable.gif"; doesn't exist.
If its in your documents folder then the correct directory would be:
C:/Documents... |
Forum: Java Sep 12th, 2005 |
| Replies: 10 Views: 3,879 Each row contains a persons info. The best thing to do is create a class that holds each row. Here is an example:
class PersonInfo
{
private String name;
private int age;
private String... |
Forum: Java Sep 2nd, 2005 |
| Replies: 9 Views: 2,342 The hardest part is knowing how to store & structure the information once it is read.
Firstly, the program must be able to quickly answer the following question: Give me all info on a subject... |
Forum: Java Sep 2nd, 2005 |
| Replies: 1 Views: 1,250 Polymorphism means many forms. The idea of polymorphism is very important in OOP. Lets look at Java's IO classes (they use a lot of this concept).
The code below is legal:
//The inputstream r... |
Forum: Java Sep 2nd, 2005 |
| Replies: 9 Views: 2,342 Why do you need to store all the lines? Couldn't you just maintain the average of the numbers in a variable.
For example,
create a total & amount variable (for the average... average =... |
Forum: Java Aug 30th, 2005 |
| Replies: 7 Views: 3,624 == has many meanings
1. When comparing simple data types (int, char, double, bool, etc), == compares the value of the two.
int x = 1;
int y = 2-1;
System.out.println( x == y ); // ****... |
Forum: Java Aug 30th, 2005 |
| Replies: 4 Views: 32,245 Here is a quick & simple example of showing an image in java. The most import code is in the paint method. In this case, we are redefining the way a usual panel draws itself. The class ImagePanel... |
Forum: Java Aug 30th, 2005 |
| Replies: 3 Views: 1,287 For the first problem, you must use two for loops. Lets call the horizontal direction i and the vertical direction j.
Notice how the #'s change 10 times from 10 to 100 in direction i
Notice how... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 When you ran the program you got an error message. It also gave you a line number on where the error occurred. This line should be commented (put // in front of the line). Run the program. Notice the... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 Try to comment the line that causes that error. You are adding the wrong thing to the applet or the jframe
The blank jframe is created herepublic void init()
{
JFrame JavaAirlines = new... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 change the line JavaAirlines.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);toJavaAirlines.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);Why are you showing a blank JFrame with the applet?
For... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 How are you running the applet? Are you using the applet viewer or using IE? Try to use the applet viewer and it should give some error messages.
To use the applet viewer, go into the command... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 I believe, the method public void JavaAirlines3() is not being called. This method is the one that puts all the radio buttons, etc. into your frame.
Call this method from your init() method.
... |
Forum: Java Aug 12th, 2005 |
| Replies: 16 Views: 5,306 This is an simple example on implementing the ActionListener interface.
class MyClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{... |
Forum: Java Aug 12th, 2005 |
| Replies: 9 Views: 2,092 Here is a test class to get you started. I think this should help you.
import java.io.*;
import java.util.*;
class Bytes
{
public static void main(String[] args)
{
try |
Forum: Java Aug 12th, 2005 |
| Replies: 4 Views: 12,442 Maybe you should try setting the maximum heap size for the JVM.
java -Xmx256m MyClassYou can put higher values if needed.
For more help, www.NeedProgrammingHelp.com |
Forum: Java Aug 12th, 2005 |
| Replies: 6 Views: 1,549 Here is the code you need. Read the comments to understand it.
public static void talk(String numbersAndLetters)
{
//go through the string's characters
for (int i = 0; i<... |