1.

R1. Becoming familiar with your computer

The operating system takes care of much of the filing work --storing, moving, and remembering where things are--so you can do useful things at a higher level. You interact with the operating system via a Graphical User Interface (GUI), for example a windowing system using a pointing device like a mouse, or a Command Line Interface, using only a keyboard and a single window.

What are some examples of tasks you'd tell the computer to do via the operating system interface?


Answer:


2.

Operations such as browsing the Web and editing text in a word-processing program involve the operating system executing a program. The operating system itself is a program that is running all the time. It executes your instructions and, in turn, it can run other programs.

It is useful to think of a program as a sequence of instructions. Both executable instructions and digital data can be represented as files, for example, on your hard drive. Both are sequences of symbols, just like the letters that make up the words in this sentence. Your job as a programmer is to provide the instructions for new programs.

Let's start with a data file. Use your operating system to locate the file Hello.java and look at its contents.

What did you do to find Hello.java?


Answer:


3.

How did you open Hello.java?


Answer:


4.

The program that you'll be running to write computer programs is your text editor, which sometimes is part of an integrated compiler environment. If you are working in a computer lab, ask your lab guide how to start the editor. If you purchased and installed your own compiler, then follow the vendor's instructions. Go ahead and start the text editor now.

What did you do to start your text editor?


Answer:


5.

R2. Compiling and running programs

Frequently in these labs you will be asked to compile a sample program. Below is a copy of a Java program that displays a drawing. Copy and paste it into your compiler's text editor. Save it as Art.java.

/**
    Displays an 'art' drawing
*/            
public class Art
{
     public static void main(String[] argv)
     {
      String s1 = " *   *   *   *   *   * ";
      String s2 = "   *   *   *   *   *   ";
      String s3 = "__________________________________\\n";
      String s4 = "_________________________________________________________\\n";          

      System.out.print(s4 + s1 + s3 + s2 + s3);      
      System.out.print(s1 + s3 + s2 + s3);      
      System.out.print(s1 + s3 + s2 + s3);      
      System.out.print(s1 + s3 + s2 + s3);      
      System.out.print(s4 + s4 + s4 + s4 + s4);
   }
}

Describe what you did to create the file Art.java.


Answer:


6.

Once you have typed in (or, in this case, pasted in) a program, you need to compile it to create an executable file. Again, these steps depend on your compilation environment. Determine the steps for your computer system, then go ahead and compile Art.java.

Describe what you did.


Answer:


7.

Finally, execute the program. Once again, the steps depend on your computer system.

Describe what you did to execute the program.


Answer:


8.

Describe what happened when the program executed.


Answer:


9.

Writing Simple Programs

Your initial Java programs will be contained entirely in one file. There are some elements that all the programs will share because of the requirements of
the Java language. When you build a program, your compiler looks for code of the form:

public class Classname
{
  public static void main(String[] args)
  {
     /*
        your work goes here
     */
  }
}  

   
The textbook has a program that prints the message Hello, World! on the screen.
   
Try changing it to display Hello, Universe!
   
Type the program into your compiler's editor, compile and test. Then paste the source code in the following text area.


Answer:


10.

P2. Detecting Syntax and Logic Errors

There are numerous opportunities for error in any program, often times in places that seem too simple to require close attention. What do you think the following program is designed to do?

public class Cube
{
   public static void main()
   {
       double height = 3.0; \ inches
       double cube_volume = height * height * height;      
      double surface_area = 8 * height      
      System.out.println("Volume = " cube_volume);
       System.out.println("Surface area = " + surface_area;
}    


Answer:


11.

Will it work as shown? If not, what problems can you identify?


Answer:


12.

Try compiling the program. What were the results? (Use copy and paste to place a copy of your compiler's error messages here.)


Answer:


13.

Fix the syntax errors. Place a copy of your program's output here.


Answer:


14.

The program has two logic errors. Fix them and paste the corrected program here.


Answer: