Philip Herzer

Greenhorn
+ Follow
since Oct 21, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Philip Herzer

CAn I think of the static keyword as:

1) A global members common to all instances of that class.
2) a static variable or method can be accesed outside of a class eventhough no instances of that class exist.

So I can apply this to constant variables and methods that I do not want to change, right?

Can someone give me a situation when to use a static method?

Also, can someone comment on my first question in this post? Thanks.
[ January 06, 2005: Message edited by: Philip Herzer ]
19 years ago
My question is referring to this following code, based on a very simple card game. I was wondering if it is more common to access and instatiate members of an object referring to a type class card by directly referencing the reference variable p1 & p2, like I have done in onecard.java?
(referenceVariableName.memberName)

My instructor is insisting that we include the name of our class, for example:
card p1 = new card();
card.init(gen,p1) // instead of
p1.init(gen,p1)

Second question, can somebody put into lamen terms what the 'static' keyword is and when to use it? I noticed that variables outside of Main() require the static require that keyword

Thanks,
Phil

card.java:


onecard.java:

[ January 06, 2005: Message edited by: Philip Herzer ]
19 years ago
Stephen, what I've heard is that it will be released first quarter of 2005, around March.
20 years ago
I get the same error on a Solaris and Mac OS X box. How can I get these NumberFormatExceptions to dissapear.

I can run them from the console with java fine. Is there a way to configure in netbeans so I can run the program without worring about these errors?


Thanks,
Philip
I'm having trouble running a simple program within Netbeans. Everytime I run it, I get errors saying I need to catch or throw an IOException. I modified my method that asks for user input to throw the exception, and I included the throws IOExcpetion, also in my main method.

The errors I'm getting now are these:


I am able to successfully build but not run the app. IT works fine when running it under the console. I am using Netbeans 4.0 beta 2 with the Sun J2SE Development kit 1.5.0 .

Thanks,
Philip
two questions arose while trying to simplify my work above and divide the program into functions. I've seperated my functions into these: 1) calcuate the prize_door, and the two booby prize doors; 2) ask for users input; 3) decide which door to offer to open for user and ask him if he'd like to stay or switch; 4) decide if he won or lost.

My dilema is how to pass more than one variable if, for example, function one is like this:


I tried to test whether this thing works in theory by having System.out.println(prize_door + " " + door2 + " " + door3);

I kept getting the error that the variables were not initialized.

My second question doesn't have to do with functions.

If I don't set the variable to 0 for door2 or door 3, I will get the message that the variables may have not been initialized. In theory, they would have been initialized after running the while loop, since I had originally set my boolean variable num_check (it controls the while loop) to false.

Why is this so? IN my function above, will I also need to instantiate the variables and set them to 0 like I did in the second code branch?

Thanks again, for everyone's help. This concept of these local variables and making them aviable outside of the function is a little bit different from what I've learned while using python for several years.

Many Thanks,
Philip
[ October 15, 2004: Message edited by: Philip Herzer ]
20 years ago
Thanks everyone for your help and suggestions. I rewrote the program to incorporate functions, and cut down the the repetive code.

I was wondering if anyone has any good suggestions on books that I could that would cover algorithims dealing with commnon computer algorithims used in programming for Java. I'm looking for something more thorough and deep than a cookbook.


Many Thanks,
Philip
20 years ago
Here's the way according to the first two replies to my post:



It's rather rough. Michael Doen, thanks for the suggestion. I'll try that way also and use arrays.

Any comments or suggestions on the above code would be greately appreciated.


Thanks,
Philip
20 years ago
Thanks Marc for your help. But, what happens if I get a 2 (meaning door) for the prize door? Than, we need to randomly pick a number that is either 1 or 3. I wonder if there is a way in Java to generate a random number and exclude certain values.

Lastly, after that number is generated it should be stored in open_door and remaining value will be stored in other_door.

I'm thinking a long switch statements, buried in if statements.

I'll go bury through the javadocs again.
20 years ago
I'm really into number theory and solving problems like this. I have covered the first six chapters of How to Program: Java, sixth edition. These chapters cover the basics of input/output, control structures (if, switch, do/while, while, for, etc), and functions. So, I want to stay within those elements to work on this problem.

The problem is based on Let's Make a Deal program that used to be shown in the seventies. First of all, there are three doors. Randomly, behind one door, there is a good prize. The other two doors contain bad prizes. The contestant, or user, is asked to choose door number 1, 2 or 3. Then,the user is shown one of the booby prize doors. Here, there are two cases. If the user selected the good door the first time, then one of the other two remaining booby prize doors are opened randomly. If the user selected a booby prize door, then the other booby prize door is opened.

Now we have two closed doors. One that was chosen by the user, and the one that was not opened. The user is then asked if he/she would like to switch doors.

Finally, the user's door is opened, either revealing a good prize or a booby prize.


Here's what I have written so far:


The part I'm stumped on is after generating the random door for the golden prize, how can I make it random for the other two doors. For example, if the golden door is 3, than all we have to do is

This situation works will if it is three, but not so good if we got a two for the golden prize door or 1. What if we were to hava n+1 doors, for example 200, 300, or more doors?

I would appreciate in helpful suggetions on how to approach this problem

Thanks,
Philip

[ October 12, 2004: Message edited by: Philip Herzer ]
[ October 12, 2004: Message edited by: Philip Herzer ]
20 years ago
I'm trying to write my own Craps game. It is very limited, just to help me get the idea of control structures within java. I tried using nested ifs, but failed to do it properly because in my crap game, the 2nd and 3rd rolls still occur regardless if the player wins in the first rolls, second, or third.

My second attempt was trying to seperate the stuff using switch and using a while control loop. I would appreciate any help on the first attempt and suggestions for improving my second attempt.

First Attempt:


Second Attempt


Thanks,
Philip Herzer
[ September 23, 2004: Message edited by: Philip Herzer ]
20 years ago
Thanks for all the helpful suggestions. I will focus most of my attention on mastering java, than will try to go back to C++. Hopefully I will gain a better understanding of OO principles that will make me a good programmer.
As far as Assembler, if Im corrent the syntax between x86 and ppc be different? I assume so, because the system calls and number of registers differs on each processor. Wouldn't it be hard to learn assembler on PPC. Doing a google search, not to many resources on ppc assembler on linux for beginners . But, just learning an overall approach wouldn't be bad, and could be very benifitial.
Off, to the Deitel & Deitel book !
20 years ago
There are was to mix C++ and Java code. One way I am somewhat familiar with is to use a glue like language like Python. You could write some objects in java, others is c++, c, or whatever language, and use Python to glue them together. Here is a link to an article on how Python does it.
There is also a program called Jython that you could use Pythons interpreter embedded inside of java apps.
[ February 12, 2004: Message edited by: Philip Herzer ]
20 years ago
I find programming different tasks or problems to be very helpful. What I've done for the past three months was to go on the net and find sample problems and also take the problems from the Deitel books and program them in C++ and Java. I've been able to master most of the fundamentals: control structures, writing functions, and arrays in C++ and Java this way. I hope that when I get into more advanced topics like polymorphimism, data abstraction, operartor overloading. Is the way I'm doing it a good way to master two things at once? I really want to learn C++ because I plan to do advanced studies in computational finance.
Now, it's just working on doing monte carlo simulation in C++ and Java
20 years ago
I have the Deitel version of Programming in C++ and Java. I found that the problems are very simular and that I could learn both languages at the same time by programming the examples in C++ and than in Java. I'm just having problems with polymorphism, pointers, and some oo principles.
TIJ, from what friends tell me, is a very good book. I read the first few chapters, before I decided to delve into C++. The book assumes you have sufficient knowledge of C or C++. If you would like to learn from the book, it would be good to start learning C before diving full headed into TIJ.
20 years ago