Dennis Ouyang

Greenhorn
+ Follow
since Mar 18, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dennis Ouyang

No, sorry. I moved on to other chapters and assignments since I didn't want to spend too much time on this issue. Out of curiosity, do you use Windows 8?
6 years ago
Looks like the below code worked! :



I was using the acm packages since that is how the book and the class that uses it (Stanford CS106) chooses to teach intro java. I used the acm.program.* library again and it was not the problem, I just needed to rename my class to something other than printWriter. Very good thing to know to avoid further mistakes like this, embarassed to admit I spent a good day or so trying to fix a bunch of other stuff that was not broken. Thanks Dave Tolls!
6 years ago
Hi,

I am looking at chapter 12 of the art and science of java intro text and I see the following example code demonstrating how to write a new file:



(I added the imports at top myself.) However, I am getting compiler errors for the lines: , which says that the constructor PrintWriter( FileWriter ) is undefined, and
, which says close() method is undefined. Pretty sure the only real problem is that PrintWriter is not accepting the FileWriter as constructor, but I don't see why. I have tried this on machine with JRE 1.4 and it worked as expected, creating new file titled "hello.txt", prints line of "Hello world!" in that file, and saves it to the directory I picked in the dialog. But I can't get it to work on this machine that uses Compiler 1.6, Java Runtime v8u25.

I have also tried using just a string in the parameter for PrintWriter, such as , and from what I can tell by reading the java spec for java 8, this should work. http://docs.oracle.com/javase/8/docs/api/index.html. But I get error message for that constructor as well.
6 years ago
So I downloaded java version 8 update 25, latest version for windows 8, from www.java.com. As part of installation I uninstalled my old java 7 update 67, then manually uninstalled it again after it still showed in programs and features. Java website confirms I successfully installed that version 8u25. I deleted every sound file in the project folder and downloaded the same .wav you linked me to above, made no changes to .wav file except rename it to "bounce.wav". I refresh eclipse project and run it, and I get the exact same error message.

I keep thinking it must have something to do with my new hardware. I tried playing around with my speakers and sound settings in windows, tried having sound come from the "AMD HD audio device" connected to my monitor. Same problem.
6 years ago
Just tried using another sound file from this link: http://soundbible.com/1120-Bounce.html. (I realize that this is the same link knute directed me to, not sure why I somehow got redirected into downloading adware, of all things. Fortunately I figured out what was happening and stopped installation in time. )

First I tried using it in the default .wav format. Got the exact same error message.

then tried changing the format to .au , restarting eclipse JDK, changing file format to .au in my MediaTools method, refreshing the package and playing again. Exact same error message. Is anyone else getting this on their machine?
6 years ago
Is that file safe to download? I clicked the download link and ran the installer, it tried to install Astromenda and a bunch of other crap on my machine. I know Astromenda is adware.

Also, I am using java 1.7.0_67-b01, according to about menu in the java control panel.
6 years ago
Plays just fine in both windows media player and quicktime. Like others have mentioned, I am definitely not including anything in my code above to set a value for the sound file. Is it possible that this has something to do with my hardware?

Has anyone else tried running the code on their machine to see if they can reproduce?
6 years ago
Hi,

I wrote the below program to set up and play the game breakout as an assignment for Stanford's CS106 programming class. I wrote it on my old mac running OSX 10.6.8, with the version of Eclipse JDK that works on that machine. When I tested it back on the mac, the program worked normally. But now I am using a Windows 8.1 computer with the corresponding version of eclipse, and when I test the program again, the sound effect I coded does not play. I get the following error message in console when the ball hits the paddle or brick, which previously caused the sound clip to play.

Exception in thread "Thread-4" java.lang.IllegalArgumentException: Requested value -120.0 smaller than allowable minimum value -80.0.
at javax.sound.sampled.FloatControl.setValue(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectDL$Gain.setValue(Unknown Source)
at acm.util.SoundPlayer.setLineVolume(SoundClip.java:909)
at acm.util.SoundPlayer.run(SoundClip.java:860)
at java.lang.Thread.run(Unknown Source)

I have no idea what the values it refers to could mean, or why my code would request a value below the min. I am using the mediatools class that is part of the ACM libraries we are required to use for the class to play the sound in question, found here: http://cs.stanford.edu/people/eroberts/jtf/rationale/UtilPackage.html#MediaTools.

I went ahead and tested all parts of the program and the missing sound effect is the only problem. Here is my complete code:

6 years ago
here is my latest attempt. I tried setting the midpoint of the circle each arc is drawn from to exactly halfway between the points you display above. So the midpoint of the left arc would be (30, 35) for the left arc, and to define the upper left corner of the rectangle bounding the arc, I just subtract the radius, from the x and y coordinates, as seen below:



The arcs are still not connecting with the rays below. I have tried this with multiple sizes. I think the secret is to define just one number for either length To Ray (distance from center of the diamond to diamond vertex, or the radius of each circle that defines the left and right arcs, then just make all other coordinates functions of that, as seen in the official answer I originally posted. But I cannot tell how the official answer made the calculations. Nothing I remember on geometry tells me what, if any, relation there is between the radius of the circles making the left and right arcs and the rays that connect with them.
7 years ago
I have the correct code for the problem 7 in chapter 9 of "The art and science of java", which I found from a solutions manual online. Images of the page describing the problem are provided in attachment. however, I cannot tell how this programmer
found the correct values to pass to the GArc and GLine methods in order to draw the heart picture. I know it has something to do with trigonometry and fact that Math.sqrt(2) is the factor you multiply the side of a right triangle by to find the hypotenuse,
but I cannot see why the solution has those values for dx, height, and so forth. I realize this may be more of a math question than concerning java, but any help would be useful.

Javadoc on the ACM libraries I used if you need it: http://cs.stanford.edu/people/eroberts/jtf/javadoc/student/index.html.
http://cs.stanford.edu/people/eroberts/jtf/

7 years ago
Hi all. I am also taking the Stanford CS 106 course, and here is my solution to chapter 4 exercise 7. The only issue I see is that it doesn't produce good looking output if you enter a negative integer for n, for example, -12345 will produce -5-4-3-2-1.

7 years ago