Forum: Lab 1
computer lab hours?
User 15803 said: Does the computer lab in 001 have specific hours? I just went there, in the middle of a weekday, and everything was locked and there were no hours posted. Are students only allowed to use the lab at specific times?
User 16785 said: The computer lab in 001 is only meant for classes, so students are only allowed to use it during their lab sections.
Lab2
User 8470 said: I am almost finished with the PosNegAvg program. I thought I was done, but when I ran a program with no positive or negative numbers it divides by zero and does not execute. How do I write code to change that....do I need an "if " statement?
User 16785 said: Essentially, yes. When you calculate the average of the positive and negative numbers you need to make sure that you actually have some or you will get the error you just described.
User 8470 said: But if I do use an "if" statement and say it "numbers = zero" then print No Pos/Neg numbers...
but that doesnt stop is from occuring? correct...it will still run and fail...
how do I get it from failing to run the rest of the loop..or essentially how do I keep the loop going...
I know "return" will stop the loop..so that wont work
User 16785 said: You can stop your divide by zero error from occuring by saying something like:
if divisor is not equal to zero
do the divide
This way the divide will only occur when it would give you a valid answer.
Forum: Lab 5 (functions)
Arraysum
User 13278 said: How do you make the function return every element of the sum array? I can only make it print out one element, not the whole array:
for (int i = 0; i < a.length; i++)
{
sum[i] = sum[i] + a[i] + b[i];
}
return sum[0]; //how do you make it print out all elements of array sum[]?
Lesley said: The question asks for you to return an array. Printing it out is left to your main() method.
You can do this:
return sum;
Which will return the whole array.
To print out sum, just write a for loop that prints out each sum[i] in your main() method.
side effects & sorting
User 13278 said: I don't get how the static method of type void allows you to sort an array. Can a TA clarify this? Are you supposed to write a function to treat a hard-wired array of doubles as a string inside the function to sort the values?
Lesley said: Java is weird in that if you pass an array to a function then it will actually modify the elements of the array. Ie:
int[] x = {1, 4, 2};
sort(x);
//now x is {1, 2, 4} !
Your sort might look like:
public static void sort(int[] b) {
//somehow you sort b's elements
}
Even though you don't pass an array called b to the function, or have the parameter of the function as an array called x, it still will actually modify the elements of the array.
If you want to see this in simple action try this:
public static void allzeroes(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = 0;
}
}
//in your main
int[] x = {1, 2, 3, 4, 6, 2};
allzeroes(x);
for (int i = 0; i < x.length; i++) {
System.out.println(x[i]); //what does this print out?
}
User 15803 said: In class Professor Horton showed us library of functions that operate on arrays, something like java.util.arrays. I know it's in the standard lib.jar file. How can I get to that description page (for future reference)? I have tried searching the booksite and can't find it.
Lesley said: java.util.Arrays is part of the Java official development, not part of stdlib. If you google you should find information on it.
Forum: How to Use Forums (README!)
How to do basic things with Forums
Professor Horton said: Things to keep in mind:
- Look through the existing messages and answers first to see if your problem has already been addressed!
- Create a new topic (see the big button above?) for your question, unless there is a topic already for a question like your's.
- Do not post large amounts of code to the forum. After all, everyone can see it! A few lines might be OK, but again if this helps someone else do the program without learning, it's not good! If you need someone to look at your code, please see someone during office hours.
Be notified!
- When you create a new Topic, you can click a box at the bottom: Notify when a reply is posted
- If you see someone else's Topic and you want to be notified when someone answers in that, click on the Watch link at the top of the window.
Forum: Exam 2 questions
Arguments
User 15764 said: Could you give an example of pass by value and pass by reference?
Lesley said: Consider:
public class Zero {
public static int makeZero (int oldValue) {
oldValue = 0;
return oldValue;
}
public static int[] makeAllZero (int[] oldValues) {
for (int i = 0; i < oldValues.length; i++) {
oldValues[i] = 0;
}
return oldValues;
}
public static void main(String[] args) {
int old = 5;
int newval = makeZero(old);
System.out.println("Old value: " + old + ", new value: " + newval);
System.out.println();
int[] olds = {4, 5, 8, 3};
int[] news = makeAllZero(olds);
for (int i = 0; i < olds.length; i++) {
System.out.println("Old value: " + olds[i] + ", new value: " + news[i]);
}
}
}
This doesn't do exactly what we would want:
Old value: 5, new value: 0
Old value: 0, new value: 0
Old value: 0, new value: 0
Old value: 0, new value: 0
Old value: 0, new value: 0
This is because an array is "passed by reference" in a sense while primitive types (int, double, etc) are "passed by value" - the int (old) that we pass into the makeZero method isn't modified (after we call the method, old still contains 5). However, olds (the array) IS modified when we pass it to a method.
To fix this (and make our code work like we wanted), we would do something like:
public static int[] makeAllZeroes(int[] oldValues) {
return new int[oldValues.length];
}
You could also say something like (int[] newValues = new int[oldValues.length]; return newValues) but this is unnecessary. Also, Java makes all new int arrays have all zeroes by default so we do not need a for loop to initialize them all to zeroes. If we wanted all 1's, though:
public static int[] makeAllOnes(int[] oldValues) {
int[] newValues = new int[oldValues.length);
for (int i = 0; i < oldValues.length; i++) {
newValues[i] = 1;
}
return newValues;
}
I'm not sure how much you've learned about objects but they act like arrays (can be modified in a method).
Forum: Exam 3 questions
Passing references as arguments to functions
User 13463 said: So on #2 in the first part of the review (and at the bottom of p. 354 in the book) the discussion is on passing references as arguments to functions. You CAN change the value of the object by passing a reference to it, but you can't change the original reference.
I can read it and kind of get it, but can you explain it in idiot's terms? Can you give an example?
Lesley said: public class Objects {
private int num;
public Objects(int n) {
num = n;
}
public int get() {
return num;
}
public static int copy(Objects o1, Objects o2) {
o2 = o1;
return o2.get();
}
public void set(int n) {
num = n;
}
public static void passSet(Objects o, int n) {
o.set(n);
}
public static void main(String[] args) {
Objects o1 = new Objects(2);
Objects o2 = new Objects(7);
//print out what each one has
System.out.println(o1.get() + ", " + o2.get());
//set o1 to have 6
o1.set(6);
//modify o2 through other set method to have 27
passSet(o2, 27);
//print out what each one has
System.out.println(o1.get() + ", " + o2.get());
//if we could modify references this would set o2 to 6
System.out.println(copy(o1, o2));
System.out.println(o1.get() + ", " + o2.get());
}
}
So by passSet() you can see that we can modify all of the instance variables associated with an object passed to a function. But by copy() you can see that while we can temporarily modify what a reference passed to a function points to, when the function is done it goes back to pointing to the object it pointed to before the function.
Forum: Java and IDE Configuration Questions
64-bit machine and Installing Java and DrJava
Professor Horton said: If you have a PC with a 64-bit processor, you have to do some things correctly to get Java and DrJava working. I'll list them below. We also are now updating the documents on setting things up, too.
- You must download and install a 64-bit version of the Java JDK!
When you download from Sun's site, there is an option for Platform that says Windows x64. Choose this one!
- For DrJava, you must run the Jar file not the Windows .EXE!
The .exe file on the DrJava site was not compiled for 64-bit machines, but the Jar fill will run fine.
Boolean from command line
User 15559 said: I am having trouble in java. I did all my work on the lab computers and it didnt save of course so I cant look back at how I did it before. I dont remember how to type in to java to recieve the boolean value I know for integers it is like this.
Int a = Integer.parseInt (args[0])
I am stuck on this
Boolean b = (what exactly)
I looked in the book and online for examples but couldnt find any
Also how exactly do you submit the files because when I was trying to find out what I did before the files I submitted were in a completely different format. Any help would be great thanks.
User 14072 said: The format for parsing a boolean is just like the format for parsing integers.
boolean b = Boolean.parseBoolean(args[0]);
Note the capitalization, as it is important that you get that correct.
In order to submit your files, go to the bottom of the assignment page where there is a text area, and just below that is a button to attach files. After you've selected all the files to attach, make sure you click the button to show that you are done. (Can't remember what it is. Continue, or done, or something like that. Probably not anything like "Cancel" :) ) It should take you back to the assignment page where the text area is, and then you can submit. Make sure that the files you attach are the .java files, not the .class or .java~ files. For a program called "foo", if the only files you see are "foo.class", "foo.java~" and "foo", submit "foo", as Windows has probably hidden the .java extension.
Lesley said: User 15559 wrote:
Int a = Integer.parseInt (args[0])
Boolean b = (what exactly)
That first part should have been int (lowercase!) on the left hand side of the equal sign.
The second part, while you can in fact declare something like Boolean b, you should use lowercase boolean (like int, double, etc - all "primitive types") until you understand the difference between the uppercase and lowercase (which you will learn later in the semester!) 'b'.
Squaring a string...
User 8470 said: I am doing number 9 from lab 1.
I have wrote all the code needed (and all of it works) except for the length/distance.
For the formula I need to square the deltay and delta x...
Is there an easy way to do this?
I know in the Math library there is a square-root but what about to square a funtion?
Or is there another formula I should be using?
Lesley said: I don't know what you mean by squaring a string, but to square a number x is the same as multiplying x by itself. Does that answer your question? You can also use Math.pow(x, 2) for the 2nd power of x, but that is more typing for something simple like squaring. Math.pow() might be more useful for something like x to the 5th.
Boolean outputs printing twice
User 15813 said: Is anyone else having problems with the outputs printing twice in the Boolean problems DeMorgan or Ordered?
For example, if I type in " java DeMorgan" than I get an output of either "true true" or "false false"
Lesley said: This sounds like a great use of office hours - we're unfortunately not psychic so since we can't see your code (AND YOU SHOULD NEVER POST YOUR CODE ON THESE FORUMS THAT IS AN HONOR VIOLATION, or at least it has been in past years) so bringing the code in person to a TA at office hours would be your best bet.
Compile error?
User 13977 said: After doing my reading last night, I tried typing in the HelloWorld program listed in 1.1.1 and thn when I hit compile it gave me this error:
File: (no associated file) [line: (no source location)]
Error: No compiler is available.
This is after saving the program and everything. Can anyone think of why this might be happening or what I'm doing wrong?
Professor Horton said: So are you trying to compile from the command line?
Or are you using DrJava?
We're about to post instructions on how to properly install Java and then DrJava soon!
User 13977 said: I just updated to the most recent java from the java.com website and am using Dr. Java and still receiving the same error. I guess I will just wait until the directions come and hope we don't have any homework that requires it.
Lesley said: This error, as Prof. Horton and I were discussing earlier, comes from not having a tools.jar file which is associated with the SDK. If you just have Java on your computer you won't have the file you need.
To take full advantage of DrJava's features, you will need to have either the JDK 6.0, the JDK 5.0 or the J2SE v 1.4.2 SDK installed on your system. We highly recommend version 5.0 or 6.0, as they provide a number of language features, additional APIs, and GUI improvements. If you are using version 1.4.0 or 1.4.1, you may see some buggy behavior, some of which is documented below.
viaFAQ on www.drjava.org
Once you have the right version of Java downloaded from java.sun.com, you can follow these instructions (also from the drjava faq):
Why can't DrJava compile any files?
If you encounter a "No Compiler Available" message, DrJava was not able to find a compatible copy of the "tools.jar" file, which comes with the Java SDK and contains the Java compiler. Note that versions of Java prior to 1.4 are not supported in the latest DrJava releases. You can specify the location of "tools.jar" by choosing "Preferences" from the Edit menu, choosing the "Resource Locations" section, and entering the location into the "Tools.jar Location" field. (The "..." button next to the field allows you to use a file dialog to locate the file.)
User 13977 said: Thanks Lesley. After downloading the Java SE 6.0 program and an update Dr Java, the problem fixed itself.
User 9756 said: After instaling the Java Runtim Environment 6.0 Update 7, I have tried to install Dr. Java many times, but I can not find the program anywhere on my computer. What should I do?
Professor Horton said: This reply is for (user 8756)who downloads DrJava but can't find it. When you use a Web browser to download a file, it always put it in some folder. Which folder? Depends on which web-browser you use, and if you've configured it to do something different than the default!
- If you're using Firefox: Go to Options if you're using Windows (Preferences on the Mac), and look on the Main tab and there you should see the directory where Firefox is downloading files.
- If you're using Internet Explorer, by default I think it prompts you for where to put the file. In fact, I think it always does this!
Does this help?
User 11517 said: I had the same error, downloaded what I needed and pointed Dr. Java in the direction of the tools.jar file. It still gave me the same error, so I restarted Dr. Java and now it's giving me two new errors: "2 errors found: File: C:\Users\MX\Documents\Downloads\EchoInt (1).java [line: (no source location)] Error: error: error reading C:\Users\MX\Desktop\Dr. Java.exe; cannot read zip file entry File: C:\Users\MX\Documents\Downloads\EchoInt (1).java [line: 1] Error: C:\Users\MX\Documents\Downloads\EchoInt (1).java:1: class EchoInt is public, should be declared in a file named EchoInt.java" I'm looking at code that worked fine in the lab, as well as stuff I've put together on this computer right here. Nothing is working for me.
Lesley said: Re: (user 11517): It seems as if you have an EchoInt.java and an EchoInt (1).java. You need to have it in EchoInt.java. If you have problems, swing by office hours, someone will be glad to help you and Dr. Java get along.
Topic: what can i do if "could not create the virtual java machine"
User 15140 said: When i clicked the icon, it suggested could not create the virtual java machine.
It did not appear to have any problem until then.
PS: Nevermind, i will use eclipise temporarily then reinstall my xp
:d
thanks
User 13977 said: I had this same problem and when I stopped by Office Hours nobody was able to figure it out. Well, after some more tinkering I managed to figure it out. When you install and start Dr. Java, the program creates a file called .drjava in your C:/Users/(your user name here) [for vista] or C/documents [equivalent I think for xp]. This file seems to act as a file that temproarily stores Dr. Java preference data. If you delete this file and reload the program, the file will be automatically remade and should allow you to load the virtual machine.
Disclaimer: My problem occured because I left Dr. Java open for too long (3-4 hrs) and it ran out of "Heap Memory". After I restarted the program and changed the maximum heap size to 5024 ( or whatever the max setting is), the program would not load and give me a "Could not create the java virtual machine" error after the Dr. Java splash screen loaded. If anyone reading this arrived at the problem from a different way, try this but be warned I don't know if it will fix it for you.
I would be more than willing to show this to anyone in person on class on Wednesday, or you can email me at ----- and we can try to arrange a meeting before then, schedules pending.
Topic: How to get Java to print out more than one outcome at time
User 15822 said: When I did the die rolls, I wanted to get more than one outcome. I wanted to be able to get a set number like 10 every time or even put: java Toss 5 to get only 5 outcomes.
I used several two ways but I'm encountering issuesssssss. Comments?
Lesley said: Consider using a for loop which parses the argument passed as an integer:
int times = Integer.parseInt(args[0]); //like always
for (int i = 0; i < times; i++) {
//do stuff: like "rolling" a die
}
It is possible to generalize this code to do 10 times unless an integer is passed as an argument, but it is beyond the scope of CS101. In CS201 you will learn about Exception handling, and thus you could "catch" an Exception thrown by not having any arguments to set times = 10.
Otherwise you could just surround your code with a foor loop like above but do something like
int times = 10;
instead of Integer.parseInt().
Forum: HW1 Questions and FAQ (Boys and Girls)
Number of Kids
User 13278 said: I'm a little confused on how to get the counter to count "the number of times the parents will have a certain number of kids" versus just getting the counter to count "number of kids" the parents have. Can anyone clarify that?
Professor Horton said: > I 'm a little confused on how to get the counter to count "the number of times the parents
> will have a certain number of kids"
Just to make sure I (and everyone understand), you mean how do I count, after running the experiment lots and lots of times, how often they have 2 kids, how often they have 3 kids, how often then have 4 kids, etc.
> versus just getting the counter to count "number of kids" the parents have.
And this is for one experiment just how many kids they had. But after running the experiement lots and lots of times, you'll need to count the total sum of number of kids the family had for all the experiments you did.
OK, now back to the first point, which I think is what you need clarifying. Let's see if I can answer and teach without just telling you what to do. We have variables to remember things we need, and often in our programs so far we've used them to count things. We need a different variable to count (or remember) different things. So if you need to count how often situation A occurs and also how often situation B occurs, you need a counter-variable for each.
Think about or look at those slides I covered yesterday in 03_loops.ppt where we set a rate variable based on an income-level. Imagine that code was in a loop and we wanted to count how many people were in each income-level. We need a counter-variable for each income-level, and but we could use code kind of like you see in the slide to update these counters correctly.
User 13278 said: Thanks for clarifying. I knew it would look like the income tax slide, but I didn't realize that a different variable was needed for each level to make it work.
The first kid
User 11928 said: Should we write our program so that we are entering the first child (boy or girl) in the command line? Also, I'm confused about using numbers vs. using names as in boy or girl in the program. I understand Strings are used, but I don't know the rules for Strings vs. ints. We used ints in the Roll problem and the Flush problem, but how do you use strings to mean the same thing?
Professor Horton said: There don't need to be any command line arguments for HW1. The sex of the first child should be determined randomly using Math.random().
As far as using a String vs. an int (or a double), in principle it would not matter which we used -- IF we had some easy way of getting a random String value, either "boy" or "girl" with a 50-50 chance of getting either.
There's no simple way of doing that. We do have Math.random() and we've seen lots of examples of using that method and the value it returns to simulate some random choice.
And don't forget that it might be useful to call Math.random() and boolean variables together. For example:
boolean isFemale = (Math.random() < 0.5);
which says we've decided that if the random number generator returns in the range [0.0, 0.5) then it's a girl and if it's in [0.5,1.0) it's a boy.
See Fri. CS101 lecture and example programs
Professor Horton said: As promised, Friday's lecture in CS101 did the "roll lucky 7" simulation that you thought about in lab this week. And, there's another example at the end that similar to HW1.
See the lecture slides and screencast link to the left. The screencast talks about those, and you'll also find links to the Java files.
User 13278 said: For the code below for the Dice example, using the "for" loop, what does "i" do?
It's not used again in the rest of the code...
for (int i=0; i < COUNT; ++i) {
int sum = 0;
int countRolls = 0;
int die1=0, die2=0;
while ( sum != 7 ) {
die1 = (int) (Math.random() * 6) + 1;
die2 = (int) (Math.random() * 6) + 1;
sum = die1 + die2;
++countRolls;
}
Professor Horton said: Sometimes the loop control variable (in this case, i) is actually used by other lines of code for some logical purpose. (But not here.)
Other times, it simply controls how often the loop goes around. That's the case here.
Here we need to make sure the loop executes (and repeats the single "experiment") some number of times (here, COUNT). So as the loop body executes each time, the variable will record which iteration this is. But we don't need to know or use that info in the loop body. We just do the experiment (have babies!) and record info about family size.
Frequency counter
User 8585 said: The question is asking for the frequency of the certain number of children the parents have, So do we have assign a counter for each "certain number", e.g. i2 for 2 kids, i3 for 3kids,.....but if yes then we have to theoritically assign N counters for N possible result. How can we do that?
User 8585 said: Sorry, I did not notice there is only one couter needed for five and above kids, but is this the final output that you need?:
The number of times they have two kids is 6
The number of times they have three kids is 3
The number of times they have four kids is 0
The number of times they have five or more kids is 1
Professor Horton said: Yes, that's right. Your output is what we're asking for.
second kid
User 14116 said: i have already set to get a random value for boy or girl but how do we make it so that the program ends once we have reached both one boy and a girl?
Lesley said: Please come to office hours.
It's much easier to explain things in person.
But if you think about your Roll7 program, how did you know when to end - you computed the sum of the two dice, and compared it to 7 to get a boolean. So you need to come up with a boolean that represents not having more than 1 boy and 1 girl for your loop to continue.
Average of kids
User 16968 said: For the average number of kids do you want an integer or a double? I figure an int makes more sense, but a double would be more precise.
User 16785 said: We would like the average expressed as a double.
Finding the Average
User 14574 said: So there is a counter for how many couples have 2 kids, 3 kids, 4 kids, and a single counter for couples that have 5 kids or more.
Then we are supposed to find the average of the amount of kids the couples had. But how can we find the average of how many kids the couples had, if say..one couple had 6 kids or 7 kids because we would not know how many above five that couple had.
Lesley said: Consider making another variable that holds the total number of children.
Posting questions very soon before the assignment is due
Lesley said: We probably won't see if you post only an hour or two before the assignment is due.
Please take every opportunity to come to office hours Sunday, Monday, Tuesday nights and Wednesday afternoons should you have questions, to avoid these last minute inquiries that none of us saw. These are the designated times for TAs to help you. Our availability is not guaranteed outside of those times.
We are here to help you - but please don't expect us to walk you through an assignment if you only start it the night of. That is an unfair request when we have office hours for four days straight before the assignment is due.
Forum: HW2 (NBody)
Step 1
User 15813 said: When we calculate the net force of a particle, does that mean we have to take into account ALL the other planets with each particle? So when we calculate, say, the net force on earth, do we have to calculate the force between earth and the sun AND earth and mercury AND earth and mars AND earth and venus? Or do we only calculate the force between the particles next to one another (ie - sun and mercury, mercury and earth, earth and mars, mars and venus)?
User 14690 said: I have a question based on your question. Is force supposed to be used somewhere? Is it only calculated or what is the point of having it.
User 13977 said: Force is used to find f(x), as seen in the Gravity program we did in lab.
Lesley said: Re:Erin: yes you must calculate the force of (ie. sun, merc, venus AND earth on mars) not just earth on mars.
Re:what is it used for: The sum of all of the forces is used to calculate the acceleration, velocity, and thus new position of the planets at each time step.
Graphics issue
User 12812 said: I've got the planets moving the way they should, but the pictures flicker as they move. I've tried playing with the StdDraw commands like StdDraw.show(), but it doesn't help. They're not blinking on and off, they're flickering, going half dim, coming back, etc., kinda like a lightbulb that's going out. What should I do to fix it?
User 13977 said: Check your placement of the clear function. I had this same problem and toying around with that should clear it up.
Lesley said: Please try playing StdDraw.show(20) AFTER you have drawn ALL planets - ie, you might have a loop that draws each of the planets like so:
for (...)
{//draws each of the planets }
StdDraw.show(20);
Make sure it's not inside the loop!
If you still have questions please stop by office hours, this is a quick fix.
leapfrog approximation scheme
User 13278 said: Can anyone elaborate on the leapfrog scheme? I tried writing it using Professor Horton's example but the program won't read the dt/PI or dt/Math.PI.
Lesley said: I'm not sure what you mean by the last part, please come to office hours.
Please remember that homework assignments are to be done without help of any other students in the class, on your honor (your question's wording is a little iffy whether you expected help from a classmate). We (TAs) have office hours for help. Don't hesistate to come by.
User 13278 said: Sorry about that; I thought who I was asking was implied. I will come to office hours for more help.
HW 2
User 14837 said: Can you explain this leapfrog approximation scheme? I know we went over it in lecture, but I still don't really understand what we are supposed to do.
Lesley said: the programs in lab are identical to what you are doing. Your final program is a combination of Gravity3 and InnerPlanets. If you still have more questions please come by office hours, though it will most likely be busy. All of the calculations you need to do are listed on the page (calculation the total Fx and Fy, acceleration for x and y, velocity for x and y, and the new positions rx and ry).
User 15110 said: Could someone (one of TA's or professors) please post the codes of the programs we did in Lab 4 ( i.e. Gravity1, Gravity2, Gravity3, BluePlanet, Distance, InnerPlanets).
Lesley said: I've asked Professor Horton if I can post the answers and if so I'll make an announcement with them.
User 15806 said: I'm very confused about the leapfrog scheme and it doesn't help when the solutions to the programs we are supposed to be using to help us aren't posted.
Lesley said: The assignment is do-able without those programs, do not take the attitude that it is impossible without them! You are supposed to be working towards these programs, we are not just supposed to "give you the answers." The programs were assigned for lab and we explained that if you did not finish that we had office hours to help you finish them. The fact that you are waiting until the day before it is due to start asking for help is NOT our fault. Please try to keep a positive attitude!! You are a UVA student who is highly capable of understanding and completing this assignment - you can do it!!
User 15772 said: I am having trouble reading the planets.txt file. It is in the bin folder of the project, but java still can't find it. Do I have to do something else?
Lesley said: for good measure you can try putting it either in the src or the root project folder and see if that helps. if not try using dr java... at this late point in time.
Planet Trail
User 16348 said: My planets are leaving trail as they revolve around the sun. What is going on?
Lesley said: you need to redraw your nightsky.jpg in an appropriate place that does something like this:
- draw nightsky
- calculate new positions for planets
- draw new positions for planets
- redraw nightsky
- recalculate new positions for planets
- draw planets in new position
- ...
see how it fits into your while(true) loop?
Planets Not Being Affected by Gravity
User 14331 said: I have set up my program so that the planets are moving. However, they are not rotating at all. They are only moving up... haha. So i'm not sure how to fix it to make sure that the planets are all being affected by gravity?
User 15781 said: My program does the exact same thing. It worked fine when I only had the planets affected by the gravity of the sun, but now that they are all acting on each other, they only move up and to the right out of sight.
User 15774 said: me too :( just right up and gone
User 15814 said: Mine are moving to the left, but still just fly out of the picture, so probably the same problem :(
User 13977 said: Mine go to the right and out
User 15409 said:
I had similiar problem, these are two things I added/fixed and now it works...
1. when calculating deltaX and deltaY of everything on everything (remember not itself), deltaX should be the position of the most nested loop minus the second most nested loop.
Simply put try changing the order to see if that is your problem (2 and 1 will be loop variables of course):
double deltaX = X[1] - X[2]; to double deltaX = X[2] - X[1];
double deltaY = Y[1] - Y[2]; to double deltaY = Y[2] - Y[1];
2. Also you do not want to overwrite the (x,y) with the new one before you are done finding all the (x,y)'s for that step.
User 15814 said: How do you stop the (x,y) from overwriting?
User 15409 said: When calculating the new position write it into a new array say (secondX, secondY) then preform a swap when you are done with that step of finding the next position values for all planets.
User 15781 said: I switched my variables and that still did not fix it. My planet's just get up and go straight out into the top right corner.
User 15774 said: do we have any other ideas on what's up with the sun's lack of gravitational force?
Lesley said: This (planets moving straight up) is caused by a myriad of coding errors. A common one is calculating some fx but overwriting it each time so that in the end you have the fx of mars being applied to all of the planets. You might want to use an array of size (number of planets) for fx instead of one single variable.
Should this not solve your issue, please come to office hours. We have seen this a lot and can help you fix it.
Lesley said: Re: moving to the right: (and up): This is the error already described by a class mate - you have your dx and dy switched (negative).
Re: moving to the left (and down): this is because you have continuously added on to fx for each planet (so the first time suppose the sum of the forces is... 5. Then the next time step instead of resetting the sum to zero and adding it up to be, say, 6, you instead end up with 5 + 6 = 11. The next time step suppose the sum of the forces is 4. Instead of ending up with 4, you end up with 5 + 6 + 4...)
User 15814 said: About going to the left and down, I see what you mean about fx adding on each time. I just have absolutely no clue how to stop that from happening. If that is too specific of a question to ask on here, I will just go to office hours. Thank you though.
Lesley said: Yes, it would be better to go to office hours. One of us can explain it for you. :)
Extra Credit
User 15813 said: So I added a little UFO to my program, and it shows up when I run it. But will it show up when I submit it and you TAs have to open it? Does my own program take my own "planets.txt" file with it?
Lesley said: please submit all related files (your planets.txt, images) in a separate file called extracredit.zip - if you need help doing this please reply. you can use a program called winzip if you use windows.
Lesley said: you install winzip
then you put all of the files (text file and pictures) in one folder.
then select all of them and right click and there should be an option to "add to ___.zip" and do that
and then you should have your .zip file!
Strobe Light Planets
User 14299 said: So I realize that its a little late to be asking a question, but my program works beautifully. All the planets are orbiting correctly. It looks great, except all the planets and the sun flash at a ridiculously high rate, to give the strobe light effect. While this looks really cool, I feel like it somehow isn't quite what you're looking for. I figure it's a simple solution of placement of my StdDraw.clear(); but I've been toying with it, and can't get it right. Any suggestions??
Lesley said: please try putting StdDraw.show(20) after you have drawn all of your planets. This lets your program take a break for 20 milliseconds. :)
Forum: HW3 (Recursive Graphics)
hints to draw N =2
User 14007 said: I drew the first black triangle, but i don't know how to get the position for the other three triangles. Do you have to recalculate the positon every time?? which means that you would have to create new arrays all the time right??
Lesley said: The smaller triangles are related to the larger one. For instance, the bottom-x-coordinate of the (smaller) top triangle is the same as the bottom-x-coordinate of the large triangle. Another thing to consider is the height of the triangle (which you can get by subtracting any top-corner y-coordinate from the bottom y coordinate) or the length of the triangle (the difference between the two x coordinates) and how those two numbers (the height and the width of the large triangle) relate to the coordinates of the smaller triangles. If you need more hints please come to office hours.
How do I change pen color?
User 13463 said: I want to alternate between black and white circles for part of my program. I assume I just set the pen color to black and white. I've tried various ways, but I can't seem to do it....
Do I create a function setPenColor and then call on it to change the color? If so, how do I do this?
Thanks!
Lesley said: Please refer to
http://www.cs.princeton.edu/introcs/15inout/ and search (ctrl + f) for "setpencolor" and it will detail how to do this and many other things with StdDraw.
Setting Background Color
User 13977 said: I am having trouble finding a method in the book to change the background color of the canvas for my Art.java file. Is there such a thing or would I need to find another way to do this?
Lesley said: Consider using StdDraw.clear(StdDraw.BLACK); for instance
Dr. Java being stupid
User 15813 said: My programs compile fine, but I tried to add a little more to my second one and every time I try and change something DrJava shuts down and says
" AN INPUT OUTPUT EXCEPTION OCCURED DURING THE LAST PROGRAM..."
What is the problem? It won't even let me save my program. Has this ever happened to anyone?
Lesley said: Strange, I would say try rebooting your computer and/or trying to edit your program on a lab computer (ie. one in Thornton stacks) to see if it is something strange typed in your program or just your computer being silly.
User 15813 said: Yea I'll definitely try rebooting my computer - hopefully it's the stupid Dell, not the stupid Dr. Java
hw3 part 2 Art
User 15811 said: For my Art part, i made a function that draws sierpinski triangles inside of sierpinski triangles. Inside of the large central triangle is a smaller Sierpinski triangle, and inside of the smaller traingles there are other Sierpinski triangles. Each new one is a different color. The color changing is implemented inside of the recursion function, after each call the color is changed. Is this different enough to not get points deducted, or is it too similar to Sierpenski
Lesley said: Well, technically, a sierpinski triangle IS three smaller sierpinski triangles... you should try to be creative but turn in what you will...
Distortion of overall triangle wrt scale
Lesley said: The instructions for HW3 say to do this:StdDraw.setXscale(0, +1.0);StdDraw.setYscale(0, Math.sqrt(3.0) / 2);
But a student pointed out that this makes his triangles distorted.The Y-scale should also be 0, 1.0
Forum: HW4 (myPhoto)
JPEG files?
User 12424 said: It seemed to be that JPEG type of images couldn't be used....is that true?
Lesley said: There are essentially 2 types of JPG images - jfif and exif, and I tested both of them (with extensions .jpg and .jpeg) on the Picture2 class and all images worked.
If you're in doubt, start up dos (go to start - run; type in: cmd) and go to the directory where your images are. Type:
edit whatever.jpg
And you will see either ...JFIF or ...Exif. If you don't please email me the image (leh5m) because I totally want to see what crazy kind of JPG you have on your hands.
You can rename .jpg and .jpeg files to be either one - whatever.jpg renamed to whatever.jpeg is the same exact thing.
User 12424 said: Thank you, Lesley!
speed of slideshow
User 13278 said: What's a good speed/time to set the show() operation on?
Lesley said: It's entirely up to you, though we've seen that fading effects work better with smaller images. Just experiment with different numbers (my guess is <= 500 milliseconds) and see what you like!
New Methods?
User 14748 said: Are we expected to / do we need to create new methods for this homwork? The instructions say that we should have a short main and that we should use methods to call other methods. This sounds like we may have to make custom methods. Is that necessary?
Lesley said: Yes, you need to make a lot of new methods. Feel free to drop by office hours if you are not sure about this.
Using methods from the book
User 13977 said: Is it against the honor code policy to copy methods from the book (ex. certain methods from the Fade class)?
Lesley said: This is definitely okay and expected! Please use any methods the book gives you.
references to the textbook
User 15409 said: Z or z or Zoom or zoom: prompt for digital zoom parameters (see the basics of the idea in question 3.1.43 on p. 369 in the text) and do a digital zoom of the current image. Note: consider looking at the "upscaling" section in the text (p. 332) for ideas on how to do this.
G or g or Gray or gray: display current image in gray-scale (see p. 327 in the text)
---------------------------------------------------------------------------
Is it possible that these pages could be made availabe online? Or at lease describe the parameters i need to do these parts?
Thanks.
Lesley said: http://www.google.com/search?hl=en&q=site%3Acs.princeton.edu%2Fintrocs+fade (similar results for "scale" or "grayscale")
current image
User 13278 said: How might you store a currently displayed image, separate from the rest of your images? Can a TA describe a general idea of what's happening there?
Lesley said: You could just make a Picture2 object to do this, and change the pixels at whim. If you're confused please stop by office hours.
image edit mode
User 15814 said: When you go into image edit mode, so you just assume that you start with the first picture in the file? Or should they enter a command to pick which picture?
Lesley said: Just start with the first picture :)
User 15814 said: K thank you
Image Edit
User 9756 said: Can someone explain how to make codes for the command "zoom" and "save"?
For "zoom":
What parameters are required?
Note: The textbook in 3.1.5 on P333 takes three different parameter than the practise 3.1.43 in the back of the chapter on P369.
For "save":
How do we prompt for the window saving the file?
Note: I don't know what parameter for actionPerformed in Picture2.
User 15409 said: My guess is use StdIn to prompt.
Lesley said: Yes, posted a sticky on zooming; please prompt the user for a file name with StdIn and then save it using the save() method in the Picture2 class.
keeping track of picture
User 15768 said: How do I keep track of the picture that it is showing in image edit mode. For example, if I'm trying to make it go to the next picture how do I make it so that each time I type in "n" when prompted it shows the next picture?
Lesley said: Consider using an int that keeps track of the current array index (in your main() most likely). You should have an array of the pictures you read in from the text file at the beginning of your program. You should increase the index when you are prompted for the next image. Do something interesting if they call next when the index counter is greater than the number of pictures in the array. The index counter will start at 0 (first image). Is this clear?
User 13278 said: So "next" doesn't have to be able to restart the slideshow once it reaches the end of the images?
User 15768 said: yes, thanks
Lesley said: re:mary: nothing was specified so no. but feel free to do this if it's easy.
edit mode
User 15814 said: after one function has been done to the picture in the picture edit mode, are you supposed to save the edited picture and be asked for another command to do something else to the edited picture? or should you start from scratch each time a command is done?
Lesley said: only "save" (to a file) if the user prompts you to save.
but yes, if you type in greyscale and then zoom, it should zoom in on the greyscale picture not the original one.
image-text file
User 15782 said: can we assume that all the images in the text file will a). have the same size and b). contain a jpg extension?
Lesley said: a. no. any image in the sample directory could be in your slideshow. this is why standardizing (extra credit) or otherwise knowing what the max width/height of the images is (not extra credit) is important.
b. no... the extension is irrelevant, it will be included in the file name string and java can handle it.
javadoc
User 13278 said: For the myPhoto() constructor, should we still put a description next to it even though we described what the myPhoto class already does intially?
Lesley said: Feel free to model how Professor Horton did his javadoc-ing for his constructors of his Picture2 class. Does this clarify things?
User 13278 said: I'm confused on what you are supposed to write since myPhoto() constructor doesn't take in any arguments. All the Picture2 constructors take in arguments.
Lesley said: You could just write "make a new myPhoto object." or something like that.
User 13278 said: For the myPhoto constructor, where can you insert the javadoc comment for it? I tried inserting a javadoc comment before the constructor, but that just gets included in the class comments. I also tried inserting a javadoc comment after, but that doesn't show up on the javadoc html page afterwards.
Lesley said: Did you look at Picture2.java to see how Professor Horton did it?
User 13278 said: In Picture2.java, the Picture2 constructors listed are separate from the class name so you are able to annotate them with javadoc comments. I'm not sure if I did something wrong for my Javadoc to show my class name as a constructor...?
Lesley said: You'll proly want to stop by office hours since I have no idea what you mean now.
Saving to a file?
User 15753 said: Hey, I was just wondering when we save an edited image, it says for us to prompt for a filename and to save it to a file. Is the filename supposed to be the location of where it's being saved to, or the name of the file that's being saved? Also, is there some place in the book that describes how to save a picture to a file?
Lesley said: prompt for the name (such as "whatever.jpg")
check out the javadoc of the Picture2 class and look for a save function... ;)
User 15753 said: Thank you for clarifying. I thought to do that about 5 seconds after posting. *doh*
Javadoc??
User 13463 said: Wait so can someone tell me specifically how we use Javadoc? I've looked at the webpage and still am having issues.
Lesley said: you just add those special comments and then press the javadoc button in dr java. check out Picture2.java for examples of how to do the special comments.
Standardize
User 15807 said: Does standardize mean to scale or to crop?
Lesley said: ...neither really, if you watch the screencast you can see what it is supposed to do.
User 15814 said: which screencast?
Lesley said: the one from fri nov 7
Heap size?
User 15768 said: everytime I try to rnu my upscale function my compiler says it ran out of memory and that I need to increase the heap size..and everytime i do that it says it cannot run the java virtual machine..what do i do?
Lesley said: Try running upscale with:
1. a "smaller" scale factor (try .5 instead of .1)
2. smaller images (no bigger than 300x300 pixels or so)
alternatively at the command prompt/interactions window in dr java type:
java -Xmx500m myPhoto
and increase 500 at will
User 15768 said: ok thanks so much for all your help...I tried a smaller scaling factor and it worked..thanks
odd error
User 14299 said: I have tried coming to office hours twice but its so crazy in there I couldn't get any help before I had to leave so I figured I could ask here. My program compiles fine, and looks fine, but when I run it all I get is this error: "java.lang.NullPointerException at java.io.File.(File.java:194) at Picture2.(Picture2.java:86) at myPhoto.Fade(myPhoto.java:14) at myPhoto.main(myPhoto.java:78)" I've looked at the book for this error and it suggests that the problem is that I haven't initialized all of the instance variables, but from that first line "at java.io.File.(File.java:194)" confuses me, because that is only in the Picture2 class that was downloaded from Collab. I'm not sure you can help without looking at my code, but if you have any suggestions I would appreciate it. Thanks!
Lesley said: It definitely means you haven't initialized all variables. I can't really help you as to why this is without seeing your code (not allowed to post on forums or email, sorry - but there are more office hours in 15 minutes, though I'm sure they'll be crowded) but check and make sure you've initialized every Picture2 object with a new keyword somewhere... IE if you did this:
Picture2[] pics = new Picture2[5];
int i = pics[0].width();
you would get the NullPointerException since you never said
pics[0] = new Picture2("whatever.jpg");
Javadoc Question
User 15813 said: I'm confused about this - I'm trying to Javadoc my "copy" fxn but I don't know what the function is copying to - ie - is it copying a file to another file? i don't get this. If this is too specific, feel free to not answer. Thanks!
Lesley said: Do you mean the copy function that copies the pixels from a target image to a source image?
User 15813 said: Yes? haha. I believe so. I don't know if anyone else is having the same problem. I just am having a hard time defining the parameters for Javadoc. Like for ColorCombine. No worries though - I'll just keep writing it and hope that if I leave some parameter descriptions blank that I won't get too many points off. Thanks :o)!
Original Call
User 15764 said: So I have most of part two done, except for Original and Zoom (let's just face it, most students consider Zoom a lost cause at this point). So I was wondering, when I run through the grey static, it works. But it changes back when I do the slide show. If I try calling original on the newly gray-scaled photo, all that happens is a new box appears.
1) Is that acceptable?
2) How would I revert back to the original image?
My idea was to create an object for the grey function that would never change the master photo. That way when you call it back in Original, it returns to the previous saved image, not the grey one.
Thanks!
User 15764 said: Or could we just expand the array to hold the new images of the grey scale picture?
Lesley said: you should have some kind of array holding all of the pictures you read in from the file.
doing greyscale should change the master image, that's okay and expected. going to next or slideshow or something after doing greyscale would not mean all the other images would be greyscale or that the image would be permanently set to greyscale... that would be unfortnuate.
calling the original image should grab the current image from the original array and copy it into your master image. calling next would copy (current + 1) th image into the master image. make sense?
User 15764 said: No, right. I understand that. As it stands, the rest of the array doesn't become grayscale. It's just when I run the slide show again with the beginning key, the image reverts backs to the original picture without any prompting. Is there any way I can add the grayscale image into the array or preserve the old one so that when I call Original it works?
Lesley said: if you re-run the slideshow, (prompt "b") there's no need to keep the image greyscale. after the slideshow, just display the image at array[0] in its original format.
How to get started
Lesley said: This is one example way to get started...
- Read in the file image-list.txt - this is very much like what you did in NBody, except you will have an array of Picture2 objects instead of an array of strings/doubles/etc.
- Make a master image (named pic, slideshow, whatever) that will house the images for your slideshow. You will note that if you call show() on every image of your Picture2 array, it opens a new window for each one. This isn't particularly useful for a slideshow. You can, however, modify the pixels of one image and show it multiple times, but it will only use one window in this case.
- At this point you might be wondering what size to make the master image. Well it should have width as big as the largest image's width and same for height. This is your typical find-the-max-value problem.
- Now you might be wondering what happens when you overwrite each new picture into the master image - you'll have leftover pixels from the big image! Consider making a function that turns every pixel in an image to black. If you're doing the extra credit, this is also where you might want to start writing your standardize function to center all of the images.
- For each picture in your picture array, copy it into the master image. You will want to make a copy function that copies the pixels of the source image into the pixels of the target image. This is very much like all of the examples in your book (especially the rescaling one).
- Consider using the Luminace (from Princeton) class's method to fade between images, or make up your own fade for extra credit.
Hopefully this will get you started, and part way through the SLIDESHOW PART (the easier part). THIS IS A LONG ASSIGNMENT. DO NOT WAIT TO START IT UNTIL A FEW DAYS BEFORE. We have office hours. Come to them. Don't wait until the Tuesday before it is due to come to office hours, it will be very busy and you will not get the help you need to finish.
User 8470 said: Very funny on how you think the slideshow part was easy!
Thanks for all the help through the semster.
Lesley said: haha, didn't say it was easy, said it was easier (than edit mode).
Zoom parameters
Lesley said: Professor Horton says,
The instructions say see p. 369 in the book, and there it says write a program that takes three parameters and describes them. The three parameters described in the book are:
s: a scaling value between 0 and 1
x and y: relative positions in the original picture
Perhaps what's confusing is the between 0 and 1 part. For x and y, this is pretty simple: (.5,.5) means the center of the picture, and (.25,.25) means the middle of the top-left quarter of the picture.
The scaling factor is a bit confusing -- if you look at the book, you'll see that 0.1 seems to mean scale 10 times larger, and that .3 seems to mean scale 1/.3 = 3.33 times larger.
User 15129 said: Could we have a little more of a push in the right direction? I read in my 3 parameters fine but then get kind of stuck. I assume that it is going to be like the Scale program in the book but I do not understand how the center-point comes into play (as well as by how much you are zooming). Any help would be greatly appreciated.
Thanks
Lesley said: the book gives you the majority of the code! you have to do some work yourself! please go to office hours if you're stuck (note, they will be busy though), but your code will be VERY similar to that in the book - think through what it does and how to modify it to do what you want. also, this is just one part of the assignment so move on and do the other parts and if you have time come back to it (after you're done java-doc-ing, etc) since you have part of it done... good luck! :)
Forum: HW5 (GuitarHero)
Dequeue in Ring Buffer
User 15782 said: I'm not exactly sure how to write the method for dequeue - I understand that it is not the same as remove because it doesnt shift any elements. Instead it just takes out the value of the index at first and then increments first to make the next element in the array equal to first. But how do you physically delete an element from an array, or do we just set that element equal to 0?
Lesley said: you actually don't have to change it to anything, but you can change it to zero if you want.
also don't forget to wrap around: see the picture on the assignment for more on that
User 15782 said: well i decremented the size, saved the original first value in a double to be printed out, then incremented first. but its still not "deleting" the value - when i print out the list after dequeing but before enqueing it shows the original first up to N-1 values. should i filter all the numbers except for the first one into a new array then perform a switch?
Lesley said: if it's still printing everything out make sure your toString or whatever you're using to print out the list starts at first and wraps around to end and only prints out those, not extras.
it's all relative: the array itself at the beginning will be a bunch of 0's right, but if you have first and last set correctly you know when to stop when print it out or otherwise dealing with it.
Guitar Hero
User 16968 said: I'm confused with the sample part of Guitar Hero. In GuitarHeroLite it computes the superposition of the 2 notes A and C, but with all 37 notes, do we need to sum them all together?? I get a bad sound when I try that.
Thanks!!
Lesley said: you do indeed need to sum them all together. if you're getting a strange sound make sure your guitarstring and ringbuffer are working, and that you're doing everything to all 37 strings that GHL does to the 2 strings (pluck, sample, whatever else it does). if in doubt head over to office hours. :)
User 15761 said: When I compile my guitar hero program, an error shows up saying java.lang.OutOfMemoryError: java heap space. I made the array of GuitarString objects, but I think it's taking up too much memory. What's going on?
Thanks
Lesley said: weird, there shouldn't be any memory problems here... is it still doing this? sometimes dr java just freaks out. if it is swing by office hours so we can see what's going on.
User 10623 said: My test programs are all running correctly, and every key in GuitarHero.java is outputting sound, but it sounds like many of the keys output an identical tone. Are we supposed to have 37 distinct notes?
EDIT: Do you ever work on a problem for a really long time, then ask for help, and then figure out the answer yourself? Never mind -- got it! :)
Lesley said: yeah if anyone else has this problem remember to divide by 12.0 and not 12 (every time this assignment comes up i try to get them to put this on the page and they ignore me... -.-;; )
RingBuffer Test code
User 15788 said: When I run my RingBuffer, I get an error that says Java.lang.ArrayIndexOutOfBoundsException: 0 at RingBuffer.main(RingBuffer.java:81). This error corresponds to the line int N = Integer.parseInt(args[0]); If I take out the int N and manually change it to 10 or 100 in the code, I get the correct output. Why do I get the error if I leave the int N in? EDIT- This parse thing doesn't work on any of the previous labs/homeworks. I just tested it, although it worked before...Am I missing a file or something?
Lesley said: You will have to compile your program in Dr Java and then instead of pressing Run type
java RingBuffer 10
or whatever, remember this from week 1 or 2 of the class before StdIn?
User 15788 said: ah, forgot about that, thanks
Guitar hero
User 8585 said: Hi there,
I tested my GHL and all the parts before and they work. but then when i run my Guitar hero, I only hear a static sound at the beginning of the program and when i close it. nothing else happen. I tested them by only play one sound in the main method and it work, so tic() and pluck() is working...Can i have some idea on whereelse might be wrong?
Thank you
Lesley said: check and make sure everything that happens for notes A and C in GHL is also happening in your GH. if you can't find it then that is what office hours are for. :)
GuitarString constructor
User 15814 said: This may sound like a dumb question.. but for the GuitarString class, are we supposed to pick one out of the two constructors and do it that way or does the class need both constructors?
Lesley said: you will need to do both constructors for full credit. you will thus have two public GuitarString(...) { ... } sections, but what is in the parentheses and the curly braces will be different.
User 15814 said: Ohhhh okay, thanks.
Office hours this week
Lesley said: Hey, if you're coming to office hours this week, please bring a pair of headphones as the computers here don't play sound.
sound too high
User 15768 said: Everything on my program runs correctly but when i play it the notes sound too high. I checked my out put for guitar string and that works but when i run my RingBuffer with n=10 i get 64 instead of 55 like the assignment sheet says. What is my issue?
Lesley said: check and make sure you are enqueueing the right kind of random numbers
Guitar Hero Lite
User 9756 said: I copied GuitarHeroLite.java from the assignment site and pasted it to DrJava. I compiled and ran the program. One big window comes out and says " Click this window and type 'A' or 'C'". I clicked on it, but the window does not let me type. Can someone explain why?
Lesley said: When the window pops up just type A or C (make sure to hit shift+a or shift+c) and then it will play that note if your other 2 files are implemented correctly. If it's not doing this you might have a problem in one of them.
User 15761 said: When the window pops up just type A or C (make sure to hit shift+a or shift+c) and then it will play that note if your other 2 files are implemented correctly. If it's not doing this you might have a problem in one of them.
User 16785 said: The first thing you should do is make sure you're not getting errors in the interactions window. If the output from the main method of GuitarString is correct then that only means that your debugging constructor, time method, sample method, and tic method appear to work correctly. This test says nothing about the pluck method, unless you added your own test.
User 14837 said: I keep getting an overflow error after I type in a letter on Guitar Hero Lite. It says that it is a problem with enqueue and pluck. What could be causing this?
Lesley said: lots of things. a common error was that people were not wrapping around in ring buffer properly.
no image
User 15811 said: my guitar hero and guitar hero lite both play the notes correctly ( I tested with stairway to heaven) but the std draw window does not display the characters that I am pressing.
Lesley said: see guitar hero lite for how this is done. you'll use StdDraw.text(x, y, s) where s is a string and x,y is the position.
superposition of samples?!
User 15110 said: I don't understand why we need to compute and use the superposition of samples(I just play the sample from the current key that was typed and my GuitarHero program seems to work fine). Do we need to compute the superposition in GuitarHero? How should we implement this when there are 37 keys?
Lesley said: just use a for loop over all 37 elements in your array
complications will arise if you don't do this
User 14690 said: Is this for the superposition part of Guitar Hero? I used an array to set each char to a note, but do I need to use it again?
Lesley said: you will need to sample each of the 37 notes and add that together to get your total sample
Popping sound
User 14690 said: I have everything working well so far, but the only problem is the sound. When I play the notes, they make a popping sound. The sounds vary in terms of pitch and etc., but just it makes a popping sound. Could this be due to the double sample value in Guitar Hero?
Lesley said: it can be a lot of things, unfortunately there are no more office hours... make sure your sample sums up all of the sample() values of all of the 37 strings, and that your ringbuffer is working correctly, and your guitarstring - any of them could be contributing to it.
User 14690 said: I have it working better now. I just realized I had to change a few things. Thanks!
super position
User 8585 said: Can someone tell me what's the use of the superposition of samples..? Coz i can run my program properly without it (just play the key-in sound) and the class plays a static sound when i use it.......
Lesley said: it kind of fades sounds into one another, you will lose points if you don't do it.
User 8585 said: I went to the office hour but the TA could not point what's wrong too. Can I know what file I should submit?
The one that wroks fine (without the superposition) or the one produces strange sound that did the superposition?
Lesley said: it's only a few points off either way, cs101 is not point-for-point so just do whichever you want.