Wednesday, August 19, 2009

Lab 1

Use Netscape/Internet Explorer to get to the lab instructions. It is a good idea to set a bookmark at http://www.csce145.com

  1. The laboratory computer systems run the Microsoft Windows XP operating system. Because it is connected to a server in the College (running Windows Server), you have a login, password, and a "profile" that can follow you around to whatever computer you use within the engineering domain (ENGR). Computer labs are located in Swearingen and 300 South Main (across the street).
  2. Login to the computer. Your login name should be the same as you were assigned by USC when you registered. Change your password. If you've never logged in before, your password should be your Student ID. (A good password should be made up of a combination of letters, both uppercase and lowercase, and numbers.)
  3. Note the desktop (i.e., the appearance of the screen). Everyone’s desktop is identical now, but it’s your desktop. Take an inventory of the things on the desktop. You can change it as you wish at your convenience.
  4. What you need for CSCE 145 is primarily Internet Explorer, Java, Eclipse, and the textbook software.
  5. Double click on the My Computer icon to see what you have. In particular, there are several drives: such as C:, H:, P:, and Z:. We will concentrate on drive H:.
  6. Open the H: drive by double-clicking on it. Create a new folder on H: called csce145; open the csce145 directory by double-clicking on it; now create a lab01 directory.
  7. You are next going to place an icon on the desktop for eclipse. Locate the eclipse folder by clicking on the Start menu, then Programs, CSE Apps, and eclipse. Click on the eclipse icon using the right mouse button. From the menu that appears, choose "send to" and then "Desktop (shortcut)". This will place a shortcut to the eclipse development environment on your desktop for ease of use.
  8. Right click the eclipse shortcut that you just made and select properties. Go to Start in and put in the home directory that you made on your H: drive earlier (e.g.: H:\csce145)
  9. Open eclipse by double-clicking on its icon on the desktop. If the "Welcome" window appears, click on the icon for the "Workbench." Eclipse will request that you "Select a workspace." Choose the default, which should be H:\csce145\workspace. If it is not there, type it in and click OK.
  10. Use File/New/Project and then choose Java Project and click next. In the window that pops up, choose a project name of lab01 and click next.
  11. Finally click finish at the bottom.
  12. For the lab this week, you will write a Java program to do simple interaction with a user (you, in this case).
  13. Right click on lab01 in the left Package Explorer frame and choose "new class". In the window that pops up, choose a meaningful name for your class (e.g., FirstProgram) and type it in the Name box. In the "which method stubs would you like to create?" section, check the box for public static void main(String[] args). Click the Finish button.
  14. A new class file will be created with the basic code you will need for your assignment. Include the following statement at the beginning of the class so that you can use the Scanner class: import java.util.Scanner;
  15. Then, just below the line with public static void main(String[] args) type:
        System.out.println("Hello out there.");
        //two forward slashes means the rest of the line is a comment!!!!
    
        //make a String variable with your    first name -- change this to your first name
        String firstName = "Clint";
        //make a String variable with your last name -- change this to your last name
        String lastName = "Fuchs";
    
        //make a char variable that indicates the grade you want to make in this class
        char grade = 'A'; //note single quotes ' around characters
    
        //Finally output all of that information to the screen
        System.out.println("My first name is " + firstName + " and my last name is " + lastName +
                " and if I study hard, I will make a(n) " + grade + " in CSCE145!");
    
    
        //prompt the user to input two numbers to add
        System.out.println("I will now add two integer values, please enter the two integer values separated by a space: ");
    
        //now we need to create and connect a Scanner object to the keyboard
        Scanner keyboard = new Scanner(System.in);
    
        //now we can use the keyboard object to retrieve values from the user
        int value1 = keyboard.nextInt();
        int value2 = keyboard.nextInt();
        int result = value1 + value2;
    
        System.out.println("The result of adding " + value1 + " and " + value2 + " is: " + result);
    
        System.out.println("Goodbye");        
    
    If you make a typing mistake you can correct it with the backspace or delete key. If you have positioned the cursor somewhere else, then you can use the four arrow keys to get back to the correct line.
  16. Use the File/Save to save and compile the program. If there is an error while compiling your code it will show up in the tasks window of eclipse workbench with a red cross in the first column, description and line number where it occurs.
  17. Navigate to Run/Run As/Java Application menu to run your program. Run your program a few times so that you can see it work. Try to understand what each line of code is actually doing.

Congratulations! You've just written and run your first Java program (at least in CSCE 145).

No comments: