LabExercise 0: Getting Started
COMP102/112 2022 Tri 1: Introductory Lab ExerciseDue 10 Mar 10am
OverviewThis lab exercise introduces you to the software that you will be using for your lab assignments, gets you to run and modify a very simple Java program, and presents a programming puzzle in which you have to write instructions for a mouse in a maze.
GoalsAfter completing this lab exercise you should:
- Know the basics of operating a linux workstation with KDE. (If you were in the physical labs)
- Be able to access course information and download the necessary files from the ECS course pages.
- Be able to use BlueJ to read, edit, and run small Java programs.
- Be able to use the online submission system to submit your files.
- Be able to write a program to direct a mouse out of a maze.
Resources and links
- Download Zip file of necessary code and data.
- Submit your answers.
- Ask for online assistance from the staff.
- Modified version of
Experience.txtfile with answers to the questions.
Summary of the lab exerciseThere are eight parts in this lab exercise.
- Registering and logging on:
Make sure you registered to uses the ECS computer systems. If you are physically in the labs, make sure that you can log on to the lab computer systems and read the Lab rules.
- In-person: Driving the lab computers:
Make sure you can access, copy, move, and delete files. Do this part only if you are physically in a lab.
Online: Setting up for online labs:
Download and install OBS, BlueJ, and the ecs100 library.
- Navigating the COMP 102-112 web pages:
Make sure you can access information on the COMP 102-112 web site, including the files you need for your assignments.
- Using the web-based submission system:
Make sure you can submit your assignments for this course, by submitting
- Running BlueJ:
Make sure you can run BlueJ (the Java program development environment you will use for editing and running Java programs) by running
NameTagPrinter.javainside BlueJ, editing it to make the name tags different, and then submitting your edited
- Solving a programming puzzle:
MazeMouseprogram, and get the mouse out of the maze. This is a good thing to do with the students next to you in the lab or on zoom.
- Extending your java program:
Add some new features to
NameTagPrinter.java. Again, work with the students next to you.
- Final part:
Experience.txtfile and submit it.
1: Registering and Logging onIn order to use the ECS lab computers, including the assignment submission system, you must have an active ECS username and password. This identifies you as an authorised user, and allows you to access your files, and various files provided by the School. Note that the ECS computers are on a different system from the rest of the university, and therefore you need to set up your username and password on the ECS computers. Your username will be the same as on the other university computers, but your password should be different. Your username is case sensitive and only contains lower case letters and digits. The first thing to do is to register/activate your ECS account (unless you have already done it via the web at https://ecs.wgtn.ac.nz/register).
- If you are doing the lab remotely, go to https://ecs.wgtn.ac.nz/register) and work through the registration process to register as a VUW Student, using your VUW usercode and password. This will allow you to use the assignment submission system and access pages on the ECS website that are restricted to enrolled students.
- If you are physically in the ECS labs, log in to your workstation using the username
registerand the password
register(all lower case).
- The computer will then lead you through the remainder of the registration process.
- Please read the lab rules carefully - it is important that you know what you can and can't do on the ECS lab computers.
- Note, the computers in the ECS labs should initially be displaying a login window. If the screen is dark, it may be in power-saving mode, and moving the mouse will re-activate it. If the computer shows a desktop screen because someone else is logged in already, ask your tutor for help.
- Once you have successfully activated your ECS account, you can log on, using your username and password. The login process takes some moments to run, so be patient. If your username and password do not seem to work, ask the lab tutor for help.
2A: Using KDE Note: This section is not relevant for students working who are not physically present in the School of Computer Science lab.KDE provides a desktop environment, similar to Windows on a PC, or a Macintosh. The most important element is the "start" button in the bottom left, which is like the "Start" button on Windows. Unless you have used KDE before, you should work through the Introduction to KDE tutorial. (There should be a pile of printed copies of the tutorial in the lab). If you have any questions or problems with tutorial, please ask a tutor. For most assignments, we will provide demo programs to show you how your java programs should work. These are provided in the
COMP112folder on your desktop, and you can run them on the lab workstations. They cannot be run on your home machine (to make this possible would give away all the answers). For this lab exercise, there is an example demo program you can try out. Now, using the file browser, navigate to the
lab0-demosfolder in the
COMP112folder on your desktop, and run the
TriangleDemoprogram by clicking on it. Note that you don't have to write this program!! The KDE tutorial and the rest of this lab exercise only introduce the bare essentials needed to do the practical work for COMP 102-112. You will learn more as you become familiar withDownload Zip file of necessary code and data. the computer system and become more confident in using it. We expect you to learn much of this by yourself by exploring the various menus, buttons, etc, by trying things out to see what they do, and by talking to tutors and other students. You might also find it useful to read this handout again in a few weeks, to remind you of what it covered.
2B: Online LabsTo make the Online labs work, you need to:
- Setup OBS and make a virtual camera so that the tutors can help you properly, and so that you can work with the other students in your online lab group. The link has instructions for doing this. It may be more problematic on a Mac. After setting up (and starting) the virtual camera in OBS, you should be able to select that camera from inside zoom to act as your webcam.
- Install BlueJ and the ecs100 library. The instructions contain the links for downloading the software and the details of how to set up BlueJ with the library. You won't be able to do any of your assignments until you have this.
- Download the Zip file of code for this lab. (The link is also at the top of this page under "Resources". You will need to download a zip file for every assignment.) After downloading, make sure it is unzipped and the folder is stored in a sensible place on your disk. You should probably make a
COMP 102(or 112) folder with an
Assignmentsfolder in it, where you put each assignment folder. This has the
NameTagPrinterprogram that you will need in the later section of this lab.
3: Using a browser to access the COMP102/112 web siteIf you are on zoom, then just use your regular web browser. If you are physically in the lab, KDE provides several web browsers, including Firefox, and Google Chrome. To start up a browser, click on the appropriate icon or use the startup menu. When your browser first starts up, you may see a License Agreement window. If so, click on the "Accept" button. If the school's home page is not showing, get to the school home page by typing
www.wgtn.ac.nz/ecsinto the white box at the top of the window, and then typing return. All information about COMP102 and COMP112 is on the COMP102 website. To access the COMP102 website, you can:
- Type in the URL
http://ecs.wgtn.ac.nz/Main, and click on the COMP102 link in the Courses section.
- Or, in the case you are not fully enrolled yet in the course, just type in the URL
- Or, from the ECS home page, select the "Wiki" in the top left hand green menu or in the collection of links at the bottom of the page, and then "Course Homepages" from the left-hand menu. This will bring up a page containing all the courses. Select "Home page" in the entry for COMP102. Do not google "COMP102": it will usually lead you to an older version of the course.
- Or, navigate to the COMP102 homepage from the course pages on Blackboard, (if you are using Blackboard for your other courses.)
COMP-102-112-2022T1-Lab0in your home folder containing the files you need. Make sure that it contains a folder called
NameTagPrinter, a folder called
MazeMouse, and a file called
Experience.txt. Note: You can do the same thing from your home computer to download the files to that computer.
4: Submitting your answersFor every assignment, when you have finished your program or programs, you should submit them using the online submission system. In your web browser, go to the top of the Lab Exercise 0 page, and click on the "Submit" link. It should look something like this: Note, if you are enrolled in COMP112, don't worry. You should still be using the COMP102 submission pages. The submission page will let you upload your files to the submission system, where the tutors and markers can access them. You may re-submit the same file as often as you like, but the submission system will only remember the latest version of each file. Use the "+Upload files..." button, then navigate to and select the
NameTagPrinter.javafile, (which you downloaded in the previous section). Once you have uploaded the
NameTagPrinter.javafile, it should look like this: Note
- the green line indicates that the file was successfully added. If you click on the Submission logs button, you will also notice that your file is recorded as being uploaded.
- the green tick next to the name
NameTagPrinter.javain the Assessment Info panel shows that you have submitted one of the required files.
NameTagPrinter.ctxt(this is a file created by BlueJ), the line will turn red as in the image below: The error message helps you identify what the problem is. In COMP 102-112 you are also permitted and encouraged to work on the core and completion parts of the assignments in pairs, as long as you both include the name of the person you worked with in the files for your assignment. If you worked with someone, then you should also specify their name or username in the submission system so that it is properly recorded. Enter the name of the person you worked with in the "Details of working in pairs" section and click on the "Update" button. Note that for the information to be recorded, you must click on the "Update" button. Finally, when you have submitted all the required files, click the "Run checks" button to run automated checking of your submitted files that we have set for each assignment (it will also email you a receipt if the completion process is successful). As you have not yet met all the requirements of this lab exercise (you still need to add the
Experience.txtfile), you will see the following image. Note this contains instructions on how to fix the submission. Even if the "Run checks" button results in an error message, the files you have submitted have still been accepted - you can see a list of all the files that you have successfully submitted in the "Submitted Files" section (and you check them by clicking on their names). Once this you do part 8 of this lab exercise and submit your
Experience.txtfile, your checking process should succeed and you will be presented with the following screen. Note how the box surrounding the "Run checks" button has now turned green and shows the time of your completion. Note, if you don't click this button, you have still successfully submitted the files - they just haven't had the automated checking and you won't get a receipt The "Submission Status" area can show in three different colours:
- red indicates that no files have been submitted. If you have submitted some files and then deleted all of them, the "Submission Status" area will turn back to red, indicating there are no files to be marked.
- blue indicates that some files have been submitted but the Run Checks has not been run on this set of files, or you have not yet submitted all the required files, or the Run Checks found an error. (For comp102, this means that some files did not compile.)
- green indicates that all the required files have been submitted and the Run Checks process has reported no error. (For comp102 this indicates that the files have compiled. It will list the files it has compiled.)
Extension RequestsThe submission system allows you to request extensions. Please note that you have ONE "LATE DAY" - 24 hours of automatic extension which will be applied to any assignment or assignments during the course, as needed. You do not need to apply for them, instead any late hours you have left will be automatically applied to assignments that you submit late. For exceptional circumstances you may need to make arrangements with the course coordinator and request an extension. You can do this by first click on the "Extensions" link at the top right of a submission page. This will direct you to Extension Requests for COMP102 page. This page display the Extensions that have been granted in the "Current Extensions" section at the top, and the ones you have requested in the "Previous Requests" section below. To make a request, click on the "Request Extension" button. It will allow you to select the assignment, enter a Justification/Explanation, and attach supporting documents. Please do not try this now and only use when necessary. Once your request has been sent, the course coordinator will receive an email. You will be notify by email when the extension is granted.
5: Java and BlueJThis section of the lab exercise will lead you through just the first steps of using BlueJ to write Java programs. Java is the programming language you will use in the course, and BlueJ is an application that allows you to construct, run, and debug Java programs. If you are doing the lab online, then you will need to install BlueJ on your laptop or home computer, look at the JavaResources page (click the JavaResources link on the left panel), and then click on the *Using Java and BlueJ at home* link. This has instructions for how to install BlueJ and set it up correctly. If you are physically in the lab, then BlueJ is already installed for you. For this lab, we will go through the steps of using BlueJ to run a program, and make minor changes to it. Opening a Java program with BlueJ A Java program consists of one or more files containing Java source code; these files must have names ending in
.javaBlueJ has a "project" for each program that you are working on. A BlueJ project is a folder that contains all the Java files for the program, along with any data files the program uses, the class files that the compiler creates (which is what the computer actually runs), and several other files that BlueJ creates itself. When you download the files for an assignment, any Java programs should already be organised into BlueJ projects. Check that your
COMP-102-112-2022T1-Lab0folder contains a folder called
NameTagPrinter; this is a BlueJ project. To work on a Java program, the safest way is to start up BlueJ and then open the project for that program from inside BlueJ. You may also be able to double click on the
package.bluejicon in the project folder, but this doesn't always work. Start up BlueJ (On the lab computers, click the "Start" button, then select "BlueJ" from the "Development" submenu). Open the
NameTagPrinterprogram from inside BlueJ using the "Open Project" option from the "Project" menu, and navigating to the
NameTagPrinterfolder. This should open a window like the following:
NameTagPrinterprogram displays a name tag in two different ways. The program is very small and contains just one Java file:
NameTagPrinter.javaBlueJ displays each class in the program (each class corresponds to one Java file in the project) as an orange rectangle. If you right-click on the rectangle for a class, it will pop up a menu of actions that you can perform on the class or its file: including "Open Editor" (to read and edit the program) and "Compile" (to compile the file). If the file is compiled, then there will be additional actions. View the
NameTagPrinter.javafile using the "Open Editor" command. Note you can double click on the rectangle for the class to activate the "Open Editor" command. It should open up a new window with the Java program code. The
NameTagPrinterprogram has three methods, each of which have a sequence of actions. Read through them and try to guess what they will do. (The "UI" in the code refers to the user interface window where the programs will read and print text and draw shapes.) Before a Java program can be run (or "executed"), it must first be "compiled" (ie translated) into Java byte code - a form that the computer can execute. The compiled form is stored in files with names ending in
.classIf a Java file has been compiled (and is therefore ready to be run), BlueJ will show the corresponding rectangle in the project window as plain orange; if it hasn't been compiled, it will have diagonal shading on it. Compile the
NameTagPrinter.javafile, by right-clicking the NameTagPrinter rectangle and choosing
Compile, or by clicking the "Compile" button on the left of the project window. The rectangle should turn plain orange. (Check with your tutor if it doesn't).
It is possible, especially on other computers not in the ECS labs, that the
NameTagPrinterobject. Right click on the
NameTagPrinterrectangle, and choose the
new NameTagPrinter()option. When it asks for the name of the instance (the object), just click "OK". This will create a new red rectangle at the bottom of the BlueJ window representing the new
NameTagPrinterobject. Right click on the new red rectangle at the bottom of the BlueJ window, (the
NameTagPrinterobject), and select one of the actions: Choose the
void drawNameTag()option. Now do it again, but choose the
void printNameTag()option. There is also another way of running this program using buttons: Choose the
void setupGUI()option. The program should put some buttons on the window. Click the buttons. Do they do what you expected? You now know how to run a simple Java program using BlueJ.
NameTagPrinterrectangle (the orange class, not the red object). Now modify the program so that it says "Hi I'm" on the name tag instead of "HELLO, my name is". You can change either (or both) of the
drawNameTagmethods. Run the methods again to check that your modifications were correct. Note that you will need to compile the program again before you can run the methods.
You now know the basics of running and editing a simple Java program using BlueJ. Close BlueJ. Submit your modified version of
NameTagPrinter.java. Make sure that you submit the
.javafile, not the
.classfile is the compiled version which the markers cannot read!
6: Solving a programming puzzleThis part of the lab exercise is optional, and only if you have time. It involves working out instructions (ie, a program) for a mouse that is trying to get out of a maze. The
MazeMouseprogram (part of the zip file you downloaded and unpacked) will let you try out your mouse instructions. You can watch a short video of the MazeMouse program to help understand what you have to do. From inside BlueJ, open the
MazeMouseprogram using the "Open Project" option from the "Project" menu, and navigating to the
MazeMousefolder. (You may have to restart BlueJ if you closed it. You may also want to close the
NameTagPrinterprogram if it is getting in the way; BlueJ is happy to have two separate programs open at once, but it tends to get confusing.) Run the
MazeMouseprogram by right-clicking on the
MazeMouserectangle and choosing
new MazeMouse(). Right click on the
MazeMouseobject and choose the
void setupGUI()option. [Note: the video runs the program in a slightly different way.] You should now see a simple square maze with a mouse in the top left corner. You can modify the maze by clicking on squares to change walls to spaces and vice versa. The basic actions of the mouse are to move forward ("
F"), turn left ("
L"), and turn right ("
R"). Your program for the mouse will consist of sequences of these basic actions. For example, the sequence "
FFLF" would make it take two steps forward, turn left, and take one more step forward. The mouse is very short sighted and can only see the square ahead of it and the squares on each side. It can distinguish five different situations:
- Space ahead: There's a blank space ahead of the mouse (it ignores what's on each side)
- Space only on left: There's a wall ahead of the mouse, and to its right, but a blank space to its left.
- Space only on right: There's a wall ahead of the mouse, and to its left, but a blank space to its right.
- Space both sides: There's a wall ahead of the mouse, but blank spaces to both its left and its right.
- At dead end: There are walls ahead of the mouse and on both sides.
L's in each of the white boxes in the left hand panel. For example, you might want to make it take two steps forward when there is a space ahead, so you would type one
FFin the "Space ahead" box. You can then make the mouse follow your instructions using the "Step" or "Run" buttons. Your goal is to find a set of instructions for the mouse that will enable it to get out of the maze, whatever the shape of the maze! You can assume that the mouse always starts in the top left corner of the maze (the "Restart" button will put the mouse back in the corner). The obvious instructions don't work, so you will have to think more carefully! Once you have some instructions that seem to work, try changing the maze to check that it still works correctly. Get in a group of three people to discuss your ideas for solving the puzzle. When you come up with a possible program, try it out, and try to find a way of "breaking it" - changing the maze so that it won't work. Can you get a program for the mouse that will work on any maze?
7: Extending your java program(Optional - only if you have time) We haven't covered very much Java in the lectures yet, but you should already be able to use the ideas from the
NameTagPrinterprogram and the
TemperatureCalculatorto extend the
NameTagPrinterprogram in several ways. In small groups of three, work on the following changes:
- make it draw a larger rectangle;
- draw the name tag as a circular button;
- make the name tag have a coloured background;
- make it draw two nametags (a button and a desk nameplate) next to each other;
- make it ask for name and school, and put both on the nametag.
- make the name tag have an image in the top left corner (you can copy an image from anywhere to get this).
- make the name tag be the right size for the name - longer names have wider name tags (you may need to find out how many characters are in the name!)
- make the program ask the user for the width and height of the nameplate, and draw the nameplate with a rectangle that size.
- make the fontsize of the name be 1/4 of the height of the nameplate, (whatever height the user entered).
8: Final partThe most important part of the learning in this course happens while you are writing programs for the assignments. Doing programming is critical to learning about programming. But you will learn more if you also think about what you have done and put things together to to get a deeper understanding. In most assignments, we will invite you to consolidate your learning by giving you some questions to prompt and lead your thinking. You do not need to submit answers to them. They will be in the "To go further" section at the bottom of the assignment page. For this lab however, we ask you to tell us briefly about what programming experience you have had, if any. It is fine to say "none" if you haven't had any. Please write your answer in the file
Experience.txtand submit it. Submit
Experience.txtin the same way that you submitted
NameTagPrinter.java. Complete the submission process.
AfterwordThere are several important links at the bottom of the course home page:
- Support.WebHome has lots of useful documentation on many different aspects of the ECS computing system. Read through the list of topics just to get an idea of what is there - you may need some of it later.
- Change password, lets you change your password on the ECS computer systems (which are also needed for accessing the forum and the submission system from home).
- Read the advice about password security and phishing.