# Assignments

# Assignment #1a

## misweb registration

Our class uses misweb for the class's course technology. We do not use MyCourses, or any other course technology system. You can use either a desktop computer or a mobile device (with a web browser) to access our class's online resources:

1\. In your web browser, go to the main misweb page: misweb.business.msstate.edu

This will take you to the main misweb page, which displays the College of Business (COB) academic areas.

2\. In a desktop browser, you will see a list of all of the COB faculty. A mobile browser (with its much smaller screen) will display only the academic areas – on a mobile device, you will need to tap on your teacher's academic area to open a list of faculty in that area.

3\. Tap on your teacher's name to go to his or her faculty profile page.

4\. In a desktop browser, you will see your teacher's complete misweb page; scroll down to the Courses Taught section. In a mobile browser, tap on the "Courses taught" button; this will open a list of courses that your teacher teaches.

5\. Find your class in the list of your teacher's courses taught, and tap on the "online gradebook" button for that class.

6\. You will see a login page similar to the one shown to the right. When the login page loads in your browser, you can save a bookmark to that page for fast access to this page in the future.

<span class="qowt-font4-CourierNew" id="E184">If you have not previously registered for misweb, you will need to register. Upon trying to log in, you will see a form that has several input fields. Enter any information that is needed to complete all fields. Please try to type correctly!</span>

<span class="qowt-font4-CourierNew" id="E187">Click the </span><span class="qowt-font4-CourierNew" id="E188">Continue</span><span class="qowt-font4-CourierNew" id="E189"> button. That’s all there is to it! You are now registered for the misweb system. You can now access any of your class's course technology.</span>

<span class="qowt-font4-CourierNew" id="E194">If you have any questions about this system, please email:</span>

<span class="qowt-font4-CourierNew" id="E197">rodney.pearson@msstate.edu</span>

<span class="qowt-font4-CourierNew" id="E203">Checking your misweb online grades</span>

<span class="qowt-font4-CourierNew" id="E206">To check your grades, go to the main misweb page, at:</span>

<span class="qowt-font4-CourierNew" id="E209">http://misweb.business.msstate.edu</span>

<span class="qowt-font4-CourierNew" id="E212">Go to your teacher's faculty profile page. Scroll down to the </span><span class="qowt-font4-CourierNew" id="E213">Courses Taught</span><span class="qowt-font4-CourierNew" id="E214"> section. Click on any link for Online Grades.</span>

<span class="qowt-font4-CourierNew" id="E217">On the next screen, select your class from the list of Online Gradebooks, enter your net id and password in the textfields, and click the </span><span class="qowt-font4-CourierNew" id="E218">Log in</span><span class="qowt-font4-CourierNew" id="E219"> button.</span>

<span class="qowt-font4-CourierNew" id="E222">Assuming that you log in correctly, you will see one or more buttons for your class. These buttons (if available) link to:</span>

- <span class="qowt-font4-CourierNew" id="E224">your grades</span>
- <span class="qowt-font4-CourierNew" id="E226">the private course web site</span>
- <span class="qowt-font4-CourierNew" id="E228">an online class calendar</span>
- <span class="qowt-font4-CourierNew" id="E230">the class email archive</span>
- <span class="qowt-font4-CourierNew" id="E232">the class message board</span>

<span class="qowt-font4-CourierNew"> </span>

<span class="qowt-font4-CourierNew" id="E235">The </span><span class="qowt-font4-CourierNew" id="E236">button</span><span class="qowt-font4-CourierNew" id="E237">s</span><span class="qowt-font4-CourierNew" id="E238"> page</span><span class="qowt-font4-CourierNew" id="E239"> also has a link at the very top that you can use to </span><span class="qowt-font4-CourierNew" id="E240">log out</span><span class="qowt-font4-CourierNew" id="E241"> of misweb. For (your own) security reasons, you should always log out rather than just moving to a different web page, since logging out physically terminates your misweb session.</span>

### <span class="qowt-font4-CourierNew" id="E246">For your homework assignment, you must do the following:</span>

<span class="qowt-font4-CourierNew" id="E249"> 1. Register for misweb.</span>

<span class="qowt-font4-CourierNew" id="E251"> 2. Enter your basic information. You must enter your name and email address; everything else is optional.</span>

<span class="qowt-font4-CourierNew" id="E253"> 3. Check your grades in this class.</span>

<span class="qowt-font4-CourierNew" id="E255"> 4. While you are checking your grades, familiarize yourself with the available buttons, such as Private Course Web Site, EMail Archive, and Class Message Board.</span>

<span class="qowt-font4-CourierNew" id="E257"> 5. Post a message on the Class Message Board under the Topic:</span>

<span class="qowt-font4-CourierNew" id="E260"> Characteristics of a Good Software Developer</span>

<span class="qowt-font4-CourierNew" id="E263">If the Topic has not been created yet, create it. If it has been created, add your message to the Topic. Try to add something meaningful.</span>

<table class="qowt-stl-TableNormal" id="bkmrk-pay-attention-to-wha"><colgroup id="columns"><col></col></colgroup><tbody><tr id="E266"><td colspan="1" id="E267" rowspan="1"><span class="qowt-font4-CourierNew" id="E269">Pay attention to what you are doing when you post a message on the Class Message Board. If the Topic already exists, </span><span class="qowt-font4-CourierNew" id="E270">DO NOT CREATE A NEW TOPIC</span><span class="qowt-font4-CourierNew" id="E271">. Instead, add a message to the existing Topic.</span>

<span class="qowt-font4-CourierNew" id="E274">To add a message to an existing topic, you must actually read at least one existing message on the topic. When you read a message, you will see a button to </span><span class="qowt-font4-CourierNew" id="E275">Post a New Message</span><span class="qowt-font4-CourierNew" id="E276">.</span>

</td></tr></tbody></table>

<span class="qowt-font4-CourierNew" id="E280">6. When you access the class message board, you will see an option at the bottom to set your “Message Board notification” level. Select “detail”, so you get an automatic email as soon as anyone posts a message to the class message board. This is a required part of this assignment.</span>

<table class="qowt-stl-TableNormal" id="bkmrk-%C2%A0-the-messages-post"><colgroup id="columns"><col></col></colgroup><tbody><tr id="E283"><td colspan="1" id="E284" rowspan="1"><span class="qowt-font4-CourierNew" id="E287">The messages posted on the class message board could be an invaluable tool when you are working on your homework assignments.</span>

</td></tr></tbody></table>

<span class="qowt-font4-CourierNew" id="E292">You do not need to turn in any type of paper or report for this assignment (or any other assignment in this class). Everything will be graded electronically.</span>

## <span class="qowt-font4-CourierNew" id="E296">misweb Online Gradebook System mobile access</span>

## <span class="qowt-font4-CourierNew" id="E298">Student Instructions</span>

<span class="qowt-font4-CourierNew" id="E301">A new feature in misweb provides you with convenient access to selected course technology through your mobile web browser (smartphone, laptop, or other mobile device). Once set up, you will be able to access your online grades, course web site, and more with just a few simple taps on your mobile device.</span>

<span class="qowt-font4-CourierNew" id="E304">To set your device up for quick access in the future, follow these one-time steps:</span>

<span class="qowt-font4-CourierNew" id="E306">1. In your device's web browser, go to the main misweb page: misweb.business.msstate.edu</span>

<span class="qowt-font4-CourierNew" id="E308"> This will take you to the main misweb page, which displays the College of Business academic areas.</span>

<span class="qowt-font4-CourierNew" id="E310">2. Tap on your teacher's academic area to open a list of faculty in that area.</span>

<span class="qowt-font4-CourierNew" id="E312">3. Tap on your teacher's name to go to his or her faculty profile page. </span>

<span contenteditable="false" id="E314"></span><span class="qowt-font4-CourierNew" id="E316">4. On your teacher's misweb page, tap on the "Courses taught" button. This will open a list of courses that your teacher teaches.</span>

<span class="qowt-font4-CourierNew" id="E318">5. Find your class in the list of courses, and tap on the "online gradebook" button for that class.</span>

<span class="qowt-font4-CourierNew" id="E320">6. You will see a login page similar to the one shown to the right. When the login page loads in your browser, you can save a bookmark to that page for fast access in the future. \[On an iPhone, iPod Touch, or iPad, tap the middle icon at the bottom of the screen (a rectangle, with an arrow pointing to the right), and select the “Add to Home Screen” option. This will create an icon on your Home Screen that you can use in the future to quickly check your grades in this class.\]</span>

<span class="qowt-font4-CourierNew" id="E323">On this login page, you can select your class from your teacher's list of online gradebooks, enter your net id, and save that information on your device for future accesses. With that information saved, all you will need to do in future accesses is tap your home screen icon, type in your net password, and tap the Log in button.</span>

You can save your net password on your device as well, although for privacy and security reasons, this is not recommended. If you do save your net password on your device, on future accesses you will simply tap your home screen icon, then the Log in button. Two taps, and you're logged in.

Upon logging in, you will see a concise version of the Online Gradebook System, with larger buttons, larger text, and no superfluous text (as shown to the left).

<table cellpadding="7" cellspacing="0" id="bkmrk-%C2%A0-caching-%C2%A0-%C2%A0-be-" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Roboto, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 15px;" width="639"><tbody><tr><td bgcolor="#f3f3f3" style="background: #f3f3f3;" valign="top" width="623"><span style="font-family: Courier New;">**Caching**</span>

<span style="font-family: Courier New;">**Be sure to read this page. It describes a problem that confuses many web users.**</span>

<span style="font-family: Courier New;">If you ever access a web page, and it seems like you are getting an old copy of the page, your web browser may be giving you a copy of that page from its </span><span style="font-family: Courier New;">*cache*</span><span style="font-family: Courier New;">. In general, a </span><span style="font-family: Courier New;">*cache*</span><span style="font-family: Courier New;"> is a temporary holding place. When you access a web page, your browser can store the page in its cache, on your local hard drive. Then, if you ask for the page again, the browser can give you the copy from its cache rather than going back to the internet for the page. If the page has not changed, the copy from cache is just fine. But if the page HAS changed, you have a problem.</span>

<span style="font-family: Courier New;">You can normally force the browser to give you a new copy by holding down the shift key, and clicking on the Refresh (or Reload) button.</span>

<span style="font-family: Courier New;">Past versions of the major browsers had good options that you could use to configure the browser cache settings. The current browsers, however, do not give you many cache configuration options. Always remember to suspect that you might be getting a cached page, and use shift-reload to force your browser to load a new page.</span>

<span style="font-family: Courier New;">As a web professional, always remember that browsers may be configured differently, so something that works one way on one computer may work a different way on a different computer. Caching is one of those things that can be configured differently, and it can really confuse the inexperienced user.</span>

</td></tr></tbody></table>

# Assignment #1b

<span class="qowt-font4-CourierNew"> </span>

## <span class="qowt-font4-CourierNew" id="E371">Programming Environment Setup</span>

<span class="qowt-font4-CourierNew" id="E374">In </span><span class="qowt-font4-CourierNew" id="E375">assignment</span><span class="qowt-font4-CourierNew" id="E376"> #1b</span><span class="qowt-font4-CourierNew" id="E377">, you will download and install several pieces of software. In </span><span class="qowt-font4-CourierNew" id="E378">assignment #1c</span><span class="qowt-font4-CourierNew" id="E379">, you will write your first Java application. Be sure to do </span><span class="qowt-font4-CourierNew" id="E380">a</span><span class="qowt-font4-CourierNew" id="E381">ssignment</span><span class="qowt-font4-CourierNew" id="E382"> #1c</span><span class="qowt-font4-CourierNew" id="E383">!</span>

<span class="qowt-font4-CourierNew" id="E386">The software that we will use during the semester will be made avai</span><span class="qowt-font4-CourierNew" id="E387">lable to you on our course web site</span><span class="qowt-font4-CourierNew" id="E388">. This software is </span><span class="qowt-font4-CourierNew" id="E389">free, public domain software</span><span class="qowt-font4-CourierNew" id="E390">. The software is </span><span class="qowt-font4-CourierNew" id="E391">also </span><span class="qowt-font4-CourierNew" id="E392">available for download from various world wide web sites.</span>

<span class="qowt-font4-CourierNew" id="E395">1</span><span class="qowt-font4-CourierNew" id="E396">. You will need Sun Microsystem’s Java Development Kit </span><span class="qowt-font4-CourierNew" id="E397">(JDK). The JDK is available on </span><span class="qowt-font4-CourierNew" id="E398">our </span><span class="qowt-font4-CourierNew" id="E399">misweb course web site, in both Windows (both 32-bit and 64-bit) and Mac versions. </span><span class="qowt-font4-CourierNew" id="E400">You can accept all default options during this installation.</span><span class="qowt-font4-CourierNew" id="E401"> Java may already be installed on your computer, so you may want to delay this step to see if you encounter a problem in step 3. If step 3 (Eclipse installation) works, you already have the JDK installed on your computer.</span>

<span class="qowt-font4-CourierNew" id="E404">2</span><span class="qowt-font4-CourierNew" id="E405">. </span><span class="qowt-font4-CourierNew" id="E406">(Steps 2 through 6 are optional. You do not need to install an IDE, but you may if you want to.) Some people like an Integrated Development Environment (IDE), in which they type their programs (probably getting type-ahead hints, color coding, delimiter matching, etc) and run the programs, all within that environment. If you want to do this, you can intall</span><span class="qowt-font4-CourierNew" id="E407"> </span><span class="qowt-font4-CourierNew" id="E408">Eclipse</span><span class="qowt-font4-CourierNew" id="E409">. You can download a </span><span class="qowt-font4-CourierNew" id="E410">free </span><span class="qowt-font4-CourierNew" id="E411">copy of Eclipse from http://www.eclipse.org/downloads</span>

<span class="qowt-font4-CourierNew" id="E414"> Download the "Eclipse IDE for Java Developers". You do not need the "EE" (Enterprise Edition) version.</span>

<span class="qowt-font4-CourierNew" id="E417">3</span><span class="qowt-font4-CourierNew" id="E418">. Once downloaded, install</span><span class="qowt-font4-CourierNew" id="E419"> Eclipse as you would any other Windows or Mac program.</span><span class="qowt-font4-CourierNew" id="E420"> (Eclipse requires that you have a Java environment installed on your computer, which you likely already do. If you don't, you can download the Java Development Kit (JDK) from our private course web site.)</span>

<span class="qowt-font4-CourierNew" id="E423">4</span><span class="qowt-font4-CourierNew" id="E424">.</span><span class="qowt-font4-CourierNew" id="E425"> Run Eclipse. The first time you run it, it will ask for your desired location for your projects that you will create. You can use the default location, or customize your own location. Just be sure that you know where you are storing your files, because you'll need to find them later on.</span><span class="qowt-font4-CourierNew" id="E426"> Every Eclipse project that you create will be in a separate folder, underneath the location that you create in this step.</span>

<span class="qowt-font4-CourierNew" id="E428">5</span><span class="qowt-font4-CourierNew" id="E429">. If you see a Welcome window, close it.</span>

<span class="qowt-font4-CourierNew" id="E432">6</span><span class="qowt-font4-CourierNew" id="E433">. By default, Eclipse will format </span><span class="qowt-font4-CourierNew" id="E434">blocks of code with the </span><span class="qowt-font4-CourierNew" id="E435">opening curly brace at the right end of a line, such as:</span>

```qowt-stl-Normal
if(i==0) {

}
```

<span class="qowt-font4-CourierNew" id="E444">Some people prefer that the opening curly brace be on the next line:</span>

```qowt-stl-Normal
if(i==0) 
{

}
```

<span contenteditable="false" id="E454"></span><span class="qowt-font4-CourierNew" id="E456">If you want to configure this, in Eclipse click on Preferences</span><span class="qowt-font4-CourierNew" id="E457"> (in Windows Eclipse, Preferences is under the Window menu option</span><span class="qowt-font4-CourierNew" id="E458">; in Mac Eclipse, it's under the Eclipse menu option</span><span class="qowt-font4-CourierNew" id="E459">)</span><span class="qowt-font4-CourierNew" id="E460">, Java, Code Style, Formatter.</span>

<span class="qowt-font4-CourierNew" id="E463">Click the "New..." button to create</span><span class="qowt-font4-CourierNew" id="E464"> a new </span><span class="qowt-font4-CourierNew" id="E465">Profile</span><span class="qowt-font4-CourierNew" id="E466">.</span><span class="qowt-font4-CourierNew" id="E467"> Name your new profile anything you want.</span>

<span contenteditable="false" id="E469"></span><span class="qowt-font4-CourierNew" id="E472">The "Edit Dialog" will open automatically.</span><span class="qowt-font4-CourierNew" id="E473"> Under the Braces tab, change every setting to "Next Line".</span>

<span class="qowt-font4-CourierNew" id="E484">7</span><span class="qowt-font4-CourierNew" id="E485">. An account will be created for you on the mislab server. Your mislab account name will be based on your Banner net id, such as </span><span class="qowt-font4-CourierNew" id="E486">abc123</span><span class="qowt-font4-CourierNew" id="E487">.</span>

<span class="qowt-font4-CourierNew" id="E490"> You can telnet to mislab.</span><span class="qowt-font4-CourierNew" id="E491">business</span><span class="qowt-font4-CourierNew" id="E492">.msstate.edu to log onto your mislab account. \[Technically, telnet is disabled on the mislab server, because it is considered insecure. An alternate protocol, SSH (Secure Shell), is enabled. These instructions use the generic term telnet, but you must actually use SSH on mislab.\] PuTTY, an excellent, free </span><span class="qowt-font4-CourierNew" id="E493">Windows </span><span class="qowt-font4-CourierNew" id="E494">telnet/SSH program, is available </span><span class="qowt-font4-CourierNew" id="E495">on our course web site.</span><span class="qowt-font4-CourierNew" id="E496"> Installing PuTTY on your computer should be straightforward (simply copy putty.exe to your desired location).</span><span class="qowt-font4-CourierNew" id="E497"> On a Mac computer, you can use the built-in ssh program.</span>

<span contenteditable="false" id="E500"></span><span class="qowt-font4-CourierNew" id="E502">Install PuTTY on your computer. When you open the program (after installation), you will see a screen similar to the one shown to the right. Type </span><span class="qowt-font4-CourierNew" id="E503">mislab.business</span><span class="qowt-font4-CourierNew" id="E504">.msstate.edu</span><span class="qowt-font4-CourierNew" id="E505"> in the Host Name textfield.</span>

<span class="qowt-font4-CourierNew" id="E508">You may want to do one more thing here, changing the default colors to black text on a white background (the default is white text on a black background). If you do want to do this, click on </span><span class="qowt-font4-CourierNew" id="E509">Colours</span><span class="qowt-font4-CourierNew" id="E510"> (on the left), then change the Red, Green, and Blue values for the Foreground and Background settings (for white, change the Red, Green, and Blue values to 255, 255, and 255; for black, change them to 0, 0, and 0).</span>

<span contenteditable="false" id="E513"></span><span class="qowt-font4-CourierNew" id="E515">Click the Save bu</span><span class="qowt-font4-CourierNew" id="E516">tton, which will save mislab.business</span><span class="qowt-font4-CourierNew" id="E517">.msstate.edu as your default Host Name, and save your color scheme. Then click the </span><span class="qowt-font4-CourierNew" id="E518">Open</span><span class="qowt-font4-CourierNew" id="E519"> button. You will be prompted to login. Your login id is equal to your Banner net id.</span>

<span class="qowt-font4-CourierNew" id="E522">Type your login id, and press Enter. You will be prompted for your mislab password. **Your initial password is equal to the last four digits of your MSU student id number.**</span>

<dl id="bkmrk-telnet-note%3A-most-te"><dd><table cellpadding="7" cellspacing="0" style="width: 911px;" width="591"><tbody><tr><td bgcolor="#f3f3f3" style="background: #f3f3f3; width: 911px;" valign="top"><span style="font-family: Courier New;">Telnet note: Most telnet programs will not </span><span style="font-family: Courier New;">*echo*</span><span style="font-family: Courier New;"> your password back onto the screen when you type it. That is, when you type your password, you will not see ANY CHARACTERS from your password displayed on the screen. Carefully type your password, and press </span><span style="font-family: Courier New;">*Enter*</span><span style="font-family: Courier New;">.</span>

</td></tr></tbody></table>

</dd></dl><span style="font-family: Courier New;">Hopefully, you will successfully log in. If you do, you will see a screen similar to the one shown below.</span>

<span style="font-family: Courier New;">After you log in, use the </span><span style="font-family: Courier New;">*passwd*</span><span style="font-family: Courier New;"> command to change your password. Your new password should be at least 6 characters long; it should not be based on a dictionary word. You might want to consider using digits and/or special characters as well. The Linux passwd program is very picky about the password that you select!</span>

<span style="font-family: Courier New;">To change your password, after you telnet to mislab.business.msstate.edu and log in, type:</span>

`<span style="font-family: Courier New;"><strong>passwd</strong></span>`

<span style="font-family: Courier New;">You will be asked for your current password (to authenticate yourself –- don’t want to let just anyone change your password!), and then asked to type your new desired password –- twice.</span>

<span style="font-family: Courier New;">Use the </span><span style="font-family: Courier New;">*chfn*</span><span style="font-family: Courier New;"> command to specify your full name.</span>

`<span style="font-family: Courier New;"><strong>chfn</strong></span>`

<span style="font-family: Courier New;">Type </span><span style="font-family: Courier New;">*logout*</span><span style="font-family: Courier New;"> to log out of your mislab account.</span>

`<span style="font-family: Courier New;"><strong>logout</strong></span>`

<span style="font-family: Courier New;">8. You need to set up your mislab account for web programming. If your user name is </span><span style="font-family: Courier New;">*abc123*</span><span style="font-family: Courier New;">, your web address will be:</span>

<span style="font-family: Courier New;"> http://mislab.business.msstate.edu/~</span><span style="font-family: Courier New;">*abc123*</span>

<span style="font-family: Courier New;"> Throughout the remainder of these instructions, references to </span><span style="font-family: Courier New;">*abc123*</span><span style="font-family: Courier New;"> represent your actual login name.</span>

<span style="font-family: Courier New;"> When you Telnet to mislab and login to your account, you will be in your home directory.</span>

<table cellpadding="7" cellspacing="0" id="bkmrk-public_html-%C2%A0-in-ge" style="width: 833px;" width="591"><tbody><tr><td bgcolor="#f3f3f3" style="background: #f3f3f3; width: 833px;" valign="top"><span style="font-family: Courier New;">**public\_html**</span>

<span style="font-family: Courier New;">In general, subdirectories are a great way to organize your files in a meaningful structure. In this class, however, you will put all of your files in your public\_html directory. This makes it much easier for your teacher to find your files.</span>

</td></tr></tbody></table>

<span style="font-family: Courier New;">Make sure that you are currently in your home directory (that's where you will be placed automatically when you telnet and log in to your account, so you should be there right now). Look at the prompt on the command line. Your prompt should look something like:</span>

`<span style="font-family: Courier New;"> [abc123@mislab abc123]$ _</span>`

<span style="font-family: Courier New;">This prompt shows (in order) your login id, the name of the server, and the </span><span style="font-family: Courier New;">*current*</span><span style="font-family: Courier New;"> directory (the \_ is the cursor).</span>

<span style="font-family: Courier New;">Get a directory listing: (type the letter l, not the digit 1).</span>

<span style="font-family: Courier New;">**`ls -l`** </span><span style="font-family: Courier New;"> get a directory listing</span>

<span style="font-family: Courier New;">The directory listing will show (for example):</span>

`<span style="font-family: Courier New;"> drwxrwxr-x 10 abc123 abc123 5120 Oct 4 13:41 public_html</span>`

<span style="font-family: Courier New;">This directory listing shows several things. First, the first character (d) indicates that this directory entry is a </span><span style="font-family: Courier New;">*directory*</span><span style="font-family: Courier New;">. If the entry related to a file, a dash would appear as the first character. The next nine characters show the </span><span style="font-family: Courier New;">*permissions*</span><span style="font-family: Courier New;"> that apply to this directory. You need to understand Unix directory and file permissions.</span>

<span style="font-family: Courier New;">Unix directories and files have three sets of permissions: one set for the owner of the file (sometimes called </span><span style="font-family: Courier New;">*user*</span><span style="font-family: Courier New;"> permissions); a second set for accounts which are in a Unix group (an individual group will be created for you and your teacher; use the middle set of permissions to give your teacher permission to access your files); and a final set, called </span><span style="font-family: Courier New;">*other*</span><span style="font-family: Courier New;">, or </span><span style="font-family: Courier New;">*world*</span><span style="font-family: Courier New;">, for everyone else. (The acronym </span><span style="font-family: Courier New;">*UGO*</span><span style="font-family: Courier New;"> is sometimes used to refer to User, Group, and Other.) Look at the directory listing again:</span>

`<span style="font-family: Courier New;"> drwxrwxr-x 10 abc123 abc123 5120 Oct 4 13:41 public_html</span>`

<span style="font-family: Courier New;">The nine characters "rwxrwxr-x" indicate the user, group, and other permissions for this directory. The first three characters relate to the user permissions, the next three to the group permissions, and the final three to other permissions. Each entity (user, group, other) can have any combination of three permissions: read, write, and execute. The directory listing above shows:</span>

<span style="font-family: Courier New;"> user permissions: read, write, execute  
</span><span style="font-family: 'Courier New';">group permissions: read, write, execute  
</span><span style="font-family: 'Courier New';">other permissions: read, execute</span>

<span style="font-family: Courier New;">When you create a directory or a file, you need to think about what permissions users will need to that directory or file. In general, you want to give users the minimal permissions necessary to do what they need to do. If users need to read your file, give them read permission. If they need to execute the file, give them execute permission. If they need to write onto your file (high risk! be careful!), give them write permission.</span>

<span style="font-family: Courier New;">Each set of Unix directory permissions consists of three possible rights; each right has a numeric equivalent:</span>

<span style="font-family: Courier New;"> Read = 4 Write = 2 Execute = 1</span>

<span style="font-family: Courier New;">The permissions for a file (or directory) are set with the </span><span style="font-family: Courier New;">*chmod*</span><span style="font-family: Courier New;"> command, specifying a 3-digit number which relates to:</span>

<span style="font-family: Courier New;"> digit </span>

<span style="font-family: Courier New;">\#1 -- user permissions</span>

<span style="font-family: Courier New;"> #2 -- group permissions</span>

<span style="font-family: Courier New;"> #3 -- other permissions</span>

<span style="font-family: Courier New;">Each of the three digits is the sum of the permission rights desired for that entity. If you want to set the permissions on your public\_html directory to (these are common permissions for web-based files):</span>

<span style="font-family: Courier New;"> user permissions: read, write, execute</span>

<span style="font-family: Courier New;"> group permissions: read, execute</span>

<span style="font-family: Courier New;"> other permissions: read, execute</span>

<span style="font-family: Courier New;">The numeric equivalents to these permissions are:</span>

<span style="font-family: Courier New;"> user permissions: 4+2+1 7</span>

<span style="font-family: Courier New;"> group permissions: 4+1 5</span>

<span style="font-family: Courier New;"> other permissions: 4+1 5</span>

<span style="font-family: Courier New;">Use the chmod command to set the correct desired permissions on your public\_html directory:</span>

`<span style="font-family: Courier New;"><strong>chmod 755 public_html</strong></span>`<span style="font-family: Courier New;"> change permissions</span>

<span style="font-family: Courier New;">Now get a new directory listing:</span>

`<span style="font-family: Courier New;"><strong>ls -l </strong></span>`<span style="font-family: Courier New;"> get a directory listing</span>

<span style="font-family: Courier New;">The directory listing will show (for example):</span>

`<span style="font-family: Courier New;"> drwxr-xr-x 10 abc123 abc123 5120 Oct 4 13:41 public_html</span>`

<span style="font-family: Courier New;">his shows that public\_html is a directory. It also shows the three sets of user/group/other permissions. Finally, it shows the group id (GID) and user id (UID) of the owners of the directory. The GID indicates the mislab group who owns this file (</span><span style="font-family: Courier New;">*abc123*</span><span style="font-family: Courier New;">); the UID indicates the user who owns the file (</span><span style="font-family: Courier New;">*abc123*</span><span style="font-family: Courier New;">).</span>

<span style="font-family: Courier New;">9. You will need to create an HTML file in your public\_html subdirectory before you will actually be able to access your web site from a web browser.</span>

<span style="font-family: Courier New;"> As a quick exercise, you can use nano (a Linux text editor) to create an HTML file.</span>

<dl id="bkmrk-%C2%A0-important%3A-put-yo"><dd><table cellpadding="7" cellspacing="0" style="width: 879px;" width="591"><tbody><tr><td style="width: 879px;" valign="top"><span style="font-family: Courier New;">Important: Put your HTML files in your public\_html directory.</span>

</td></tr></tbody></table>

</dd></dl><span style="font-family: Courier New;"> First, be sure to move into your public\_html directory.</span>

`<span style="font-family: Courier New;"><strong>cd public_html</strong></span>`

<span style="font-family: Courier New;"> Your prompt should look something like:</span>

`<span style="font-family: Courier New;"> [abc123@mislab public_html]$</span>`

<span style="font-family: Courier New;"> This prompt shows your login id, the name of the server, and the current directory. Now, to create your new file, type:</span>

`<span style="font-family: Courier New;"><strong> nano index.html</strong></span>`

<span style="font-family: Courier New;"> Type the following HTML code:</span>

```western
<html>
<body>
Hello world
</body>
</html>
```

<span style="font-family: Courier New;">Press &lt;Ctrl&gt;-x to exit nano. Answer "y" to "Save modified buffer?", and press &lt;enter&gt; when prompted for the file name.</span>

<span style="font-family: Courier New;"> Get a directory listing.</span>

`<span style="font-family: Courier New;"><strong>ls -l</strong></span>`

<span style="font-family: Courier New;">Review the permissions on your hello.html file. You may see something like:</span>

`<span style="font-family: Courier New;"> -rw-rw-r-- 10 abc123 abc123 5120 Oct 4 13:41 index.html</span>`

<span style="font-family: Courier New;"> You should now be able to get into your web browser and access your sample web page at (for example):</span>

<span style="font-family: Courier New;"> http://mislab.business.msstate.edu/~</span><span style="font-family: Courier New;">*abc123*</span>

<span style="font-family: Courier New;">10. As soon as possible, a list of all Advanced Languages students will be available at:</span>

<span style="font-family: Courier New;"> http://mislab.business.msstate.edu</span>

<span style="font-family: 'Courier New';">As soon as you create your index.html file, be sure to test your page from the Advanced Languages student list, since that is the page from which grading will be performed.</span>

<dl id="bkmrk-step-7-tells-you-how"><dd><table cellpadding="7" cellspacing="0" style="width: 842px;" width="591"><tbody><tr><td style="width: 842px;" valign="top"><span style="font-family: Courier New;">Step 7 tells you how to install FileZilla on your own computer. If you are using a COBI Lab computer, FileZilla is already installed. You can skip to step 10.</span>

<span style="font-family: Courier New;">On COBI Lab computers, FileZilla is available in the </span><span style="font-family: Courier New;">*Programming Tools*</span><span style="font-family: Courier New;"> icon, right there on the desktop. Double-click the Programming Tools icon to open it.</span>

</td></tr></tbody></table>

</dd></dl><span style="font-family: Courier New;">11. You will need an FTP (File Transfer Protocol) program to upload your work to your mislab account. If you do not already have such a program, you can download </span><span style="font-family: Courier New;">**FileZilla**</span><span style="font-family: Courier New;"> (Windows) from our private course web site. On a Mac computer, YummyFTP is a very good FTP program. At this time, it costs $4.99.</span>

<table cellpadding="7" cellspacing="0" id="bkmrk-if-you-are-using-a-c" style="width: 845px;" width="639"><tbody><tr><td bgcolor="#f3f3f3" style="background: #f3f3f3; width: 845px;" valign="top"><span style="font-family: Courier New;">If you are using a COBI Lab computer, you should store your files on a flash drive.</span>

</td></tr></tbody></table>

<table cellpadding="7" cellspacing="0" id="bkmrk-be-sure-to-upload-yo" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Roboto, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 15px; width: 849px;" width="639"><tbody><tr><td bgcolor="#f3f3f3" style="background: #f3f3f3; width: 849px;" valign="top"><span style="font-family: Courier New;">Be sure to upload your files into your public\_html directory on your mislab account.</span>

</td></tr></tbody></table>

<span style="font-family: Courier New;">12. Download the Java API (Application Programmer's Interface) documentation from the course web site and unzip it on your computer.</span>

<span style="font-family: Courier New;"> You should create a bookmark link in your web browser to the JDK online documentation (the provided documentation gives detailed information about the JDK API -- Application Programmer’s Interface -- all of the classes, methods, and properties available in the JDK).</span>

<span style="font-family: Courier New;"> Get into your web browser and select "File", "Open", then “Choose File”. Browse your JDK directory structure to find the file a file named java\\API\\index.html (there are several of them, read on to make sure you open the correct one).</span>

<span style="font-family: Courier New;"> This page is an alphabetical list of Java classes, properties, and methods.</span>

<span style="font-family: Courier New;"> Save a bookmark to this page, then get used to using this online documentation when you program in Java.</span>

<span style="font-family: Courier New;">13. The programs and files that are included in section 3 of your course packet are available in the /home/bis3523/resources/coursePacket directory on mislab. If you ever want a copy of a program that we go over in class, you’ll know where to find it.</span>

<span style="font-family: Courier New;">14. Finally... an unfortunate fact of life for web developers is that the various web browsers are somewhat incompatible. In this class, the standard is set at the current version of Firefox. That is, your assignments and programming exams will be graded with the Firefox browser. It is highly recommended that you test your programs in this browser so that you can be sure that they will work when they are graded.</span>

<span style="font-family: Courier New;">15. (Windows only) If you want to use the JDK from the command-line (we will on mislab, and you can on your computer if you want to, but this is totally optional), you need to configure your environment. We will probably not need to do anything from the command line on your computer, because we will probably be able to do everything from within Eclipse, so these remaining steps are totally optional.</span>

<span style="font-family: Courier New;">Modify the value of your computer’s Path environment variable. The Path environment variable tells your operating system locations in which to look for executables (such as javac.exe). For this class, you should add c:\\program files\\java\\jdk1.8.0\_20\\bin to your Path. You can do this with the following steps:</span>

<span style="font-family: Courier New;"> 1. open Control Panel</span>

<span style="font-family: Courier New;"> 2. open System</span>

<span style="font-family: Courier New;"> 3. click on the Advanced tab</span>

<span style="font-family: Courier New;"> 4. click on the Environment Variables button</span>

<span style="font-family: Courier New;"> 5. Under System Variables, edit the value of Path</span>

<span style="font-family: Courier New;"> The value of the Path environment variable is a list of directories, separated by semi-colons. Simply add your program files\\java\\jdk1.8.0\_20\\bin directory to the end of this value, after a semi-colon. The next time you open a DOS window, the path will be updated.</span>

<span style="font-family: Courier New;"> When you open a new DOS window, you can type:</span>

`<span style="font-family: Courier New;"> path</span>`

<span style="font-family: Courier New;"> to see the value of your Path environment variable. Your java\\bin directory should be part of that value, and the operating system will look there for executables.</span>

<span style="font-family: Courier New;">16. Test your Java installation. Get to your command line and type:</span>

`<span style="font-family: Courier New;"><strong>javac –version</strong></span>`

<span style="font-family: Courier New;"> This should display the version of the JDK that you just installed. More importantly, it will show that the javac command works. This is the command that you will type in the future to compile your Java programs.</span>

<span style="font-family: Courier New;"> You should see something like:</span>

`<span style="font-family: Courier New;"> javac 1.8.0_20</span>`

<span style="font-family: Courier New;">17. The Java interpreter (JVM) uses an environment variable named Classpath to specify “a list of directories to be searched for .class files”. That is, when you try to run a program, if your program uses any outside .class files, the interpreter will search for those .class files – but it will search only in the directories specified by the value of your Classpath environment variable.</span>

<span style="font-family: Courier New;"> You can check the value of your Classpath environment variable by going to the DOS prompt and typing:</span>

`<span style="font-family: Courier New;"> set classpath</span>`

<span style="font-family: Courier New;"> This will display something like:</span>

`<span style="font-family: Courier New;"><span style="font-size: small;">CLASSPATH=C:\Program Files\Java\jre1.8.0_20\lib\ext\QTJava.zip</span></span>`

<span style="font-family: Courier New;"> This Classpath specifies only one place that the interpreter should look for .class files – in the one listed location. You probably also want the interpreter to ALWAYS look in the current directory first, then elsewhere. To set this up, you need to edit the value of your Classpath environment variable, using steps similar to those followed to modify the value of your Path environment variable.</span>

<span style="font-family: Courier New;"> In directory parlance, . indicates “the current directory”. You want to insert this in your list before the other specified location, so you should change the value to something like:</span>

`<span style="font-family: Courier New;"> .;C:\Program Files\Java\jre1.8.0_20\lib\ext\QTJava.zip</span>`

<span style="font-family: Courier New;">This tells the interpreter, first, search the current directory for .class files; if you don’t find them there, look in the second location.</span>

</body></html>

# Assignment #1c

## Hello World

filenames: HelloWorld.java, HelloWorld.class

(Many of the assignments provide instructions for writing your programs in Eclipse. Using Eclipse is not required. You can type your programs with a standard text editor, and compile from the command-line.)

Write a simple text-based application to test your installed Eclipse environment. Write an application that will display the phrase "Hello world, from Eclipse" to your screen.

First, open Eclipse.

1\. Using the Eclipse menu, select File, New, and Java Project.

2\. This will open the New Java Project window. In the Project name: textfield, enter the name of your project:

`HelloWorld`

(case-sensitive, no spaces)

Click the Finish button. This will create your project.

3\. The Eclipse toolbar has a number of icons. One of these is a green circle with a white C (and a small plus sign in its top right corner). In the screen capture, it's just below the rap10 in the project path. This is the New Class icon. Click it to create a new class for your project.

4\. There are many options available when you create a new class. The first thing we want to do is name the class. In the Name: textfield, type HelloWorld

(case-sensitive, no spaces)

Check one of the checkboxes near the bottom:

`public static void main(String[] args)`

This is the standard (and required) method header for your main method. This is the first method that will be called when you run your program. We could type the method header ourselves, but by checking this checkbox, Eclipse will type if for us.

Click the Finish button. Eclipse will create the file HelloWorld.java, and put it in your project's src folder.

5\. The screen capture to the right shows your initial project, complete with:

\- class header

\- main method header

\- matching curly braces

6\. Type one line of code, inside your main method:

`System.out.println("Hello world, from Eclipse.\n\n");`

7\. Click the Run icon, the green circle with a white arrow pointing to the right. Your output will appear on the Console, the wide area toward the bottom of the Eclipse window.

Hopefully, your first program will run without errors!

8\. Outside Eclipse, find your HelloWorld.class file, in the workspace that you specified. In your "workspace" folder, you will find a separate folder for each project that you create, such as one named HelloWorld. The project folders will contain at least two subfolders: src (which contains .java source code files), and bin (which contains compiled byte code .class files). Look in the bin folder for HelloWorld.class.

Upload HelloWorld.class to your mislab account, into your public\_html directory. Telnet to mislab.business.msstate.edu, log in to your account, and run your byte code in the mislab environment.

`java HelloWorld`

This demonstrates that your byte code is platform-independent. The same byte code will run in your Windows or Mac environment and in mislab's Linux environment. All you need is an appropriate (platform-dependent) JVM in the environment. The byte code is platform-independent; the JVM is platform-dependent. The program named "java" is the JVM on mislab.

9\. Upload your HelloWorld.java file to your mislab account, into your public\_html directory. (It will be in your project's src folder on your local computer.)

Compile it.

`javac HelloWorld.java`

Run your new byte code.

`java HelloWorld`

This demonstrates that your source code is platform-independent. You can create your source code in a Windows, Mac, or Linux environment, then compile it into byte code in a different environment. All you need is an appropriate (platform-dependent) Java compiler in the environment. Your source code is platform-independent; the compiler itself is platform-dependent. "javac" is the compiler on mislab.

# A Brief Linux Reference Guide

## <span class="qowt-font4-CourierNew" id="E1233">Working with directories</span>

- `<span class="qowt-font4-CourierNew" id="E1235">mkdir <name> </span>`<span class="qowt-font4-CourierNew" id="E1236"> </span>
    - <span class="qowt-font4-CourierNew" id="E1237">make subdirectory with specified name</span>
- <span class="qowt-font4-CourierNew" id="E1239">`rmdir <name>` </span>
    - <span class="qowt-font4-CourierNew" id="E1240"> </span><span class="qowt-font4-CourierNew" id="E1241">remove specified subdirectory</span>
- <span class="qowt-font4-CourierNew" id="E1243">`cd <name>` </span>
    - <span class="qowt-font4-CourierNew" id="E1244"> </span><span class="qowt-font4-CourierNew" id="E1245">move down to specified subdirectory</span>
- <span class="qowt-font4-CourierNew" id="E1247">`cd ..` </span>
    - <span class="qowt-font4-CourierNew" id="E1247">move up one directory level</span>
- <span class="qowt-font4-CourierNew" id="E1249">`ls` </span>
    - <span class="qowt-font4-CourierNew" id="E1250"> </span><span class="qowt-font4-CourierNew" id="E1251">get a directory listing</span>
- <span class="qowt-font4-CourierNew" id="E1253">`ls -l` </span>
    - <span class="qowt-font4-CourierNew" id="E1253">directory listing, long format (letter l)</span>
- <span class="qowt-font4-CourierNew" id="E1255">`ls -al` </span>
    - <span class="qowt-font4-CourierNew" id="E1255">directory listing, including hidden files</span>

## Working with files

- <span class="qowt-font4-CourierNew" id="E1261">`more <filename>` </span>
    - <span class="qowt-font4-CourierNew" id="E1261">display the contents of the file, a page at </span><span class="qowt-font4-CourierNew" id="E1263">a time</span><span class="qowt-font4-CourierNew" id="E1264"> </span><span class="qowt-font4-CourierNew" id="E1265">(press &lt;space&gt; to go to next page, </span><span class="qowt-font4-CourierNew" id="E1267">or &lt;b&gt; to back up to the previous page)</span>
- <span class="qowt-font4-CourierNew" id="E1269">`chmod <permissions> <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1270">set the permissions on &lt;file&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1272">`chown <UID>.<GID> <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1273"> </span><span class="qowt-font4-CourierNew" id="E1274">change the user.group owner</span><span class="qowt-font4-CourierNew" id="E1275"> </span><span class="qowt-font4-CourierNew" id="E1276">of &lt;file&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1278">`cp <source> .` </span>
    - <span class="qowt-font4-CourierNew" id="E1278">copy specified file to current </span><span class="qowt-font4-CourierNew" id="E1281">directory</span>
- <span class="qowt-font4-CourierNew" id="E1283">`cp <source> <dest>` </span>
    - <span class="qowt-font4-CourierNew" id="E1284"> </span><span class="qowt-font4-CourierNew" id="E1285"> </span><span class="qowt-font4-CourierNew" id="E1286">copy file &lt;source&gt; to the destination</span>
- <span class="qowt-font4-CourierNew" id="E1288">`mv <old> <new>` </span>
    - <span class="qowt-font4-CourierNew" id="E1288">rename the file from &lt;old&gt; to &lt;new&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1290">`mv <old> <dest>` </span>
    - <span class="qowt-font4-CourierNew" id="E1291">move the file &lt;old&gt; to the destination</span>
- <span class="qowt-font4-CourierNew" id="E1293">`rm <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1293">remove the specified file</span>
- <span class="qowt-font4-CourierNew" id="E1295">`rm *` </span>
    - <span class="qowt-font4-CourierNew" id="E1295">remove all files in current directory</span>
- <span class="qowt-font4-CourierNew" id="E1297">`head <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1297">display the first 10 lines of &lt;file&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1299">`head -20 <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1299">display the first 20 lines of &lt;file&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1301">`tail <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1301">display the last 10 lines of &lt;file&gt;</span>
- <span class="qowt-font4-CourierNew" id="E1303">`tail -20 <file>` </span>
    - <span class="qowt-font4-CourierNew" id="E1303">display the last 20 lines of &lt;file&gt;</span>

## <span class="qowt-font4-CourierNew" id="E1307">Administration</span>

- <span class="qowt-font4-CourierNew" id="E1309">`man <command>` </span>
    - <span class="qowt-font4-CourierNew" id="E1309">display the manual for &lt;command&gt;</span>
- `<span class="qowt-font4-CourierNew" id="E1311">passwd </span>`
    - <span class="qowt-font4-CourierNew" id="E1311">change your account's password</span>
- <span class="qowt-font4-CourierNew" id="E1313">`chfn` </span>
    - <span class="qowt-font4-CourierNew" id="E1313">change your account's full name</span>
- <span class="qowt-font4-CourierNew" id="E1315">`top` </span>
    - <span class="qowt-font4-CourierNew" id="E1316"> </span><span class="qowt-font4-CourierNew" id="E1317">display all running processes</span>
- <span class="qowt-font4-CourierNew" id="E1319">`kill <pid>` </span>
    - <span class="qowt-font4-CourierNew" id="E1319">kill one of your processes</span>
- <span class="qowt-font4-CourierNew" id="E1321">`ps -u <user>` </span>
    - <span class="qowt-font4-CourierNew" id="E1321">display all running processes </span><span class="qowt-font4-CourierNew" id="E1323">for &lt;user&gt;</span>

## <span class="qowt-font4-CourierNew" id="E1326">Special files</span>

- <span class="qowt-font4-CourierNew" id="E1328">`public_html` </span>
    - <span class="qowt-font4-CourierNew" id="E1329">directory in which all web pages should reside</span>
- <span class="qowt-font4-CourierNew" id="E1331">`.profile` </span>
    - <span class="qowt-font4-CourierNew" id="E1332">account setup file (similar to autoexec.bat)</span>
- <span class="qowt-font4-CourierNew" id="E1334">`.forward` </span>
    - <span class="qowt-font4-CourierNew" id="E1335">used to forward email to another email</span><span class="qowt-font4-CourierNew" id="E1336"> </span><span class="qowt-font4-CourierNew" id="E1337">address</span>

# Assignment #2a

## DateTime

filenames: DateTime.java, DateTime.class

Create the text-based application DateTime.java. This program should instantiate a Date object, then use that object's toString() method to display the current date and time to “Standard Out”. Be sure to upload your platform-independent source code to your mislab account public\_html directory, and be sure to actually test your program on your mislab account.

1\. Use Eclipse or a text editor to create a project named DateTime. (The instructions here assume that you are using Eclipse, but you can certainly type your program using a text editor.)

2\. Within your project, create a class named DateTime. This class file should contain:

\- a class header

\- a main method header

\- a statement to instantiate a Date object

Instantiating a Date object (an instance of the Date class) in Java is exactly like instantiating one in Javascript. Use the “new” operator. Since Java is a strongly typed language, you must define your variable first, such as:

```Java
Date myDate;
myDate=new Date();
```

This defines a variable named myDate, whose data type is Date (it is a Date object). It then uses the “new” operator to instantiate a Date object, and assigns that object to the variable myDate.

\- a statement to call your Date object's toString() method to get a string representation of the Date object (and assign that string to a String variable)

```Java
String dateString;
dateString=myDate.toString();
```

\- a statement to display the string

```Java
System.out.println(dateString);
```

<span class="qowt-font4-CourierNew" id="E1407">4</span><span class="qowt-font4-CourierNew" id="E1408">. You will notice that you have syntax errors – unresolved references – because the Date class is not in a standard </span><span class="qowt-font4-CourierNew" id="E1409">package</span><span class="qowt-font4-CourierNew" id="E1410"> that is automatically available to your program.</span>

<span class="qowt-font4-CourierNew" id="E1413"> Before your class header, import the classes from the java.util package:</span>

```Java
import java.util.*;
```

<span class="qowt-font4-CourierNew" id="E1419">5</span><span class="qowt-font4-CourierNew" id="E1420">. </span><span class="qowt-font4-CourierNew" id="E1421">Run your program. As a side-effect, this will also create your .class file.</span><span class="qowt-font4-CourierNew" id="E1422"> </span><span class="qowt-font4-CourierNew" id="E1423">Hopefull</span><span class="qowt-font4-CourierNew" id="E1424">y it will display the correct date and time</span><span class="qowt-font4-CourierNew" id="E1425"> on the Console</span><span class="qowt-font4-CourierNew" id="E1426">.</span>

<span class="qowt-font4-CourierNew" id="E1429">6</span><span class="qowt-font4-CourierNew" id="E1430">. </span><span class="qowt-font4-CourierNew" id="E1431">U</span><span class="qowt-font4-CourierNew" id="E1432">pload your DateTime.java file from this project</span><span class="qowt-font4-CourierNew" id="E1433"> to your mislab account. </span><span class="qowt-font4-CourierNew" id="E1434">The file will be in the src subdirectory, under your project folder in your designated workspace</span><span class="qowt-font4-CourierNew" id="E1435">.</span><span class="qowt-font4-CourierNew" id="E1436"> In your ftp program, drag just DateTime.java from the left (your computer) to your mislab public\_html directory.</span>

<span class="qowt-font4-CourierNew" id="E1439">7. ssh to mislab, log in, move to your public\_html directory, compile your program, and run your program to make sure it works.</span>

`<span class="qowt-font4-CourierNew" id="E1442"> cd public_html</span>`

`<span class="qowt-font4-CourierNew" id="E1444"> javac DateTime.java</span>`

`<span class="qowt-font4-CourierNew" id="E1446"> java DateTime</span>`

# Assignment #2b

<table class="qowt-stl-TableNormal" id="bkmrk-%C2%A0-throughout-the-se" style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Roboto, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 15px;"><colgroup id="columns"><col></col></colgroup><tbody><tr id="E1460"><td colspan="1" id="E1461" rowspan="1"><span class="qowt-font4-CourierNew" id="E1464">Throughout the semester, be sure to use the filenames that th</span><span class="qowt-font4-CourierNew" id="E1465">e assignments tell you to use. On mislab, s</span><span class="qowt-font4-CourierNew" id="E1466">tore all files in your public\_html directory. Do not create any additional directories. Do everything you can to make the job of grading your work easier!</span>

</td></tr></tbody></table>

## <span class="qowt-font4-CourierNew" id="E1471">Home</span><span class="qowt-font4-CourierNew" id="E1472"> Page</span>

<table class="qowt-stl-TableNormal" id="bkmrk-%C2%A0-you-must-correctl"><colgroup id="columns"><col></col></colgroup><tbody><tr id="E1475"><td colspan="1" id="E1476" rowspan="1"><span class="qowt-font4-CourierNew" id="E1479">You must correctly set up your account on the mislab server, as expla</span><span class="qowt-font4-CourierNew" id="E1480">ined in Assignment #1b</span><span class="qowt-font4-CourierNew" id="E1481">, before you can complete this assignment.</span>

</td></tr></tbody></table>

<span class="qowt-font4-CourierNew" id="E1486"><span class="qowt-font4-CourierNew" id="E1453">filename</span><span class="qowt-font4-CourierNew" id="E1454">: index.</span><span class="qowt-font4-CourierNew" id="E1455">html</span></span>

<span class="qowt-font4-CourierNew" id="E1486">Create a web page that will be used to grade your remaining assignments. This page will provide links to each of your remaining assignm</span><span class="qowt-font4-CourierNew" id="E1487">ents. Be sure to name your file for this assignment</span><span class="qowt-font4-CourierNew" id="E1488"> index.htm</span><span class="qowt-font4-CourierNew" id="E1489">l</span><span class="qowt-font4-CourierNew" id="E1490">. Also</span><span class="qowt-font4-CourierNew" id="E1491">, be sure to store the file</span><span class="qowt-font4-CourierNew" id="E1492"> in your public\_html directory.</span>

<span class="qowt-font4-CourierNew" id="E1495">1</span><span class="qowt-font4-CourierNew" id="E1496">. C</span><span class="qowt-font4-CourierNew" id="E1497">reate your index.html. index</span><span class="qowt-font4-CourierNew" id="E1498">.html should contain several anchor tags, providing a link to each of your assignments for the semester </span><span class="qowt-font4-CourierNew" id="E1499">(provide links for assignments 1-14</span><span class="qowt-font4-CourierNew" id="E1500">). Also provide links for exams </span><span class="qowt-font4-CourierNew" id="E1501">1, </span><span class="qowt-font4-CourierNew" id="E1502">2</span><span class="qowt-font4-CourierNew" id="E1503">,</span><span class="qowt-font4-CourierNew" id="E1504"> </span><span class="qowt-font4-CourierNew" id="E1505">3, and 5</span><span class="qowt-font4-CourierNew" id="E1506">. Finally, create a working email link in your links.html, so a grader can email you easily while looking at your assignments throughout the semester. Your links may be either text-based or image-based.</span>

<span class="qowt-font4-CourierNew" id="E1509">2</span><span class="qowt-font4-CourierNew" id="E1510">.</span><span class="qowt-font4-CourierNew" id="E1511"> Set your link for assignment #1</span><span class="qowt-font4-CourierNew" id="E1512"> to </span><span class="qowt-font4-CourierNew" id="E1513">display </span><span class="qowt-font4-CourierNew" id="E1514">your HelloWorld.java source code file.</span><span class="qowt-font4-CourierNew" id="E1515"> To do this, ssh to your mislab account, move to the public\_html directory, and copy lister.php to your account:</span>

`<span class="qowt-font4-CourierNew" id="E1518"> cd public_html</span>`

`<span class="qowt-font4-CourierNew" id="E1520"> cp /home/bis3523/resources/code/lister.php .</span>`

<span class="qowt-font4-CourierNew" id="E1523"> Don't forget the period at the end, which specifies the "destination" of your cp command – the current directory.</span>

<span class="qowt-font4-CourierNew" id="E1526">Set the href of your anchor tag for assignment #1 to</span>

```Java
href='lister.php?HelloWorld.java'
```

<span class="qowt-font4-CourierNew" id="E1532"> Follow this procedure any time that you need to display the contents of a file rather than having the browser "render" the file.</span>

<span class="qowt-font4-CourierNew" id="E1535">3</span><span class="qowt-font4-CourierNew" id="E1536">.</span><span class="qowt-font4-CourierNew" id="E1537"> Set your link for assignment #2</span><span class="qowt-font4-CourierNew" id="E1538"> to </span><span class="qowt-font4-CourierNew" id="E1539">display </span><span class="qowt-font4-CourierNew" id="E1540">your DateTime.java source code file that you will create later in this assignment.</span>

```Java
href='lister.php?DateTime.java'
```

<span class="qowt-font4-CourierNew" id="E1546">4</span><span class="qowt-font4-CourierNew" id="E1547">. Provide some sort of "Not available </span><span class="qowt-font4-CourierNew" id="E1548">yet" page for your assignments 1-14</span><span class="qowt-font4-CourierNew" id="E1549"> and exams </span><span class="qowt-font4-CourierNew" id="E1550">1, 2, 3</span><span class="qowt-font4-CourierNew" id="E1551">,</span><span class="qowt-font4-CourierNew" id="E1552"> and 5</span><span class="qowt-font4-CourierNew" id="E1553"> so your user doesn't get an error page when following those links.</span>

<span class="qowt-font4-CourierNew" id="E1556">5</span><span class="qowt-font4-CourierNew" id="E1557">. Upload all of your required files to the public\_html directory on your mislab account. Test your page, using Firefox, from the Advanced Languages student page.</span>

<span class="qowt-font4-CourierNew" id="E1560">Be sure to test each of your assignments in the environment in which it will be graded. If your assignment does not work under Firefox, from the Advanced Languages page, it does not work. Period.</span>

<span class="qowt-font4-CourierNew" id="E1564">FOR EVERY ASSIGNMENT: Be sure to go to mislab.business.msstate.edu, to the BIS 3523 page, and to your page. Your Home Page should load automatically.</span>

<table class="qowt-stl-TableNormal" id="bkmrk-%C2%A0-reminder-%C2%A0-don%E2%80"><colgroup id="columns"><col></col></colgroup><tbody><tr id="E1571"><td colspan="1" id="E1572" rowspan="1"><span class="qowt-font4-CourierNew" id="E1575">Reminder</span>

<span class="qowt-font4-CourierNew" id="E1578">Don’t forget that each programming assignment is an individual assignment. These are not group projects. Do your own work. Do not look at anyone else’s code without that person’s explicit permission. YOU should type every single character in your programs.</span>

</td></tr></tbody></table>

# Assignment #3

## <span class="qowt-font4-CourierNew" id="E1595">Text-based Payroll Application</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E1586">Filenames:</span><span class="qowt-font4-CourierNew" id="E1587"> </span><span class="qowt-font4-CourierNew" id="E1588">Payroll.java</span><span class="qowt-font4-CourierNew" id="E1589">, </span><span class="qowt-font4-CourierNew" id="E1590">Employee.java, </span><span class="qowt-font4-CourierNew" id="E1591">Ut</span><span class="qowt-font4-CourierNew" id="E1592">ility.java</span></span>

<span class="qowt-font4-CourierNew" id="E1598">Create a project named Payrol</span><span class="qowt-font4-CourierNew" id="E1599">l. In this project, we will create two classes – Payroll </span><span class="qowt-font4-CourierNew" id="E1600">and Employee</span><span class="qowt-font4-CourierNew" id="E1601"> – and use a third class that you can download from our course web site</span><span class="qowt-font4-CourierNew" id="E1602">. Payroll will contain the logic of our payroll application. The Employee class will</span><span class="qowt-font4-CourierNew" id="E1603"> be a re-usable class that we can use to</span><span class="qowt-font4-CourierNew" id="E1604"> represent an Employee </span><span class="qowt-font4-CourierNew" id="E1605">object</span><span class="qowt-font4-CourierNew" id="E1606">.</span><span class="qowt-font4-CourierNew" id="E1607"> The Utility class contains several </span><span class="qowt-font4-CourierNew" id="E1608">class methods</span><span class="qowt-font4-CourierNew" id="E1609"> that you will end up using throughout the semester.</span>

<span class="qowt-font4-CourierNew" id="E1612">1. </span><span class="qowt-font4-CourierNew" id="E1613">Create your</span><span class="qowt-font4-CourierNew" id="E1614"> Employee class. </span><span class="qowt-font4-CourierNew" id="E1615">Important note: Since this is not the class that represents the main functionality of our application, it will NOT have a </span><span class="qowt-font4-CourierNew" id="E1616">main</span><span class="qowt-font4-CourierNew" id="E1617"> method. Don't check the checkbox for a main method.</span>

<span class="qowt-font4-CourierNew" id="E1620">2. </span><span class="qowt-font4-CourierNew" id="E1621">Y</span><span class="qowt-font4-CourierNew" id="E1622">our E</span><span class="qowt-font4-CourierNew" id="E1623">mployee class needs one instance variable (property)</span><span class="qowt-font4-CourierNew" id="E1624">:</span>

<span class="qowt-font4-CourierNew" id="E1627">public double payRate</span><span class="qowt-font4-CourierNew" id="E1628">;</span>

<span class="qowt-font4-CourierNew" id="E1631">3. </span><span class="qowt-font4-CourierNew" id="E1632">You need a constructor method so your application program can</span><span class="qowt-font4-CourierNew" id="E1633"> </span><span class="qowt-font4-CourierNew" id="E1634">instantiate an Employee object.</span><span class="qowt-font4-CourierNew" id="E1635"> Your constructor should receive </span><span class="qowt-font4-CourierNew" id="E1636">a </span><span class="qowt-font4-CourierNew" id="E1637">double</span><span class="qowt-font4-CourierNew" id="E1638">, which is this</span><span class="qowt-font4-CourierNew" id="E1639"> employee's payrate. The constructor needs to assign that parameter to your instance variable for more persistence.</span><span class="qowt-font4-CourierNew" id="E1640"> (Remember that the name of a constructor method must match the name of its class: Employee. Also, it is not allowed to specify a "return data type", not even "void").</span>

```Java
public Employee(double thisPayRate)
{
		this.payRate=thisPayRate;
}
```

<span class="qowt-font4-CourierNew" id="E1654">4. </span><span class="qowt-font4-CourierNew" id="E1655">You need a method named calculatePay that receives an </span><span class="qowt-font4-CourierNew" id="E1656">int</span><span class="qowt-font4-CourierNew" id="E1657"> </span><span class="qowt-font4-CourierNew" id="E1658">(</span><span class="qowt-font4-CourierNew" id="E1659">hoursWorked) and returns a </span><span class="qowt-font4-CourierNew" id="E1660">double</span><span class="qowt-font4-CourierNew" id="E1661"> (grossPay). This method</span><span class="qowt-font4-CourierNew" id="E1662"> </span><span class="qowt-font4-CourierNew" id="E1663">should calculate the employee's grossPay (hoursWorked times</span><span class="qowt-font4-CourierNew" id="E1664"> </span><span class="qowt-font4-CourierNew" id="E1665">payRate).</span>

```Java
public double calculatePay(int hoursWorked)
{
	double grossPay=hoursWorked * this.payRate;
	return grossPay;
}
```

<span class="qowt-font4-CourierNew" id="E1679">5. Create a class that will contain the main logic of your application. Name this class </span><span class="qowt-font4-CourierNew" id="E1680">Payroll</span><span class="qowt-font4-CourierNew" id="E1681">.</span>

<span class="qowt-font4-CourierNew" id="E1684">6. Initially, </span><span class="qowt-font4-CourierNew" id="E1685">inside your main method defin</span><span class="qowt-font4-CourierNew" id="E1686">e</span><span class="qowt-font4-CourierNew" id="E1687"> a hard-coded hoursWorked</span><span class="qowt-font4-CourierNew" id="E1688"> and payRate</span><span class="qowt-font4-CourierNew" id="E1689">:</span>

```Java
int hoursWorked=40;
double payRate=8.75;
```

<span class="qowt-font4-CourierNew" id="E1697">7. Inside your main method, i</span><span class="qowt-font4-CourierNew" id="E1698">nstantiate an Employee object,</span><span class="qowt-font4-CourierNew" id="E1699"> passing </span><span class="qowt-font4-CourierNew" id="E1700">payRate to the constructor method. T</span><span class="qowt-font4-CourierNew" id="E1701">hen call the calculatePay</span><span class="qowt-font4-CourierNew" id="E1702"> </span><span class="qowt-font4-CourierNew" id="E1703">method of that </span><span class="qowt-font4-CourierNew" id="E1704">Employee </span><span class="qowt-font4-CourierNew" id="E1705">object (it's an instance method)</span><span class="qowt-font4-CourierNew" id="E1706">, passing hoursWorked as your argument,</span><span class="qowt-font4-CourierNew" id="E1707"> to calculate</span><span class="qowt-font4-CourierNew" id="E1708"> </span><span class="qowt-font4-CourierNew" id="E1709">the gross pay. Display the gross pay to the screen.</span>

```Java
Employee employee=new Employee(payRate);
double grossPay=employee.calculatePay(hoursWorked);
System.out.println(grossPay);
```

<span class="qowt-font4-CourierNew" id="E1721">Now, that's a pretty good start, but there are a number of things</span><span class="qowt-font4-CourierNew" id="E1722"> </span><span class="qowt-font4-CourierNew" id="E1723">that you can now do:</span>

<span class="qowt-font4-CourierNew" id="E1726">8</span><span class="qowt-font4-CourierNew" id="E1727">. Modify the program to accept </span><span class="qowt-font4-CourierNew" id="E1728">both </span><span class="qowt-font4-CourierNew" id="E1729">hoursWorked</span><span class="qowt-font4-CourierNew" id="E1730"> and payRate</span><span class="qowt-font4-CourierNew" id="E1731"> from the keyboard. One of our</span><span class="qowt-font4-CourierNew" id="E1732"> early </span><span class="qowt-font4-CourierNew" id="E1733">course packet </span><span class="qowt-font4-CourierNew" id="E1734">DOS-based programs uses a readInt method, something like:</span>

```Java
int hoursWorked=Utility.readInt();
```

<span class="qowt-font4-CourierNew" id="E1740"> Utility.j</span><span class="qowt-font4-CourierNew" id="E1741">ava is on our course web site</span><span class="qowt-font4-CourierNew" id="E1742">.</span><span class="qowt-font4-CourierNew" id="E1743"> Download a copy of Utility.java. Open it in a text editor.</span>

<span class="qowt-font4-CourierNew" id="E1746"> Back in Eclipse, create a new class named Utility. Delete any automatic code that Eclipse puts in that file, and copy/paste the entire Utility.java code from your text editor into this new class in Eclipse.</span>

<span class="qowt-font4-CourierNew" id="E1749">9</span><span class="qowt-font4-CourierNew" id="E1750">. You will</span><span class="qowt-font4-CourierNew" id="E1751">, of course, want to display a prompt before reading the input.</span>

```Java
System.out.println("Hours worked?");
int hoursWorked=Utility.readInt();
```

<span class="qowt-font4-CourierNew" id="E1759">10</span><span class="qowt-font4-CourierNew" id="E1760">. </span><span class="qowt-font4-CourierNew" id="E1761">Use Utility.readDouble to a</span><span class="qowt-font4-CourierNew" id="E1762">ccept the payRate from the keyboard.</span>

<span class="qowt-font4-CourierNew" id="E1766">11</span><span class="qowt-font4-CourierNew" id="E1767">. One of the reasons for defining the Employee class is that it separates the functionality of the Employee object from the functionality of your application program. The person who writes the application program doesn't need to know anything about calculating pay; he or she just needs to call the Employee class's calculatePay method. The person who maintains the Employee class needs to know how to calculate grossPay.</span>

<span class="qowt-font4-CourierNew" id="E1770"> Modify the </span><span class="qowt-font4-CourierNew" id="E1771">Employee class's </span><span class="qowt-font4-CourierNew" id="E1772">calculatePay method to pay time and a half for overtime. That is, if the employee works over 40 hours, pay 1.5 times the payRate for any hours over 40.</span>

<span class="qowt-font4-CourierNew" id="E1775"> Pretend that you are two different people (this will be easy if you actually believe that you ARE two different people). One of your personas is working on the application program, and your other persona (or one of your other personas) maintains the Employee class. You have just demonstrated that the application programmer doesn't need to know the inner workings of calculating gross pay. The application programmer didn't change his (or her, or its) application program; the other programmer changed the Employee class. The application programmer didn't have to recompile his program. As a matter of fact, the application prog</span><span class="qowt-font4-CourierNew" id="E1776">r</span><span class="qowt-font4-CourierNew" id="E1777">ammer may not even know that anything has changed. But his program is working!</span>

<span class="qowt-font4-CourierNew" id="E1780"> This demonstrates </span><span class="qowt-font4-CourierNew" id="E1781">encapsulation</span><span class="qowt-font4-CourierNew" id="E1782">.</span><span class="qowt-font4-CourierNew" id="E1783"> All of the functionality of an Employee object is encapsulated in the Employee class. It also demonstrates the concept of the class's </span><span class="qowt-font4-CourierNew" id="E1784">interface</span><span class="qowt-font4-CourierNew" id="E1785">. All the application programmer needs to know is the interface with the Employee class: if there are any public properties, the application programmer may manipulate those directly. If there are any public methods, what do they receive? and what do they return? The application programmer does not need to know the inner workings of those methods.</span>

<span class="qowt-font4-CourierNew" id="E1789">12</span><span class="qowt-font4-CourierNew" id="E1790">. You could add a flat tax rate as a property of the Employee class.</span>

```Java
private double taxRate=.10;
```

<span class="qowt-font4-CourierNew" id="E1798"> Now, if that is a flat t</span><span class="qowt-font4-CourierNew" id="E1799">axRate, applied to all Employee object</span><span class="qowt-font4-CourierNew" id="E1800">s evenly, does EACH Employee object need its own taxRate, or is there one t</span><span class="qowt-font4-CourierNew" id="E1801">axRate for all Employee objects?</span><span class="qowt-font4-CourierNew" id="E1802"> Although either would work, it seems wasteful to have a separate copy of the value .10 for each Employee object when one copy would do, so you should change that line to:</span>

```Java
private static double taxRate=.10;
```

<span class="qowt-font4-CourierNew" id="E1809">You could write a calculateTax method now. T</span><span class="qowt-font4-CourierNew" id="E1810">his method would receive a double (grossPay) and return a double</span><span class="qowt-font4-CourierNew" id="E1811"> (netPay). When you use taxRate in your calculations, use Employee.taxRate since taxRate is a class variable (non-static properties are called instance variables; static properties are called class variables).</span>

<span class="qowt-font4-CourierNew" id="E1814"> If you want to prevent the value of taxRate from being changed during the program, you can declare taxRate as "final". By convention, final variables are written in all upper case characters, using the underscore character to separate "logical words":</span>

```Java
private static final double TAX_RATE=.10;
```

<span class="qowt-font4-CourierNew" id="E1821">13</span><span class="qowt-font4-CourierNew" id="E1822">. Try to think of some other things that you could add to this example.</span>

<span class="qowt-font4-CourierNew" id="E1825">14</span><span class="qowt-font4-CourierNew" id="E1826">. </span><span class="qowt-font4-CourierNew" id="E1827">U</span><span class="qowt-font4-CourierNew" id="E1828">pload your .java files from this project (including Utility.java)</span><span class="qowt-font4-CourierNew" id="E1829"> to your mislab account.</span>

<span class="qowt-font4-CourierNew" id="E1832"> Your link to your assignment #3</span><span class="qowt-font4-CourierNew" id="E1833"> (in your index.html</span><span class="qowt-font4-CourierNew" id="E1834">) should display your Employee.java file. It's in the src subdirectory of your project. Be sure to test your page from http://mislab.business.msstate.edu to verify that your links work.</span>

<span class="qowt-font4-CourierNew"> </span>

# Assignment #4

## Text-based Trivia Application

Filenames: TextTrivia.java

Write a text-based application which will list today's trivia events to the console. Ask the user for today's month and day (from the keyboard), then read the class's trivia file (two versions available from our course web site). Read the records, and if the month and day from the trivia event match the user's input, display the year and event to the console.

Check for the following data entry errors:

1\. invalid month number (should be 1-12)

2\. invalid day number (minimum day number is 1; if month==1, 3, 5, 7, 8, 10, or 12,   
 maximum day number is 31; if month==4, 6, 9, or 11,   
 maximum day number is 30; if month==2, maximum day number is 29)

Display the appropriate trivia events, plus a count of the number of events listed.

The trivia file:

Two versions of the trivia file are available on our private course web site:

1\. Trivia.dat contains variable-length, delimited fields (using a tab as the delimiter character). When you read a record from this file, you can break it apart using the String class's split() method.

2\. Trivia.fil contains fixed-length fields. You can extract individual fields from this record by using the String class's substring() method.

# Assignment #5

## There is no assignment #5

# Assignment #6

## <span class="qowt-font4-CourierNew" id="E1901">GUI Payroll Application</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E1887">F</span><span class="qowt-font4-CourierNew" id="E1888">ilenames: </span><span class="qowt-font4-CourierNew" id="E1889">GUI</span><span class="qowt-font4-CourierNew" id="E1890">Payroll.java</span><span class="qowt-font4-CourierNew" id="E1891">, </span><span class="qowt-font4-CourierNew" id="E1892">Employee.java</span><span class="qowt-font4-CourierNew" id="E1893">, </span><span class="qowt-font4-CourierNew" id="E1894">Ut</span><span class="qowt-font4-CourierNew" id="E1895">ilit</span><span class="qowt-font4-CourierNew" id="E1896">y.java</span></span>

<span class="qowt-font4-CourierNew" id="E1905">This assignment re-uses the Employee class that you created in the previous assignment. You may also want to use the padString method from Utility.java for formatting some of your output. Hopefully, this assignment will help demonstrate how you can re-use an existing class (such as your Employee class) to build a system.</span>

<span contenteditable="false" id="E1908"></span> <span class="qowt-font4-CourierNew" id="E1910">Write a Java GUI application which performs payroll calculations, similar to your previous assignment. The layout of your application is up to you, but you can feel free to mimic the sc</span><span class="qowt-font4-CourierNew" id="E1911">reen shown here</span><span class="qowt-font4-CourierNew" id="E1912">. The captured screen shown there uses a 5-row, 2-column GridLayout which contains:</span>

<span class="qowt-font4-CourierNew" id="E1914">-</span><span class="qowt-font4-CourierNew" id="E1915"> </span><span class="qowt-font4-CourierNew" id="E1916">three Label objects</span>

<span class="qowt-font4-CourierNew" id="E1918">-</span><span class="qowt-font4-CourierNew" id="E1919"> </span><span class="qowt-font4-CourierNew" id="E1920">three TextField objects</span>

<span class="qowt-font4-CourierNew" id="E1922">-</span><span class="qowt-font4-CourierNew" id="E1923"> </span><span class="qowt-font4-CourierNew" id="E1924">three Button objects</span>

<span class="qowt-font4-CourierNew" id="E1926">-</span><span class="qowt-font4-CourierNew" id="E1927"> </span><span class="qowt-font4-CourierNew" id="E1928">one TextArea object</span>

<span class="qowt-font4-CourierNew" id="E1932">The operation of this application should be fairly obvious. Your user is supposed to enter an employee name, </span><span class="qowt-font4-CourierNew" id="E1933">hours worked, and </span><span class="qowt-font4-CourierNew" id="E1934">a pay rate</span><span class="qowt-font4-CourierNew" id="E1935">. When the user clicks </span><span class="qowt-font4-CourierNew" id="E1936">the Calculate button, your program should instantiate an Employee object, then use methods of the Employee class to calculate the employee's pay. The TextArea should be cleared, and the employee's information should be shown in the TextArea.</span>

<span class="qowt-font4-CourierNew" id="E1939">The Clear button clears all three TextFields, as well as the TextArea.</span>

<span class="qowt-font4-CourierNew" id="E1942">The Quit button terminates the program and closes the window.</span>

<span class="qowt-font4-CourierNew" id="E1947">1. In Eclipse, create a project named GUIPayroll.</span>

<span class="qowt-font4-CourierNew" id="E1950">2. Create a class named GUIPayroll. This class should be a subclass of java.awt.Frame. This class will contain your application program logic.</span>

<span class="qowt-font4-CourierNew" id="E1953">3. The GUIPayroll class should contain a </span><span class="qowt-font4-CourierNew" id="E1954">main</span><span class="qowt-font4-CourierNew" id="E1955"> method.</span>

<span class="qowt-font4-CourierNew" id="E1958">4. The GUIPayroll class should also contain a constructor method.</span>

```Java
public GUIPayroll()
{
}
```

<span class="qowt-font4-CourierNew" id="E1968">5. Your main method should do only one thing: instantiate a GUIPayroll object.</span>

```Java
new GUIPayroll();
```

<span class="qowt-font4-CourierNew" id="E1974">6. The GUIPayroll constructor method should:</span>

<span class="qowt-font4-CourierNew" id="E1976"> - set your frame's title</span>

<span class="qowt-font4-CourierNew" id="E1978"> - set your frame's size</span>

<span class="qowt-font4-CourierNew" id="E1980"> - set up your desired layout manager</span>

<span class="qowt-font4-CourierNew" id="E1982"> - instantiate GUI objects and add them to the layout manager</span>

<span class="qowt-font4-CourierNew" id="E1984"> - register your class as the event listener for your buttons</span>

<span class="qowt-font4-CourierNew" id="E1986"> - make your frame visible</span>

<span class="qowt-font4-CourierNew" id="E1989"> Notes:</span>

<span class="qowt-font4-CourierNew" id="E1991"> - To respond to a button click, you need to:</span>

```Java
import java.awt.event.*;
```

<span class="qowt-font4-CourierNew" id="E1997"> implement</span><span class="qowt-font4-CourierNew" id="E1998">s</span><span class="qowt-font4-CourierNew" id="E1999"> ActionListener</span><span class="qowt-font4-CourierNew" id="E2000"> (in the class header)</span>

<span class="qowt-font4-CourierNew" id="E2003"> override the default actionPerformed method</span>

```qowt-stl-Normal
public void actionPerformed(ActionEvent e)
{
}
```

<span class="qowt-font4-CourierNew" id="E2013"> - Your logic that </span><span class="qowt-font4-CourierNew" id="E2014">actually </span><span class="qowt-font4-CourierNew" id="E2015">responds to button clicks </span><span class="qowt-font4-CourierNew" id="E2016">(your </span><span class="qowt-font4-CourierNew" id="E2017">event responder</span><span class="qowt-font4-CourierNew" id="E2018"> logic) </span><span class="qowt-font4-CourierNew" id="E2019">goes in the actionPerformed method</span>

<span class="qowt-font4-CourierNew" id="E2022"> - To copy Employee.java from a previous project into this one, right-click or control-click on the old Employee.java file, select Copy, then Paste it into your new project.</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E2025">Note: Because telnet is a text-based program, you will not be able to telnet to your mislab account and run your GUI application. For grading, your teacher will download yo</span><span class="qowt-font4-CourierNew" id="E2026">ur files</span><span class="qowt-font4-CourierNew" id="E2027"> to his computer, and run it locally.</span><span class="qowt-font4-CourierNew" id="E2028"> Be sure to upload </span><span class="qowt-font4-CourierNew" id="E2029">all required .java files from your project</span><span class="qowt-font4-CourierNew" id="E2030"> to your mislab account.</span></span>

# Assignment #7

## Improved GUI Payroll Application

Filenames: GUIPayroll.java, Employee.java, Utility.java

Modify your GUIPayroll project to handle invalid user input in the (expected) numeric fields. Use a try/catch block when you try to get a primitive numeric representation of your String values from the TextFields.

If you detect invalid input, change the text color in your TextArea to red.

# Assignment #8a

## Setting up your own tomcat Server on mislab

mislab runs the apache web server software. apache is open-source software, available for free from www.apache.org. Over 60% of the web servers on the internet run the apache web server software.

apache does not support Java servlets by itself. To provide that support, mislab runs the tomcat server software (this is also open-source, free software). For class purposes, each student will run his or her own tomcat server. The following instructions explain how to get your tomcat server up and running.

1\. First, check your grades for this class, and look for your Assigned Tomcat Port Numbers. You will have two assigned port numbers: a primary port number, and a secondary port number. Write these numbers down for later use.

2\. Next, you need to edit one of your system startup files on your mislab account. “Hidden” files are not shown when you get a normal directory listing, such as with the command “ls -l”. To show “all” files, use the command:

`ls -al`

Telnet to your account, and get a listing of all files in your root directory (ls -al). You should see several files whose filenames begin with a period. These are hidden files; they are not normally shown when you get a directory listing (unless you include the “a” switch, of course). You need to edit the file named .profile.

`pico .profile`

Your .profile file contains commands that you want to have executed as part of your login process. For tomcat programming, you need to set the values of four environment variables. You can do this with the export command.

You should see the following four lines in your .profile:

```shell
export JAVA_HOME=/usr/local/jdk
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_BASE=/home/bis3523/abc123/tomcat
export CLASSPATH=.:
/usr/local/tomcat/common/lib/servlet.jar:
/usr/local/jdk/bin/mysql.jar
```

Modify the third of these lines to substitute your netid for abc123. Also make sure that your entire path specification is correct (make sure it is /home/bis3523, for instance).

The commands that you type into your .profile are exactly like commands that you would type at the command line. At the command line, you could not press &lt;Enter&gt; in the middle of a command. Similarly, you cannot split any of these commands across multiple lines.

Be sure to check your .profile for accuracy. Each command must be on a single line.

These environment variables specify (1) the location of mislab’s Java installation, (2) mislab’s tomcat (catalina) installation, (3) your tomcat directory, and (4) locations (directories or files) to be searched for Java classes.

3\. You can create your own aliases for commands in your .profile file. For instance, if you want to type "dir" instead of "ls –l", you can include the following line in your .profile:

```shell
alias dir="ls –l"
```

For your convenience, an alias to start your tomcat server, one to shutdown your tomcat server, and one to show all running tomcat servers have been created in your .profile file.

```shell
alias starttom="/usr/local/tomcat/bin/startup.sh"
alias stoptom="/usr/local/tomcat/bin/shutdown.sh"
alias showtom="ps -f -C java"
```

You will be able to type starttom to start your tomcat server, stoptom to shut it down, and showtom to show all running tomcat servers.

<span class="qowt-font4-CourierNew" id="E2189">4</span><span class="qowt-font4-CourierNew" id="E2190">. Press Control-X to exit pico, saving your file.</span>

<span class="qowt-font4-CourierNew" id="E2193">5</span><span class="qowt-font4-CourierNew" id="E2194">. Log out of your account, then log back in. The lines that you just inserted into your .profile file will be processed when you log back in (and every time you log in in the future).</span>

<span class="qowt-font4-CourierNew" id="E2197">Any time that you edit your .profile, you need to log out, then log back in. The commands in your .profile are processed as part of the login process.</span>

<span class="qowt-font4-CourierNew" id="E2200">6</span><span class="qowt-font4-CourierNew" id="E2201">. Under your root directory, make a subdirectory named tomcat:</span>

`<span class="qowt-font4-CourierNew" id="E2204"> mkdir tomcat</span>`

<span class="qowt-font4-CourierNew" id="E2207">7</span><span class="qowt-font4-CourierNew" id="E2208">. Change to your tomcat subdirectory:</span>

`<span class="qowt-font4-CourierNew" id="E2211"> cd tomcat</span>`

<span class="qowt-font4-CourierNew" id="E2214">8</span><span class="qowt-font4-CourierNew" id="E2215">. Copy a</span><span class="qowt-font4-CourierNew" id="E2216">ll of the tomcat files from mislab's</span><span class="qowt-font4-CourierNew" id="E2217"> tomcat directory to your own tomcat subdirectory:</span>

`<span class="qowt-font4-CourierNew" id="E2220"> cp -R /</span><span class="qowt-font4-CourierNew" id="E2221">usr/local</span><span class="qowt-font4-CourierNew" id="E2222">/tomcat/* .</span>`

<span class="qowt-font4-CourierNew" id="E2225"> (The -R switch indicates that all subdirectories should be copied, recursively. The period at the end specifies that the current directory is the destination to which files are to be copied.)</span>

<span class="qowt-font4-CourierNew" id="E2228">9</span><span class="qowt-font4-CourierNew" id="E2229">. Get a direct</span><span class="qowt-font4-CourierNew" id="E2230">ory listing. You should see several</span><span class="qowt-font4-CourierNew" id="E2231"> subdirectories</span><span class="qowt-font4-CourierNew" id="E2232">, including</span><span class="qowt-font4-CourierNew" id="E2233">: conf, logs, webapps, and work. Change to your conf subdirectory.</span>

`<span class="qowt-font4-CourierNew" id="E2236"> cd conf</span>`

<span class="qowt-font4-CourierNew" id="E2239">10</span><span class="qowt-font4-CourierNew" id="E2240">. The file server.xml is used to configure your tomcat server. You need to edit this file to specify your assigned port numbers.</span>

`<span class="qowt-font4-CourierNew" id="E2243"> pico server.xml</span>`

<span class="qowt-font4-CourierNew" id="E2246"> </span><span class="qowt-font4-CourierNew" id="E2247">(</span><span class="qowt-font4-CourierNew" id="E2248">If you do not want to use pico, you could ftp server.xml down to your local computer, edit the file, then ftp it back to your mislab account.)</span>

<span class="qowt-font4-CourierNew" id="E2251">On line 3, change `port=8085`</span><span class="qowt-font4-CourierNew" id="E2252"> to use your assigned secondary port number. (You can press Control-C to see the current line number</span><span class="qowt-font4-CourierNew" id="E2253"> in pico</span><span class="qowt-font4-CourierNew" id="E2254">.)</span>

<span class="qowt-font4-CourierNew" id="E2256"> On line 15, change `port=8080`</span><span class="qowt-font4-CourierNew" id="E2257"> to use your assigned primary port number.</span>

<span class="qowt-font4-CourierNew" id="E2260">11</span><span class="qowt-font4-CourierNew" id="E2261">. Exit pico, saving your edited file.</span>

<span class="qowt-font4-CourierNew" id="E2264">12</span><span class="qowt-font4-CourierNew" id="E2265">. Start your tomcat server:</span>

`<span class="qowt-font4-CourierNew" id="E2268"> starttom</span>`

<span class="qowt-font4-CourierNew" id="E2271"> You should get a message indicating the directories that your server is using. These should correspond to the environment variables that you set in your .profile.</span>

<span class="qowt-font4-CourierNew" id="E2274">13. Check to see if your tomcat server is running:</span>

`<span class="qowt-font4-CourierNew" id="E2277"> showtom</span>`

```qowt-stl-Normal
conf> showtom
UID PID PPID C STIME TTY TIME CMD
rpearson 24611 1 13 11:00 pts/2 00:00:04 /usr/local/jdk/bin/java -Djava.u


```

<span class="qowt-font4-CourierNew" id="E2280"> You should see something like:</span>

<span class="qowt-font4-CourierNew" id="E2294"> (Note: There could be multiple tomcat servers running, since each student will run his or her own server.)</span>

<span class="qowt-font4-CourierNew" id="E2297">14</span><span class="qowt-font4-CourierNew" id="E2298">. Get into your web browser and try to access your server. Go to the following URL:</span>

<span class="qowt-font4-CourierNew" id="E2301"> http://mis</span><span class="qowt-font4-CourierNew" id="E2302">lab.business</span><span class="qowt-font4-CourierNew" id="E2303">.msstate.edu:</span><span class="qowt-font4-CourierNew" id="E2304">8080</span>

<span class="qowt-font4-CourierNew" id="E2307"> (Replace the </span><span class="qowt-font4-CourierNew" id="E2308">808</span><span class="qowt-font4-CourierNew" id="E2309">0</span><span class="qowt-font4-CourierNew" id="E2310"> with your assigned primary port number.)</span>

<span class="qowt-font4-CourierNew" id="E2313"> This should load the index.jsp file that is stored in your tomcat/webapps/ROOT directory. (You may have to try this more that once, since it takes a few moments for your tomcat server to actually get up and running.</span><span class="qowt-font4-CourierNew" id="E2314"> Its first response to a request may be slow, but subsequent responses will be fast.</span><span class="qowt-font4-CourierNew" id="E2315">)</span>

<span class="qowt-font4-CourierNew" id="E2319">15</span><span class="qowt-font4-CourierNew" id="E2320">. You should have the file c</span><span class="qowt-font4-CourierNew" id="E2321">ounter.jsp in your tomcat/webapps/ROOT subdirectory. The .jsp filename extension indicates to the tomcat server that this is a java server page, meaning that it includes jsp code. Given your knowledge of </span><span class="qowt-font4-CourierNew" id="E2322">Java, you can probably look at c</span><span class="qowt-font4-CourierNew" id="E2323">ounter.jsp and determine to some extent what is going on in the page. When your tomcat server gets a request for this file, it (the server) translates the .jsp file into an actual java servlet. To see this in action, telnet to your account, an</span><span class="qowt-font4-CourierNew" id="E2324">d move to tomcat/work/Catalina</span><span class="qowt-font4-CourierNew" id="E2325">/localhost</span><span class="qowt-font4-CourierNew" id="E2326">/ROOT/org/apach/jsp</span><span class="qowt-font4-CourierNew" id="E2327">. You will proba</span><span class="qowt-font4-CourierNew" id="E2328">bly have two files in that directory: index\_jsp.java and index\_jsp.class</span><span class="qowt-font4-CourierNew" id="E2329">.</span><span class="qowt-font4-CourierNew" id="E2330"> These two files were created when you accessed your index.jsp page.</span>

<span class="qowt-font4-CourierNew" id="E2333">16</span><span class="qowt-font4-CourierNew" id="E2334">. In your browser, go to:</span>

<span class="qowt-font4-CourierNew" id="E2337"> http://mislab.</span><span class="qowt-font4-CourierNew" id="E2338">business</span><span class="qowt-font4-CourierNew" id="E2339">.msstate.edu:</span><span class="qowt-font4-CourierNew" id="E2340">808</span><span class="qowt-font4-CourierNew" id="E2341">0</span><span class="qowt-font4-CourierNew" id="E2342">/c</span><span class="qowt-font4-CourierNew" id="E2343">ounter.jsp</span>

<span class="qowt-font4-CourierNew" id="E2346"> (Replace the </span><span class="qowt-font4-CourierNew" id="E2347">808</span><span class="qowt-font4-CourierNew" id="E2348">0</span><span class="qowt-font4-CourierNew" id="E2349"> with your assigned primary port number.)</span>

<span class="qowt-font4-CourierNew" id="E2352"> You should see a page which displays the current date and time, followed by an access counter.</span>

<span class="qowt-font4-CourierNew" id="E2355">17</span><span class="qowt-font4-CourierNew" id="E2356">. Now go back to your telnet session and get a new directory listing. You will see that your tomcat server translated you</span><span class="qowt-font4-CourierNew" id="E2357">r .jsp file into a .java file (c</span><span class="qowt-font4-CourierNew" id="E2358">ounter\_jsp.java), then compiled that into a .class file. Your .class file generated the page that you see in the browser!</span>

<span class="qowt-font4-CourierNew" id="E2361">18</span><span class="qowt-font4-CourierNew" id="E2362">. The first time you access c</span><span class="qowt-font4-CourierNew" id="E2363">ounter.jsp with your browser, there will be a significant delay, because the .jsp file has to be translated into .java, then the .java file has to be compiled into byte code. On subsequent requests for the page, these steps can be skipped, so the desired page will load much more quickly.</span>

<span class="qowt-font4-CourierNew" id="E2366"> Note that any time that you shut down your server, or any time that you edit the .jsp file, Java code generation and compilation will need to occur again. One noticeable effect of this is that the next request for the page will, once again, be slow. Another noticeable effect is that your counter will be reinitialized. This counter will count correctly, as long as you don’t shut down your tomcat server and don’t edit your .jsp file.</span>

<span class="qowt-font4-CourierNew" id="E2370">19</span><span class="qowt-font4-CourierNew" id="E2371">. If you want to do some quick experimentation, you can put your own .html files in your tomcat/webapps/ROOT directory and access them via your own assigned tomcat primary port number.</span>

<span class="qowt-font4-CourierNew" id="E2374">20</span><span class="qowt-font4-CourierNew" id="E2375">. Now that you know that you can process a .jsp correctly, test a servlet. We want to make sure that you can compile a servlet, and that you can then run it from a web page.</span>

<span class="qowt-font4-CourierNew" id="E2378"> You should have the following two files:</span>

`<span class="qowt-font4-CourierNew" id="E2381"> tomcat/webapps/ROOT/s</span><span class="qowt-font4-CourierNew" id="E2382">nooperServlet.html</span>`

`<span class="qowt-font4-CourierNew" id="E2384"> tomcat/webapps/ROOT/WEB-INF/classes/SnooperServlet.java</span>`

<span class="qowt-font4-CourierNew" id="E2387"> Edit SnoooperServlet.html and change the default port number of </span><span class="qowt-font4-CourierNew" id="E2388">8080</span><span class="qowt-font4-CourierNew" id="E2389"> to </span><span class="qowt-font4-CourierNew" id="E2390">your primary tomcat port number (this is in the href attribute of an anc</span><span class="qowt-font4-CourierNew" id="E2391">hor tag). </span>

<span class="qowt-font4-CourierNew" id="E2394">Also change the </span><span class="qowt-font4-CourierNew" id="E2395">abc123</span><span class="qowt-font4-CourierNew" id="E2396"> that you find in that attribute to your net id.</span>

<span class="qowt-font4-CourierNew" id="E2400"> Move to your "classes directory". If you are currently in your home directory, you can use one, or several, cd commands to move to your classes directory, such as:</span>

`<span class="qowt-font4-CourierNew" id="E2403"> cd tomcat/webapps/ROOT/WEB-INF/classes</span>`

<span class="qowt-font4-CourierNew" id="E2406"> or</span>

`<span class="qowt-font4-CourierNew" id="E2409"> cd tomcat</span>`

`<span class="qowt-font4-CourierNew" id="E2411"> cd webapps</span>`

`<span class="qowt-font4-CourierNew" id="E2413"> cd ROOT</span>`

`<span class="qowt-font4-CourierNew" id="E2415"> cd WEB-INF</span>`

`<span class="qowt-font4-CourierNew" id="E2417"> cd classes</span>`

<span class="qowt-font4-CourierNew" id="E2420">21</span><span class="qowt-font4-CourierNew" id="E2421">. Get a directory listing, to be sure that you really have SnooperServlet.java.</span>

`<span class="qowt-font4-CourierNew" id="E2424"> ls -l</span>`

<span class="qowt-font4-CourierNew" id="E2428">22</span><span class="qowt-font4-CourierNew" id="E2429">. Compile SnooperServlet.java.</span>

`<span class="qowt-font4-CourierNew" id="E2432"> javac SnooperServlet.java</span>`

<span class="qowt-font4-CourierNew" id="E2435"> If you get an error message such as:</span>

`<span class="qowt-font4-CourierNew" id="E2438"> -bash: javac: command not found</span>`

<span class="qowt-font4-CourierNew" id="E2441"> then you have an error in the Path environment variable in your .profile. Since your .profile was pre-configured for you, you should not get this error message. If you have accidentally messed up your path, however, you could get this error. Your .profile should contain the following line:</span>

`<span class="qowt-font4-CourierNew" id="E2444"> PATH=$PATH:$HOME/bin:/usr/sbin:/usr/local/jdk/bin</span>`

<span class="qowt-font4-CourierNew" id="E2447"> Since java is in /usr/local/jdk/bin on mislab, this value should point the operating system to the correct file.</span>

<span class="qowt-font4-CourierNew" id="E2450"> If you get an error message such as:</span>

`<span class="qowt-font4-CourierNew" id="E2453"> SnooperServlet.java:10: package javax.servlet does not exist</span>`

<span class="qowt-font4-CourierNew" id="E2455"> or</span>

`<span class="qowt-font4-CourierNew" id="E2457"> SnooperServlet.java:13: cannot resolve symbol</span>`

<span class="qowt-font4-CourierNew" id="E2460"> then you probably have an error in you</span><span class="qowt-font4-CourierNew" id="E2461">r classpath (also set in your .</span><span class="qowt-font4-CourierNew" id="E2462">profil</span><span class="qowt-font4-CourierNew" id="E2463">e</span><span class="qowt-font4-CourierNew" id="E2464">, but you typed this one).</span>

<span class="qowt-font4-CourierNew" id="E2467">23</span><span class="qowt-font4-CourierNew" id="E2468">. Once you have worked the bugs out of your environment, you will successfully compile SnooperServlet.java. Get a directory listing, and make sure that you have a SnooperServlet.class.</span>

<span class="qowt-font4-CourierNew" id="E2471">24</span><span class="qowt-font4-CourierNew" id="E2472">. In your web browser, go to:</span>

<span class="qowt-font4-CourierNew" id="E2475"> http://mislab.</span><span class="qowt-font4-CourierNew" id="E2476">business</span><span class="qowt-font4-CourierNew" id="E2477">.msstate.edu:</span><span class="qowt-font4-CourierNew" id="E2478">808</span><span class="qowt-font4-CourierNew" id="E2479">0</span><span class="qowt-font4-CourierNew" id="E2480">/s</span><span class="qowt-font4-CourierNew" id="E2481">nooperServlet.html</span>

<span class="qowt-font4-CourierNew" id="E2484"> </span><span class="qowt-font4-CourierNew" id="E2485">C</span><span class="qowt-font4-CourierNew" id="E2486">lick the </span><span class="qowt-font4-CourierNew" id="E2487">anchor link</span><span class="qowt-font4-CourierNew" id="E2488">. If you see a display of a lot of information, formatted in a table, you are doing great!</span>

<span class="qowt-font4-CourierNew" id="E2491">25</span><span class="qowt-font4-CourierNew" id="E2492">. When you are finished, you can shut down your tomcat server, or you can leave it running to wait for requests.</span>

`<span class="qowt-font4-CourierNew" id="E2495"> stoptom</span>`

# Assignment #8b

## <span class="qowt-font4-CourierNew" id="E2513">DataEntry</span><span class="qowt-font4-CourierNew" id="E2514"> servlet</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E2504">Filenames:</span><span class="qowt-font4-CourierNew" id="E2505"> D</span><span class="qowt-font4-CourierNew" id="E2506">ataEntry</span><span class="qowt-font4-CourierNew" id="E2507">.html</span><span class="qowt-font4-CourierNew" id="E2508">, DataEntry</span><span class="qowt-font4-CourierNew" id="E2509">.java</span>  
</span>

<span class="qowt-font4-CourierNew" id="E2518">Create an HTML form that requests data from the user. Submit that form data to a servlet. For output, display the user’s submitted data back to the user. For extra experience, also save the data in a server-based text file.</span>

<span class="qowt-font4-CourierNew" id="E2521">1. Create your HTML data entry form, and store it in your tomcat/webapps/ROOT directory. You can access it at:</span>

<span class="qowt-font4-CourierNew" id="E2524"> http://misla</span><span class="qowt-font4-CourierNew" id="E2525">b.business.msstate.edu:</span><span class="qowt-font4-CourierNew" id="E2526">808</span><span class="qowt-font4-CourierNew" id="E2527">0</span><span class="qowt-font4-CourierNew" id="E2528">/D</span><span class="qowt-font4-CourierNew" id="E2529">ataEntry.html</span>

<span class="qowt-font4-CourierNew" id="E2532"> (Of course, substitute your primary port number.)</span>

<span class="qowt-font4-CourierNew" id="E2535">2. Your form tag should refer to your servlet in its </span><span class="qowt-font4-CourierNew" id="E2536">action</span><span class="qowt-font4-CourierNew" id="E2537"> attribute:</span>

`<span class="qowt-font4-CourierNew" id="E2540"> /servlet/</span><span class="qowt-font4-CourierNew" id="E2541">abc123</span><span class="qowt-font4-CourierNew" id="E2542">.DataEntry</span>`

<span class="qowt-font4-CourierNew" id="E2545">3</span><span class="qowt-font4-CourierNew" id="E2546">. In Eclipse, create a new Java project. </span><span class="qowt-font4-CourierNew" id="E2547">Name it Servlets</span><span class="qowt-font4-CourierNew" id="E2548">.</span><span class="qowt-font4-CourierNew" id="E2549"> You will not actually run your servlets in Eclipse, so we suggest that you simply use this one project for the rest of your Java programming assignments. Just create new classes as you need them, and keep them all in this project. You will upload them as needed from the project into your mislab account.</span>

<span class="qowt-font4-CourierNew" id="E2552">4</span><span class="qowt-font4-CourierNew" id="E2553">. This project needs some non-standard classes that are not automatically included in an Eclipse project.</span><span class="qowt-font4-CourierNew" id="E2554"> Download the file servlet.jar from our course web site. This is a </span><span class="qowt-font4-CourierNew" id="E2555">java archive</span><span class="qowt-font4-CourierNew" id="E2556"> file that contains several servlet-related classes.</span>

<span class="qowt-font4-CourierNew" id="E2562">5</span><span class="qowt-font4-CourierNew" id="E2563">. In Eclipse, right-click (or control-click) on your project name, then select Properties. This will open the Properties Window.</span>

<span class="qowt-font4-CourierNew" id="E2566">6</span><span class="qowt-font4-CourierNew" id="E2567">. In the Properties Window, select Java Build Path along the left, then click the Libraries tab.</span>

<span class="qowt-font4-CourierNew" id="E2570">7</span><span class="qowt-font4-CourierNew" id="E2571">. Click the "Add External JARs" button, and add servlet.jar to your project.</span>

<span contenteditable="false" id="E2574"></span><span class="qowt-font4-CourierNew" id="E2576">8</span><span class="qowt-font4-CourierNew" id="E2577">. Create a class named DataEntry.</span>

<span class="qowt-font4-CourierNew" id="E2580"> This class</span><span class="qowt-font4-CourierNew" id="E2581"> should be a subclass of HTTP</span><span class="qowt-font4-CourierNew" id="E2582">Servlet, not of java.lang.Object.</span>

<span class="qowt-font4-CourierNew" id="E2585">Click the Browse button. In the pop-up window, start typing the word </span><span class="qowt-font4-CourierNew" id="E2586">httpser</span><span class="qowt-font4-CourierNew" id="E2587">. When you see the HTTP</span><span class="qowt-font4-CourierNew" id="E2588">Servlet class listed, select it as your superclass.</span>

<span class="qowt-font4-CourierNew" id="E2591">9</span><span class="qowt-font4-CourierNew" id="E2592">. Eclip</span><span class="qowt-font4-CourierNew" id="E2593">se will generate an import statement</span><span class="qowt-font4-CourierNew" id="E2594">:</span>

`<span class="qowt-font4-CourierNew" id="E2597"> import javax.servlet.http.HttpServlet;</span>`

<span class="qowt-font4-CourierNew" id="E2600"> We recommend changing this to:</span>

`<span class="qowt-font4-CourierNew" id="E2603"> import javax.servlet.http.*;</span>`

<span class="qowt-font4-CourierNew" id="E2606">10</span><span class="qowt-font4-CourierNew" id="E2607">. Add another import, for I/O exception handling:</span>

`<span class="qowt-font4-CourierNew" id="E2610"> import java.io.*;</span>`

<span class="qowt-font4-CourierNew" id="E2612">11</span><span class="qowt-font4-CourierNew" id="E2613">. Write a method that will be called automatically to respond to an </span><span class="qowt-font4-CourierNew" id="E2614">HTTP get</span><span class="qowt-font4-CourierNew" id="E2615"> request:</span>

```qowt-stl-Normal
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
}
```

<span class="qowt-font4-CourierNew" id="E2627">12</span><span class="qowt-font4-CourierNew" id="E2628">. Your servlet needs to send back a "doctype" indicator before it sends any other output. You can do this with your </span><span class="qowt-font4-CourierNew" id="E2629">response</span><span class="qowt-font4-CourierNew" id="E2630"> parameter, which has a setContentType() method.</span>

<span class="qowt-font4-CourierNew" id="E2633"> response.setContentType("text/html");</span>

<span class="qowt-font4-CourierNew" id="E2636">13</span><span class="qowt-font4-CourierNew" id="E2637">. You can use your </span><span class="qowt-font4-CourierNew" id="E2638">response</span><span class="qowt-font4-CourierNew" id="E2639"> parameter's getWriter() method to get a PrintWriter object, which you can use to send text back to the browser.</span>

```qowt-stl-Normal
PrintWriter out=response.getWriter();
out.println("This is a test.");
```

<span class="qowt-font4-CourierNew" id="E2649">14</span><span class="qowt-font4-CourierNew" id="E2650">. Save your work in Eclipse, then upload your DataEntry.java file to tomcat/webapps/ROOT/WEB-INF/classes.</span>

<span class="qowt-font4-CourierNew" id="E2653">15</span><span class="qowt-font4-CourierNew" id="E2654">. Telnet to your account and move to your classes directory. You need to compile your Java code on mislab, because tomcat does not yet support Java 1.8 byte code. mislab has Java compilers for Java 1.4, 1.5, 1.6, 1.7, and 1.8. In your classes directory, type:</span>

`<span class="qowt-font4-CourierNew" id="E2657"> javac DataEntry.java</span>`

<span class="qowt-font4-CourierNew" id="E2661">16</span><span class="qowt-font4-CourierNew" id="E2662">. </span><span class="qowt-font4-CourierNew" id="E2663">M</span><span class="qowt-font4-CourierNew" id="E2664">ove to your tomcat/webapps/ROOT/WEB-INF directory. </span>

<span class="qowt-font4-CourierNew" id="E2667">For security purposes, your tomcat server will not serve any servlet that is not listed in your web.xml file.</span>

<span class="qowt-font4-CourierNew" id="E2670">Use pico to edit web.xml. You will see entries in the file for HelloWorldExample and SnooperServlet. You need to put an entry in for your DataEntry servlet.</span>

```Java
<servlet>
      <servlet-name>DataEntry</servlet-name>
      <servlet-class>DataEntry</servlet-class>
</servlet>
<servlet-mapping>
      <servlet-name>DataEntry</servlet-name>
      <url-pattern>*.DataEntry</url-pattern>
</servlet-mapping>
```

<span class="qowt-font4-CourierNew" id="E2698"> Copy/paste in pico is a bit tricky, but here's how you do it. Move to the first &lt;servlet&gt; container for SnooperServlet. Press Shift-Control-6. At the bottom of the screen, you will see "\[ Mark Set \]".</span>

<span class="qowt-font4-CourierNew" id="E2701"> Arrow-down to highlight the lines you want to copy.</span>

<span class="qowt-font4-CourierNew" id="E2704"> Press Control-k.</span>

<span class="qowt-font4-CourierNew" id="E2707"> This will cut the highlight block, so immediately press Control-u to paste it right back where it was. Now you can Control-u again to paste it again, and have a copy that you can edit. Change every SnooperServlet to DataEntry.</span>

<span class="qowt-font4-CourierNew" id="E2710"> VERY IMPORTANT: Any mistake in this file will prevent your tomcat server from working. If you make any mistake in this file, you will probably get a blank screen response from your tomcat server when you try to access any page.</span>

<span class="qowt-font4-CourierNew" id="E2713">17</span><span class="qowt-font4-CourierNew" id="E2714">. You will need to stop your tomcat server and start it again, so it will process your web.xml file.</span>

`<span class="qowt-font4-CourierNew" id="E2717"> stoptom</span>`

`<span class="qowt-font4-CourierNew" id="E2719"> starttom</span>`

<span class="qowt-font4-CourierNew">18. Modify your servlet to retrieve the submitted form data fro</span><span class="qowt-font4-CourierNew">m your HTML form. If you have a form field named lastName, for instance, you can retrieve the form data with:</span>

```Java
String lastName=request.getParameter("lastName");
```

<span class="qowt-font4-CourierNew" id="E2731"> Echo information back to the browser to verify that you can indeed retrieve the submitted form data.</span>

<span class="qowt-font4-CourierNew" id="E2734"> Remember that any time you edit your .java servlet, you must:</span>

<span class="qowt-font4-CourierNew" id="E2736"> - save your work in Eclipse (to generate a new .java file)</span>

<span class="qowt-font4-CourierNew" id="E2738"> - upload the .java file from your workspace to your classes folder</span>

<span class="qowt-font4-CourierNew" id="E2740"> - switch over to your mislab account (telnet) and compile the .java file</span>

<span class="qowt-font4-CourierNew" id="E2742"> - stop your tomcat server</span>

<span class="qowt-font4-CourierNew" id="E2744"> - start your tomcat server</span>

<span class="qowt-font4-CourierNew" id="E2747">19. If you can get one more step done, you will be in really good shape. Write the submitted data into a server-based file (the file will be in your classes folder).</span>

```Java
try
{
  FileWriter file=new FileWriter("DataEntry.txt",true);
  file.write(lastName+"\t"+firstName+"\n");
  file.close();
}
catch(Exception e)
{
}
```

<span class="qowt-font4-CourierNew" id="E2774">20. In your index.html, change the href in t</span><span class="qowt-font4-CourierNew" id="E2775">he anchor tag for this assignment</span><span class="qowt-font4-CourierNew" id="E2776"> to request DataEntry.html. Unlike previous assignments, you will not display your Java source code now, because you now have a working web-based assignment. We want the </span><span class="qowt-font4-CourierNew" id="E2777">DataEntry assignment to </span><span class="qowt-font4-CourierNew" id="E2778">work</span><span class="qowt-font4-CourierNew" id="E2779">, not simply display source code.</span>

# Assignment #9

## Java Source Code Lister

Filenames: ListFiles.java, ListSource.java

Write a servlet which will display a directory listing of all of the .java files in your classes folder (on mislab). When the user clicks one of the listed file names, display the contents of that .java file.

1\. In Eclipse, you can use your Servlets project, and simply create two new classes in that project. You have already added servlet.jar to that project, so this will save you a step.

2\. Create a new class named ListFiles. It should be a subclass of HttpServlet.

3\. You will need two import statement. You need to import

`javax.servlet.http.*`

`java.io.*`

4\. You will need to write a `doGet()` method.

5\. Your` doGet()` method should set the contentType of your response to text/html.

6\. Since you will want to generate some output to the browser, you need to call your response object's `getWriter()` method:

`PrintWriter out=response.getWriter();`

7\. You can instantiate a File object to get a listing of the files in the current directory. Once you get that File object, you can call its listFiles() method to get an array of file names.

`File dir=new File(".");`

`File[] filesList=dir.listFiles();`

"." indicates "the current directory".

<span class="qowt-font4-CourierNew" id="E2833">8. Now use a for loop to step through the elements of the filesList array. Process each element in the array (each element is a File object).</span>

<span class="qowt-font4-CourierNew" id="E2836"> You can determine whether a File object is a file or a directory by calling its `isFile()` method.</span>

<span class="qowt-font4-CourierNew" id="E2839"> You can get a File object's filename by calling its `getName()` method.</span>

<span class="qowt-font4-CourierNew" id="E2842"> Once you have a filename (a String object), you can use its matches() method to see if the filename ends with .java.</span>

`<span class="qowt-font4-CourierNew" id="E2845"> if(filename.matches(".*\\.java"))</span>`

<span class="qowt-font4-CourierNew" id="E2848"> If the filename ends in .java, generate a line of HTML that includes an anchor tag. Clicking on the anchor tag should submit a request for your ListSource servlet, passing it the current filename. You want to generate something like:</span>

`<span class="qowt-font4-CourierNew" id="E2851"> <a href='</span><span class="qowt-font4-CourierNew" id="E2852">abc123</span><span class="qowt-font4-CourierNew" id="E2853">.ListSource?name=Test.java'>Test</a></span>`

<span class="qowt-font4-CourierNew" id="E2856">9. Update web.xml, in your WEB-INF folder, to provide support for both ListFiles and ListSource.</span>

<span class="qowt-font4-CourierNew" id="E2862">10. When you get this servlet running, it will display a list of the .java files in your classes folder, displaying them as anchor tags.</span>

<span class="qowt-font4-CourierNew" id="E2872">11. Now write `ListSource.java`. It should also be a subclass of `HttpServlet`.</span>

<span class="qowt-font4-CourierNew" id="E2875">12. `ListSource` should set the `contentType` of your response to text/plain (not text/html, because you don't want the browser to try to render this Java source code).</span>

<span class="qowt-font4-CourierNew" id="E2878">13. </span><span class="qowt-font4-CourierNew" id="E2879">R</span><span class="qowt-font4-CourierNew" id="E2880">etrieve the submitted file name</span><span class="qowt-font4-CourierNew" id="E2881">.</span>

<span class="qowt-font4-CourierNew" id="E2884">14.</span><span class="qowt-font4-CourierNew" id="E2885"> </span><span class="qowt-font4-CourierNew" id="E2886">I</span><span class="qowt-font4-CourierNew" id="E2887">nstantiate a FileReader obje</span><span class="qowt-font4-CourierNew" id="E2888">ct, then a BufferedReader object</span><span class="qowt-font4-CourierNew" id="E2889">.</span>

<span class="qowt-font4-CourierNew" id="E2892">15. Loop, reading a record from the .java file, and displaying it to the browser</span><span class="qowt-font4-CourierNew" id="E2893"> (as plain text)</span><span class="qowt-font4-CourierNew" id="E2894">.</span>

<span class="qowt-font4-CourierNew" id="E2897">16. In your `index.html`, change the href in the anchor tag for this assignment to request your ListFiles servlet.</span>

# Assignment #10

## <span class="qowt-font4-CourierNew" id="E2914">Trivia Serv</span><span class="qowt-font4-CourierNew" id="E2915">let</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E2905">Filenames:</span><span class="qowt-font4-CourierNew" id="E2906"> T</span><span class="qowt-font4-CourierNew" id="E2907">rivia</span><span class="qowt-font4-CourierNew" id="E2908">.html</span><span class="qowt-font4-CourierNew" id="E2909">, Trivia</span><span class="qowt-font4-CourierNew" id="E2910">.java</span></span>

<span class="qowt-font4-CourierNew" id="E2919">In this a</span><span class="qowt-font4-CourierNew" id="E2920">ssignment, you will write a serv</span><span class="qowt-font4-CourierNew" id="E2921">let that reads records from a server-based trivia text file, and displays selected trivia events on the user’s browser.</span>

<span class="qowt-font4-CourierNew" id="E2924">1. Create an HTML page that provides two radio buttons – the user can get trivia events for:</span>

<span class="qowt-font4-CourierNew" id="E2926"> - the current date, or</span>

<span class="qowt-font4-CourierNew" id="E2928"> - a specified month and day.</span>

<span class="qowt-font4-CourierNew" id="E2931"> Use your HTML experience to provide a good user interface for this.</span>

<span class="qowt-font4-CourierNew" id="E2934">2. Write a servlet that will:</span>

<span class="qowt-font4-CourierNew" id="E2936"> - retrieve the radio button option</span>

<span class="qowt-font4-CourierNew" id="E2938"> - if the user selected "current date", get the current month and day</span>

<span class="qowt-font4-CourierNew" id="E2940"> - if the user specified a month and day, retrieve those from the form</span>

<span class="qowt-font4-CourierNew" id="E2943">3. Getting the current date in Java.</span>

<span class="qowt-font4-CourierNew" id="E2946">You can use the GregorianCalendar class to get the current date and time. GregorianCalendar inherits some useful methods and constants from its direct superclass, Calendar. GregorianCalendar inherits a general-purpose accessor method named get, which receives a primitive int. It also inherits several constants that you can pass to specify what you want to “get”. To get the current day of the month, for instance, you can:</span>

<span class="qowt-font4-CourierNew" id="E2949">GregorianCalendar calendar=new GregorianCalendar();</span>

<span class="qowt-font4-CourierNew" id="E2951">int day=calendar.get(Calendar.DAY\_OF\_MONTH);</span>

<span class="qowt-font4-CourierNew" id="E2958"> Make sure that you can get a numeric month and a numeric day for both options before you even think about reading the trivia file.</span>

<span class="qowt-font4-CourierNew" id="E2961">4. </span><span class="qowt-font4-CourierNew" id="E2962">Y</span><span class="qowt-font4-CourierNew" id="E2963">ou can </span><span class="qowt-font4-CourierNew" id="E2964">copy T</span><span class="qowt-font4-CourierNew" id="E2965">rivia.fil into your classes</span><span class="qowt-font4-CourierNew" id="E2966"> directory:</span>

`<span class="qowt-font4-CourierNew" id="E2969">cp</span><span class="qowt-font4-CourierNew" id="E2970"> /home/bis</span><span class="qowt-font4-CourierNew" id="E2971">3523</span><span class="qowt-font4-CourierNew" id="E2972">/resources/data/T</span><span class="qowt-font4-CourierNew" id="E2973">rivia.fil .</span>`

<span class="qowt-font4-CourierNew" id="E2976">Be sure to include the period at the end, which specifies the destination for the cp command.</span>

<span class="qowt-font4-CourierNew" id="E2979">5. Read the records from the trivia file, and display the events for the selected date. Generate good HTML.</span>

<span class="qowt-font4-CourierNew" id="E2982">6. In your index.html, change the href in the anchor tag for this assignment to Trivia.html.</span>

# Assignment #11

## <span class="qowt-font4-CourierNew" id="E2994">Servlet</span><span class="qowt-font4-CourierNew" id="E2995">-based</span><span class="qowt-font4-CourierNew" id="E2996"> Survey System</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E2988">Filenames:</span><span class="qowt-font4-CourierNew" id="E2989"> S</span><span class="qowt-font4-CourierNew" id="E2990">urvey.html, Survey.java</span></span>

<span class="qowt-font4-CourierNew" id="E3000">Create an HTML data entry form for some sort of data collection/survey system. Your survey should contain at least one set of radio buttons, so you can generate some counts and statistics (it's easy to count how many 1s, 2, and 3s people select from radio buttons; it's much more difficult to summarize free-form text).</span>

<span class="qowt-font4-CourierNew" id="E3003">Write a servlet that retrieves the submitted form data, saves it into a server-based text file, and displays up-to-date survey results (counts, percentages, means, whatever makes sense for your survey).</span>

<span class="qowt-font4-CourierNew" id="E3006">In your index.html, change the href in the anchor tag for this assignment to Survey.html.</span>

# Assignment #12

## There is no assignment #12

# Assignment #13

## JDBC Database Trivia

Filenames: DatabaseTrivia.html, DatabaseTrivia.java

Modify your earlier Trivia assignment to retrieve trivia events from mislab's Trivia mysql table.

# Assignment #xx (not this one)

## States Database Query System

Filenames: States.html, States.java

Create an HTML form that the user can use to perform queries on the mislab States mysql table. You should provide the following options:

1\. Sort order: List states alphabetically (by state name), by population, by area, or by population density. In all cases, provide options to list in either ascending or descending order.

2\. Selection options: Provide a textfield for each of the four fields: state name, population, area, and population density. If the user enters any letters into the state name textfield, list states that begin with that string (if the user enters Mi, the list all states that begin with Mi; this search should be case-insensitive). If the user enters a number into any of the other three textfields, list all states that match that value or greater (treat the number as a minimum value).

3\. Display your output in a well-formatted table.

# Assignment #14

## <span class="qowt-font4-CourierNew" id="E3089">AJAX Customer/Database</span><span class="qowt-font4-CourierNew" id="E3090"> Query System</span>

<span class="qowt-font4-CourierNew"><span class="qowt-font4-CourierNew" id="E3082">Filenames: </span><span class="qowt-font4-CourierNew" id="E3083">CustomerList</span><span class="qowt-font4-CourierNew" id="E3084">.java</span><span class="qowt-font4-CourierNew" id="E3085">, CustomerQuery.java</span></span>

<span class="qowt-font4-CourierNew" id="E3094">Write a servlet that lists all customers in the mislab mysql customer table. Your list should include only customer number and customer name, listed in a well-formatted table. Provide at least one additional cell to the right of the customer name in your table – you will display detail information for that customer via AJAX.</span>

<span class="qowt-font4-CourierNew" id="E3097">Respond to clicking on a table row by submitting an AJAX request for that customer's information (submit a request for your CustomerQuery servlet). Display all information about that customer in the cell to the right of the customer name in your table.</span>

<span class="qowt-font4-CourierNew" id="E3100">In your index.html, change the href in the anchor tag for this assignment to request your CustomerList servlet.</span>