Links Quizes/Exams Assignments Proctor Lab Hours Office Hours Sylabus Announcements
PA1 Questions and Answers Updated: 4/12/02
 
Q: I noticed in PA1 that the multiplication and division operations for the complex numbers was incorrect. I wasted a couple of hours debugging thinking it was my algorithm. Was this issue addressed in class? If so, I apologize, but if not, please be more thorough about generating correct output results.

A: In class, I went over this. I know we are not correctly mult & div complex numbers correctly. As I said in class, just mult & div like you are add & sub just to keep it simple.



Q: My program works fine on DOS at home, but when I FTP it to sunpal, I can't get it to run. What's going on?

A: If you're trying to run code using telnet or ssh from your home computer, and your program includes calls that create separate windows, the problem is not from your code but telnet/ssh is unable to do any GUI functionality with Java. I would suggest you to physically go to the Sunpal lab and test your program there since we are going to grade your program using these Sunpal stations.



Q: I am having problems compiling and running the sample program. At first, when I ran PA1.java, the cancel button didn't terminate the program. Then, when I tried compiling PA1.java, I got this error msg: PA1.java:22: error while writing PA1: PA1.class (Permission denied) public class PA1
^
1 error

A: You need to copy ~/../public/Assignments/PA1.java into your own PA1 directory and compile there.

You will only be given valid input. Don't worry about the Cancel button on this assignment.



Q: When I transfer my code to sunpal after writing it in windows, I get these weird ^M characters at the end of each line. Is there a way to get rid of them without having to go to each line and delete them?

A: The reason for the ^M is that dos/windows and unix use different symbols to represent newlines in text files. You can use the command dos2unix to get rid of the ^M's. Here's the format:

dos2unix $sourcefile $destfile

where $sourcefile is the name of the file to convert, and $destfile is the name of the file to write to. If you have $destfile the same as $sourcefile, it will overwrite the dos version of your file, which in the lab is usually what you want anyway, but you have a choice of creating a new file if you want.



Q: The sample output for the hashcode method yields the same hashcode for c1, c2, and c3. c4 has a different hashcode value. My code generates the same pattern (i.e. c1.hashcode() == c2.hashcode() == c3.hashcode()) but my hashcode values are different from the example. Is this supposed to happen?

A: The hashCode() method takes the return value ( which is a String ) and converts it to a number. So if your toString is different than the sample program, then your hash code will be also different. You might want to check your output against the sample program since if there is any extra spacing or missing any spacing, your hash code will be DIFFERENT. Also, hash code value will NOT change since it ALWAYS depends on the string.



Q: I am having real problems with this same class constructor we are suppose to use for the CSE 8b assignment. Can you point me out to this part where they have it in the book?

A: In both constructors, you call the same-class constructor that takes two arguments, passing the values of real and imaginary that you want that two-arg constructor to use to initialize this object.

So for the no-arg constructor, the call same-class constructor call would look like

this( 0.0, 0.0 );

and that is the only line of code in that constructor.

I'll leave it up to you to determine how to do something similar with the one-arg constructor.



Q: Can I run PA1 on my computer in my dorm? Since it has JOption, everytime I do java PA1, it does not run the program, but rather prints out many lines of other things. Is there something I need to have on my computer for me to run something w/ JOptionPane?

A: You will have to have an X Windows server running on your local PC to run a Java program that uses graphics (like JOptionPane) remotely. You can transfer the files to your PC and run them there if you have Java installed on your PC -- java.sun.com/j2se -- either 1.3.1 or 1.4 is fine.