If you have a question you would like answered on this list, or if you are not satisfied with an answer that appears below, please send email to the course instructors.
The following questions are linked to answers below.
The CS111 server
A: There are many possible mistakes you may be making. Here are some important tips to follow:
A: When you connect to Fetch, you are connected to your home directory (/users111/your-user-name) by default. Your goal is to navigate to the CS111 drop folders, which are located in /usr/users/cs111/drop. You navigate using the Change Directory command. Here's how it works:
Q: How do I navigate to a CS111 drop folder in Winsock FTP?
A: In Winsock FTP, you have two windows. The window on the left represents your computer. The files and folders there are the ones stored on your own machine. The window on the right shows the files and folders stored on the cs111 server. To get to the drop folder, you need to change your directory on the cs111 server.
Q: When I upload files to/download files from the CS111 server using Fetch, files don't have the right name/format. What's the fix?
A: If your uploaded files end up having .bin or .hqx extensions, or if downloaded files don't have the right icons, your Fetch preferences are probably incorrect. You can fix them by installing the CS111 patches.
A: There are numerous reasons why an applet might not run on your home page. Before you do anything else, read the applet invocation notes, and follow the steps explained there. If you still have problems, here are some possible reasons:
A: If the applet is running, then your <applet ..> tag codebase attribute is correct. But if images are not appearing, it means that the addresses for data resources are not correct. See the notes on referencing data resources at the end of the applet invocation notes for how to fix this.
A: Add the following method to your applet
public void init() { this.setBackground(bgcolor); }
where bgcolor is an expression denoting the background color you want. Important: do not use the method invocation this.setBackground(bgcolor); within an applet's paint method -- this will cause the applet to get stuck in flicker mode.
A: It's likely that you have a method invocation this.setBackground(bgcolor); within the applet's paint method. As noted in the answer to the previous question, this invocation should appear in the applet's init method, not its paint method.
A: Here are several possible causes for missing graphics:
A: Here are several sources for details on Java arithmetic:
A: A floating-point number is a number that has a fractional part; it is written with a decimal point, e.g.: 2.5, 3.141, -5.99. Floating point numbers are distinguished from integers, which have no fractional part. In Java, there are two types of floating-point numbers, those of type float and those of type double. Numbers of type double have higher precision than those of type float. By default, we will use double for floating-point numbers in CS111.
A: If exp is an expression denoting an int, it can be converted to a double by means of a so-called "cast" expression:
(double) exp
If exp is an expression denoting a double, it can be converted to an int by means of a "cast" expression that truncates the information after the decimal point:
(int) exp
Here are some examples:
|
|
|
|
|
|
|
|
|
|
|
|
In practice, converting an int to a double is rarely needed, since most binary operators (e.g. +, -, * , /, <, >, ==, !=) automatically convert an int argument to a double when the other argument is a double. (But see the question about dividing two ints, below.) Here are some examples involving addition:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note in the example
(int) 10.9 + 3.141
that (int) binds more strongly than +; that is, the above example is treated as:
((int) 10.9) + 3.141
Sometimes truncating the fractional portion of a double is not the desired behavior -- instead, we want to find the floor (round toward negative infinity), find the ceiling (round toward infinity), or round toward the nearest integer. These calculations are performed by the Math.floor, Math.ceil, and Math.round library functions, as shown below:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See the java.lang.Math API for more information on library math functions.
A: In Java, the division of two numbers of which at least one is a double always yields a double result. However, dividing two ints always yields an int -- this is the result of so-called "integer division", in which any fractional portion of the result is truncated. How can we get a double result from dividing two ints? By first casting one or both of the integer arguments to a double. Here are some examples:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A: The compiler reports an error as soon as it reaches a bit of code it cannot execute. Sometimes, when it cannot execute a piece of code, it is because of a mistake made earlier in the method. Check the line before the line that's receiving the error.