symbol

Basic Java Programs and Submit

Jmad


Objectives: At the conclusion of  this lab students should:
  • Be able to connect to the Linux server
  • From the Linux server, mount the n-drive.
  • Copy files from the lab machine to the Linux server into an appropriate directory
  • Read values from the keyboard (standard input).
  • Use integer division and remainder
  • Display results with appropriate labes
  • Use the submit system to submit work for reporting and testing
Background: This lab will convert seconds to the correct corresponding hours minutes and seconds.
New Terms:
Scanner 
class methods which return tokens from an input stream
return value
The value a method sends back to the caller at the completion of the method execution
instantiate
The process of creating a new instance of an class
integer division(/) and remainder(%)
Binary operations that perform integer division and produce a whole number quotion and remainder respectively
import statements
Statements in a java program that make available classes from the standard java packages
Linux commands of pwd, cd, cd ~, mount-n, submit, ls, ls -l, rm, cp, man
Materials:

The program will not use any existing components

Prerequisites: Students should come prepared with an algorithm and examples for this lab. Instructions are found here.
Acknowledgement:: Acknowledge the original author of this lab
Turning in
your work:
This lab is adapted from a lab by Arch Harris and Nancy Harris

Part A: Preparation
If you have not already done so, do the homework described in the Prerequisites section. If you have done the homework, you may go to part 2. (NOTE: You may have done this in class.)

Part B: Setting up your environment
  1. Create a new folder for this lab.
Part C: Implementing the algorithm
  1. Create the program, SecondsToHours, using the following structure.
    1. Create the heading using the Javadocs format found in the template. Of course, alter the comments for the current program and change the name of the class inside of  the file.
    2. You will need the import statement that makes Scanner available to your program. (import java.util.Scanner;)
    3. You will create the class declaration and the main method declarations (don't forget the braces to enclose the associated code.
    4. Inside of the main method, all constant and variable declarations will go first. Look at your algorithm and declare all of your containers. You should have at least one constant in your algorithm.
    5. You should declare your Scanner variable with the other declarations.
    6. You will need to instantiate a Scanner object passing it System.in. (Gaddis, Section 2.13)
    7. Next you will deal with the input. You will build a prompt for the input (see item #2 below for specific output requirements), then read the seconds using your Scanner variable and an appropriate next method. Refer to your book for an appropriate method to use.
    8. You will calculate the equivalent hours, minutes, and seconds using your algorithm.
    9. Finally, output the your result.
  2. The program output must be very specific. All students should use the following (feel free to cut and paste):
Part D: The Linux server - stu2.cs.jmu.edu

We will be using a submit system housed on the Linux server to submit our programs for automatic compilation and in some cases testing.  This section will familiarize you with the commands you need to use submit.  If you wish to use the Linux space for file storage, please see the instructor or the reference page that you will find in the Resources section of our Blackboard course.
  1. Access a terminal window on your lab machine(Ctrl-Alt-Fn, where Fn is one of the Function keys 1-6). (This portion of the lab could also be done in a terminal window on the graphical screen, but by only using text screens to connect to stu2, it may make be easier to keep track of which computer you are dealing with.) Execute the pwd command. You are still on the local machine.
  2. Connect to computer stu2.cs.jmu.edu by executing the command, ssh stu2.cs.jmu.edu . You will need to provide your eid password to access the Linux server.  Remember that the password does not echo anything in Linux. 
  3. Execute the command mount-n and give your eid password when it is requested.  Now execute the ls command. Your N: drive should have been mounted into your home directory.   
  4. The www directory is a web accessible directory into which you can put web pages for view by others.  You can use the cp command to copy from the n-drive to your www directory and the scp command to move files into directories in www remotely.  Our web space supports php code.  See the Blackboard resource on Linux commands.
  5. The cd command changes the working directory. On the Linux server use the cd command to change to the sub-directory on your N: drive that you created today. Then execute the ls command to list the contents of this directory. If you do not see your file here, please have a lab assistant or the instructor help you with this step.
  6. There are two important key-strokes to remember in linux: Cntrl-d and Cntrl-c. For a program waiting for input, Cntrl-d tells that program there is no more input to be had. The normal way of logging off linux is to enter the exit command (logout), but Cntrl-d also works because it tells linux there are no more comands to execute. Cntrl-c tells linux to abort any program that is currently running.
  7. Linux has hundreds of commands but you need to learn just a few to effectively use the command line interface for this course. The man command outputs online documentation. To find out more information about the list directory program, execute the command man ls. The following commands may be useful to you. Some we have already used. For the rest of the lab, experiment with these commands and read the online documentation to learn how you can use them to perform basic tasks. (For some of the commands, the online documentation contains many pages of information on a wide variety of options that might take days to fully understand. For this lab, you just want to learn the basics about each command.)
  8. The CS139 top-10 linux commands: man, apropos, pwd, cd, ls, cp, mv, rm, mkdir, rmdir, less (enter `q' at the `:' prompt to exit this program), pico (an editor for text files).
  9. Remain logged into the Linux server.  To access the Windows environment, use Ctrl-Alt-F7.  Reaccess the text screen using Ctr-Alt-Fn that you used before.

Part E: Submitting your work

You should be logged into your local machine, your work should be on the n-drive in a folder, you should have a text window (or terminal window) available logged into the Linux server, and on the Linux server you should be in the lab directory as your working directory.
  1. Type the command:  submit
  2. Answer the prompts as follows:
  3. submit will compile your program and provide a series of messages.  Reports will be placed into your n-drive folder.  When the submit has run, go to your n-drive on the local machine and display the pdf or txt report.  On Windows, use only the pdf report. 
  4. You must work on the program until you see all successes in the screen display.  If you see anything other than successes, you will have a pdf report with messages indicating where the first discrepancy between your output and the expected output are.
  5. Print a copy of your report with you to class on Monday for an activity based on this lab.
AnswerKey
last updated - 09/15/2010 by NLH index