BestJewSinceJC 700 Posting Maven

I believe the String class has a toCharArray method that would help you. Then every 3 indexes are what you are looking for. Otherwise, use a for loop to add every substring of 3 chars to an array.

BestJewSinceJC 700 Posting Maven

Ah, sorry, I only glanced over the assignment and missed that requirement. You could change your if() criteria to check that the box is big enough to hold the item. If it's big enough, check against the one you have already found to see if the current box is smaller (or if foundBox is null). If it is, set 'foundBox' to the current box. When you're done, 'foundBox' should contain the smallest box that will accommodate the dimensions you specified.

@ OP: If your post prior to this one is referring to what Ezzaral said, the if statement pseudocode would probably look like this...

if(Box Height >= Item Height && Box Width >= Item Width){
//Do what ezzaral suggested in here.
}

Of course, you will have to replace the statements I made with equivalent code statements. And out of curiosity, why are you using a 2D box instead of a 3D box?

BestJewSinceJC 700 Posting Maven

thanks very much but can you give me a suggestion for the regular add and minus methods i tried to do

this.add2(bad)

but the program didnt compile
thank you so much for your help

I looked at your add2 method and your add method. They both look like they will compile. What error are you getting? Post the entire error & your code again in code tags

BestJewSinceJC 700 Posting Maven

My internets freaked out. Triple post - sorry guys.

BestJewSinceJC 700 Posting Maven

My interwebs freaked out. What do I do? (Triple post, sorry)

BestJewSinceJC 700 Posting Maven

The code tags are just the following:

for the first one and the last one is exactly what gets pasted in there when you click the button. So all you're adding is the =Java.

And you didn't set your previous thread to solved. While I don't mind helping you, these are both things that you should be doing out of courtesy.

On to the programming, I can come back and give you some more help tomorrow. For now, you might want to consider that "cents" can be much greater than 200. It looks like your code in the add method will not work if cents is > 200. (Lets say you had 0 dollars, 200 cents. Your code would convert that to 1 dollar, 100 cents - but it should convert it to 2 dollars.)[CODE=Java] for the first one and the last one is exactly what gets pasted in there when you click the button. So all you're adding is the =Java.

And you didn't set your previous thread to solved. While I don't mind helping you, these are both things that you should be doing out of courtesy.

On to the programming, I can come back and give you some more help tomorrow. For now, you might want to consider that "cents" can be much greater than 200. It looks like your code in the add method will not work if cents is > 200. (Lets say you had 0 dollars, 200 cents. Your …

BestJewSinceJC 700 Posting Maven

Not trying to be rude, but that still does not make sense to me. Maybe you should try writing a full explanation of what your program does.

BestJewSinceJC 700 Posting Maven

You forced them to input a row between 1 and 3 and a column between 1 and 3. Your array has 3 rows and 3 columns. Arrays in Java (and most other languages) are indexed from 0 to (rows-1). Which means that your array's first cell is _board[0][0], and _board[3][3] is NOT a valid row or column.

In your makeMove method, you should convert rows and columns so that they can be used to index the array. Since the first row is indexed by 0, not by 1, all you have to do is subtract 1 from whatever the user inputs.

BestJewSinceJC 700 Posting Maven

FYI, to add to what Ezzaral said, the clone method makes a shallow copy, not a deep copy. So it will just be a reference to the same object, not a new copy of the object. If you want to make a new copy of an Object, which is NOT the same reference, override the clone method or make your own method.

BestJewSinceJC 700 Posting Maven

Didn't we explain to you in the last thread how to use code tags? Under 'Go Advanced' there is a button that says code tags. Use it. Also add [CODE=Java] to the first part.

BestJewSinceJC 700 Posting Maven

I would help if your explanation was coherent. Repost it but this time, make sure it makes sense.

BestJewSinceJC 700 Posting Maven

Writing programs for chess [complex calculations] can be done practicallly only by supercomputers

Sounds false to me. Who told you that? ;)

BestJewSinceJC 700 Posting Maven

No problem. Set the thread to 'solved' if you don't have any more questions. And Darkagn, you should have let him work through it by himself.

BestJewSinceJC 700 Posting Maven

When you use the code tags in the Java forum, where it says

, put [CODE=java] and it will give it Java highlighting and it will number the lines. This makes it easier for everyone to find and discuss things.

Also, I looked through your code, and I noticed one mistake (so far):

[CODE=Java]public static Money add(Money m3, Money m4)
	{
		return (Money m3 + Money m4);
	}

Money is your class name. The method header (the top line where it says public static Money...) needs to say 'Money' because it tells the program what type of Object to expect as a return type, and what type of Objects are going to be passed in to your method. But in the return statement, this is not allowed. But you have another error. . you cannot just add objects. m3 and m4 are 'Money' Objects. m3 has 'dollars' and 'cents' and so does m4. So add up those dollars and cents, then create a new Money Object using your constructor, then return that Money Object. If you do what I just suggested, and called the Money object "addedMoney", your code would look like this:

public static Money add(Money m3, Money m4)
	{

		//You do the adding of the dollars and cents here
//You create a new Money Object, addedMoney, here, using your constructor and the dollars and cents you just added.

return addedMoney;
	}

Your minus method has the same problem that I just described above. And your add2 …

BestJewSinceJC 700 Posting Maven

You can use a for loop to put things into each array index.

BestJewSinceJC 700 Posting Maven

It sounds like you are using netbeans. If you "select" the button so that it is orange, then double click it (or click on 'source'), you will see something that says jButton1ActionPerformed (or whatever the name of it is). Assuming you've already created whatever other window you want to open, and it is in the same Netbeans project, code to open the window would look like this

public void jButton1ActionPerformed(ActionEvent evt){
new SecondScreen();
}

This is assuming your netbeans hierarchy looks like this:

MyProject
-FirstScreen.java
-SecondScreen.java
-ThirdScreen.java

I hope that makes sense. If you aren't using netbeans, my apologies (your use of 'JFrame forms' is netbeans terminology, I think). But I'd recommend reading the swing tutorials anyway, and coding some GUIs without netbeans. It will teach you a lot more than netbeans will.

BestJewSinceJC 700 Posting Maven

Not saying that these data structures are the most efficient, but one thing you could do is read the entire file into a String (would be inefficient), then search by substring. Continuously increase the size of the substring until it either didn't match the word you're looking for or you found a match. If it didn't match the word (lets say you're looking for the word PROGRAM and it says PRA) you would stop there, move the part of the text you're looking at up a few characters, and start over.

I'm not sure what examples the other posters are pointing you towards, but they will probably be the easier route. This is what I'd do if I wasn't going to look for classes and methods that make my life easier.

BestJewSinceJC 700 Posting Maven

Making it an advanced book from the perspective of someone who is just learning Java. :)

BestJewSinceJC 700 Posting Maven

^ Thats a beginner's book? Sounds like an advanced book to me.

BestJewSinceJC 700 Posting Maven

Static methods exist for the entire class -- although I'm not sure if this is technically correct, you can think of it as there being 'one copy' for the entire class. Static methods exist whether or not you create an Object of that class type, hence the reason why you can invoke them the way Ezzaral explained. More about static methods:

http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html

BestJewSinceJC 700 Posting Maven

Absolute Java is a good beginner's book. It covers the concepts with simplicity and clarity, and goes in depth enough that you can explore the concepts further on your own without too much trouble.

BestJewSinceJC 700 Posting Maven

Yeah, I understand. My advice would've been to do all the math by hand and see if the x and y values fall within the desired range. But that works better (if it does actually work).

:)

BestJewSinceJC 700 Posting Maven

So you're saying to create a Rectangle, for example, that does not appear at all on his GUI? Then he can set the position of this invisible rectangle and see if the user clicks there with contains?

BestJewSinceJC 700 Posting Maven

No problem. Don't forget to mark as solved if you don't have any more questions.

BestJewSinceJC 700 Posting Maven

while (coinInsert == '1' || coinInsert == '0.5' || coinInsert == '0.2' || coinInsert == '0.1')
{
coinInc(coinInsert);

sumCoininsert = sumCoininsert + coinInsert;
while (sumCoinInsert < 1.20)
{
System.out.println("Insert Coin==>");
double coinInsert = sc.nextDouble();

}

That code doesn't make sense. Think about it logically. You want to do the following:

While the user hasn't yet paid for their drink, wait for them to put in money, and add up the money that they put in. Stop once they put in enough money and give them their change.

Your code doesn't do this because it has two while loops and you are adding up the money in the wrong place. You can combine your while loops and add up the money properly like this:

while (sumCoinInsert < 1.20 && (coinInsert == '1' || coinInsert == '0.5' || coinInsert == '0.2' || coinInsert == '0.1'))
{
System.out.println("Insert Coin==>");
double coinInsert = sc.nextDouble();
sumCoininsert = sumCoininsert + coinInsert;
}

There may still be some issues (such as the fact that I didn't tell you what to do with your coinInc() method -- I'll leave that to you to figure out) and the fact that the code I gave you will not work since you'll need to modify it to prompt the user to tell you the first coin they are putting in -- but that is the general idea. I'm also not sure how you are giving the …

BestJewSinceJC 700 Posting Maven

Error check your code and tell us at what point your code doesn't work and show us the method where it doesn't work. If you can't do that then you won't get any help.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

That's probably because you didn't import anything. In order to use the class you have to import it. I would guess the import is "import javax.swing.*;". You put imports above your class body.

BestJewSinceJC 700 Posting Maven

If you want help, then identify, specifically, what you are trying to do and why it does not work. We aren't going to scour your program for errors and give you answers. We will help you if you specify what you need help with. Start by dividing your payscale program into logical units. That is, what does it need to do? You've already done so, above:

1. It needs to prompt user for "Hours worked" and "Pay rate"
2. Determine if there is overtime
3. Calculate overtime at "time and 1/2"
4. Calculate regular pay
It must then print out:
1. Total hours worked
2. Regular hours
3. Overtime hours
4. Pay rate
5. Regular pay
6. Overtime pay
7. Total pay

Now, write test code to make sure that those things are working properly. Since your program isn't working, clearly, not all of those work properly. Tell us which one doesn't, and post the code for it. Then we can help you further.

BestJewSinceJC 700 Posting Maven

It would help if you declared main correctly, as

public static void

Also, you might want to check that the variable 'i' doesn't go out of scope after the for loop.

BestJewSinceJC 700 Posting Maven

Or you could think of it in a few other ways. For example

1 * 10 ^ -1 is the same as 1/10^1 or 1/10. It is also equivalent to moving the decimal place back a few spots.

BestJewSinceJC 700 Posting Maven

It isn't working because you never initialized the 'birthDate' variable to the person's birthday.

public int getLeefTijd()
    {
        // make an object with the birth date
        Calendar birthDate = new GregorianCalendar();
        
        if (today.before(birthDate))
        {
            age--;
            Age = age;          // Age is also a field
            return Age;
        }
      
    }

So birthDate just has whatever the default values are. . not the person's birthday like you want it to have. To fix it, you could use this constructor, "GregorianCalendar(int year, int month, int date)" instead of the default no parameter constructor you're currently using.

BestJewSinceJC 700 Posting Maven

if (today.before(birthDate))


You're passing a GregorianCalendar Object to the before method. Are you sure this is correct? I wouldn't really know, but I don't see how a calendar and a day are the same thing.... you should be passing a day to the before method, probably.

edit: Yeah, it seems like you have it correct. Hm

BestJewSinceJC 700 Posting Maven

You could also make an Object that holds a name and an integer. The integer would be timesSeen. Then you'd only need one array. Either way works.

BestJewSinceJC 700 Posting Maven

Therefore, you have to gather information from the maze as you navigate your way through it.

In any case, you somehow have a representation of a maze. If you figure out a different way [other than using a stack or a queue and the algorithm I suggested] to do this program I'd be very interested to see it. But good luck on your project.

BestJewSinceJC 700 Posting Maven

Any Object can be inserted into a queue. Think about it logically - a queue is just a collection of items where the first thing put in the queue will be the first thing to come out of the queue. A line at a grocery store is an example of a queue. The first person to get in line is the first person to get out of the line.

BestJewSinceJC 700 Posting Maven

If that explanation didn't make sense, which I doubt it did, use the maze I gave you above and go through the algorithm. The maze I gave you above is small enough to do quickly but it demonstrates what you need to know about the algorithm. Just go through it step by step and you'll understand it by the time you finish the maze. And yes, the algorithm I gave you is definitely correct. Google Maps uses a more sophisticated, but similar, algorithm.

BestJewSinceJC 700 Posting Maven

1. From whatever cell you're at, check the North cell. If you can go there, add it to your list. Check the South cell. If you can go there, add it to your list. Check the East cell. If you can go there, add it to your list. Check the West cell. If you can go there, add it to your list.

After you do that, if your current cell is named currentCell, and you're using an LinkedList called availableCells, do currentCell = availableCells.removeFirst(). In other words, set current cell = the first cell in your availableCells list, and remove the first cell from the availableCells list. Now go back to step 1. and repeat until you find the finish.


And if you don't have a file to read the maze from, then how are you getting the maze?

One more thing - if you still don't understand how the algorithm works, create a small maze and follow its steps. Once you do that you'll definitely understand. Here's an example, where # are walls, x is start space, o is goal space, and * are spaces you can go to.


#####
# x** #
#*#*#
#** o#
#####

Ok. You initially have a queue. Using a LinkedList for the queue, called availableSpots. You also have a currentCell Object which is initially the start cell. Now, doing the algorithm

1. We look at our current cell (the …

BestJewSinceJC 700 Posting Maven

Yes, you could do this more easily. As an example,

System.out.println("Here's an example for you. " + num + ", " + (num + 1) + "");

Where I have (num + 1) in parenthesis that lets the compiler know that you're adding with the + sign. Otherwise, the compiler would think you're doing String concatenation. (If you take out the parenthesis there, it will print out 01 because it combined the two Strings).

Also, your problem is confusing to begin with. Like I said, and like the person above me just mentioned, do the numbers have to be in a series? For example what do you want your output to be if the person types in 1 and 5? 1, 2, 3, 5?

BestJewSinceJC 700 Posting Maven

I'm just going to link you to the project that I was given back when I did it. It gives you the exact algorithm; you just need to implement it. My project was somewhat different, but the way that you get from the start to finish of the maze is the exact same.

http://www.csee.umbc.edu/courses/undergraduate/341/fall08/projects/proj2/341-fall08-p2.shtml

Go to the part where it says "the algorithm". If you don't understand why the algorithm is used, then ask me. But I do guarantee you that it works. And it's important to understand why it works correctly, so spend a few minutes trying to figure it out on your own, and then don't hesitate to ask questions if you need to.

BestJewSinceJC 700 Posting Maven

I did a project like this, except with more strict guidelines. What you do is use either a stack or a queue. Push the start space onto the stack/queue. Then, push any adjacent cells (that you can move to!) from the cell you're currently at (at first, this will be the start space). Then, pop a cell from the stack/queue and repeat. You will eventually find the finish. If that didn't make sense, you're basically 'looking' at whatever cell you're currently at, pushing all adjacent cells that you can move to on the stack, popping the next cell from the stack, and repeating until you find the finish.

Good luck...

BestJewSinceJC 700 Posting Maven

So the numbers have to be in a continuous sequence? Or is that just a coincidence in the bad example you picked? Because from what you stated, you could just generate four random integers and display them and you're done. Or do two of the numbers have to be the ones the user entered? If so, what do the other numbers have to be... anything, like you said, or some sort of sequence, like your example implied?

Also. . . do your own work. We don't do code for you. Explain your problem better, then attempt to code it on your own. If you have any problems you can ask specific questions that don't say "do this for me", but that say "I need some guidance", and we will answer those. Also, post your code, in code tags.

BestJewSinceJC 700 Posting Maven
if ((x==0)||(y==0))
            return 1;
       else if ((x==1) || (y==1))
                return 1;

One problem lies in the 'else if' part of that code. If you're on the first step, you still have to go down one. That makes a total of two ways. However, since you said 'return 1', you only account for one of the ways, and prevent the recursive call. (Basically, remove the else if portion, I think your code will work better).. you have two base cases where you should only have one.


Also, in your recursive call, why are you subtracting from both x and y? What do x and y represent? I'm assuming x represents the step you're currently on. If so, what does y represent? And finally, I retract what I said previously about needing a parameter to count the total number of ways. That's already taken care of by "return (numWaysToClimb(x-1,y-2)+numWaysToClimb(x-2,y-1));" (Well, it will be once your code works properly)

Also - I apologize for the conflicting advice (about the second parameter). I'm almost positive what I said in this post is correct. When I get to work in a couple hours, I'll code the solution myself to make sure that it is, in fact, good advice. I'm not going to post the solution because that would destroy the point of learning, but I will give you some hints from there if you need it.

BestJewSinceJC 700 Posting Maven

Sorry.. you'd actually also need a second int parameter to count the total number of ways

BestJewSinceJC 700 Posting Maven

Ok, well why do you need your method to take two parameters? If you're always taking one or two steps, the only parameter you should need is the step you're currently on. Then, at the end of the method, you should have two recursive calls (which you do). The one should try to go down two steps, the other should try to go down one step. If you cannot go down anymore, then you should return 0 for that attempt.

BestJewSinceJC 700 Posting Maven

4-5
4-5-6
4-3
4-3-2

I count 4 ways. And the number you start at will never matter if I'm doing this correctly, so whats the point? If I'm not doing it correctly than perhaps you should explain.

BestJewSinceJC 700 Posting Maven

If you expect a solution, please post the exact error code you are getting. It usually includes line numbers and method names, etc.

BestJewSinceJC 700 Posting Maven

It's not necessarily better style/design. And if the job of one function requires another function, then you should call the other function within the first function. You shouldn't use main to do it. And I'm kind of curious how to do this as well, which is why I am upping this topic. Its been a while since I've programmed in C, but I would think you'd just include the one header in the other one. Since you need to compile each file into a .o, I'm not sure where that comes into play though. Guess you'd just always have to link them somehow.

BestJewSinceJC 700 Posting Maven

I'm not sure I understand your class structure, so take this with a grain of salt. You could pass the MainFrame as an argument to AddClientPanel's constructor and then store the MainFrame in a static variable in the AddClientPanel class. AddClientPanel could have a get method that, using the static MainFrame variable, returns whatever info you need. (AddClientPanel is a class, right?)

MainFrame
AddClientPanel ... constructor takes MainFrame variable, then stores it in a static variable. Also has getter.
Other classes ... get Mainframe's info by using AddClientPanel's getter.

peter_budo commented: Thanx for reminder on statics ;) +14
BestJewSinceJC 700 Posting Maven

Just want to comment that you're using this. correctly now. Except in your no argument constructor, "this." isn't necessary at all (although it doesn't hurt, either).

And it looks fine to me. Also, remember to mark solved when you're done asking qns