![]() | cs111 Frequently Asked Questions (FAQ) |
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 (/students/your-user-name) by default. From your home directory, click on the cs111 folder, and from within that folder, click on the drop folder. Within the drop folder, select the right folder for the problem set you are handing in (ps1-ps9).
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.
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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.