To-do List
- Prepare for Final Exam. Exam 1 and 2 solutions have been posted below.
- No more homework or project for this class. During the last week of classes
we will review the entire shopping cart project.
Lecture Presentations
- OOIntro.ppt (introduction to OO programming) [154KB]
- Review1ap-ap.ppt (First application-applet) [406KB]
(files related to this lecture:
Hello.java,
HelloFromVenus.java,
HelloFromVenus.html,
Venus.gif)
- Review2simple.ppt (simple Java programming) [221KB]
(files related to this lecture:
Calculate.java,
Triangle2.java)
- Review3files.ppt (io, strings, vectors, files) [261KB]
(files related to this lecture:
CleanHTML1.java,
CleanHTML2.java,
CleanHTML3.java,
0.html)
- ObjectBased.ppt (classes, constructors, set/get) [225KB]
(files related to this lecture:
Time1.java,
TimeTest1.java,
TimeTest2.java)
- ObjectOriented.ppt (inheritance, polymorphism) [244KB]
- GUI1.ppt (graphical user interfaces 1) [506KB]
(files related to this lecture:
ButtonTest.java,
LabelTest.java,
bug1.gif,
RadioButtonTest.java,
ListTest.java,
BorderLayoutDemo.java,
PanelDemo.java)
- GUI2.ppt (graphical user interfaces 2) [190KB]
(files related to this lecture:
DrawShapes.java,
DrawShapes.html,
LookAndFeelDemo.java)
- ProjectIntro.ppt (Introduction to project, databases) [860KB]
(files related to this lecture:
MIS120_Project2.mdb)
- SQL_JDBC.ppt (SQL and JDBC intro) [602KB]
- HTML_JavaScript.ppt (HTML and JavaScript) [650KB]
(files related to this lecture:
FileForm.html,
SurveyForm.html,
SimpleJSForm.html)
- FrontPage_asp.ppt
(FrontPage and online surveys with asp) [794KB]
(Web site related to this lecture:
Online Survey)
- JSP.ppt
(Tomacat and JavaServer Pages -- updated) [575KB]
(Files related to this lecture, running on the Nick's server:
welcome.jsp,
welcome2.jsp,
BookList1.jsp )
Exams
Project
- Project, Part 1 (P1): Create the classes CartItem and ShoppingCartBean.
Deliverables: CartItem.java, ShoppingCartBean.java, one class diagram,
test case descriptions. This is a group assignment.
Description:
Create a class called CartItem, belonging to package "scart" (this means that you should also
create a directory called "scart" and place your java files in there).
Make sure you include the following Java Bean properties: String: itemID, itemTitle, authorOrArtist,
bookOrCD. Integer: quantity. Double: price. Also write set and get methods for all your properties.
For testing purposes, include a main method which instantiates the class, sets example values,
and verifies those values using get methods and println. After you are satisfied with your
implementation, remember to comment out your main method.
Also create a class called ShoppingCartBean,
which holds lists of books and CDs, implemented as vectors of CartItems. It should provide all the
necessary methods to add, remove, set quantities, as well as all the necessary get methods.
For testing purposes, create a Java application called ShoppingCartBeanTest.java which should
instantiate a few cart items, then set their attribute values, then instantiate a shopping cart,
add a few cart items into the shopping cart, and finally verify that everything is in the shopping
cart, in the correct quantities, with the correct total price, using println. Rember that the println
method can print on your screen all the contents of a vector, when you do a println(myVector). Do
not submit this testing application with your deliverables, because the instructor will use his
own testing application. As part of your report, you are asked to provide
the test cases you created, and explain how you veryfied that your classes are implemented correctly,
i.e., explain what you expected to see in the test printout and whether you got it.
In your report provide a class diagram for these two classes (CartItem and ShoppingCartBean),
showing the relationship between the two. Attach all your code and the program output at the end.
Help: Use the code in CartItem2.java and
ShoppingCartBean0.java to see the class structure for
the two classes. These programs include the correct constructors and all the necessary methods
(note that the earlier version CartItem1.java did not include the private variables).
None of the methods is implemented, which is what you have to do. Additional help is provided
in removeCD.txt and
setBookQty.txt, which show the implementations for these two
selected methods. Finally, addItem.txt does not give you
the complete implementation for the method addItem, but it gives you some useful guidelines.
Some helpful java hints: (i) Since BookList is a vector of CartItems, the expression
CartItem temp = (CartItem)BookList.elementAt(index)
will typecast the "object" contained in BookList at
position "index", to a "CartItem" type. When you want to change the properties of a cart item, you
may first retrieve it as shown above, then change its properties usinr the get and set methods of
the CartItem class, and finally put it back in the vector by BookList.setElementAt(temp, index),
assuming that "temp" is a CartItem, and "index" is an integer.
- Project, Part 2 (P2): SQL queries and JDBC test.
Deliverables: An introduction explaining how you achived JDBC in your own words,
Seven SQL statements (in text format), Results of the execution of the queries in text format (two results
where different alternative outputs are possible),
JDBCTest.java code attached. This is a group assignment.
Description:
An Access database called MIS120_Project2.mdb will be provided to you. Write a class called JDBCTest.java
that establishes a connection to this database and executes queries to the database.
Write SQL queries to perform the following:
- Display all books with non-zero inventory
- Display all CDs with non-zero inventory
- Display a particular book’s or CD’s inventory quantity
- Display a credit card if its parameters are equal to the given values
- Insert records into CUSTOMER, ORDER_HEADER, and ORDER_DETAIL.
- Display the next available order number and customer number
- Reduce inventory quantity by the order quantity for a given item.
Help: Use the code in JDBCTest.java
to make static DB connections using Java. You will first have to register your database with the
Access ODBC driver, as a User DSN called "120db". Alternatively, you can use the class in
DBConnection.java which establishes a
dynamic DB connection that does not require the creation of a DSN at all, and write your own
test code which will provide a main method that instantiates DBConnections. Note that, if you
are using DBConnection.java, you will also need to create a text file called db.properties and
place it in your "Apache Tomcat 4.0" directory.
- Project, Part 3 (P3): Static HTML Pages.
Deliverables: BookList.html, CDList.html, screenshots,
HTML code attached. This is a group assignment.
Description:
Build two static HTML pages as shown in FrontPage_asp.ppt. Each file should
display one book or one CD, using images from a locally stored /images directory.
You may start coding manually or using FrontPage, but at the end you should remove
all redundant tags and provide clean HTML code. The result should look nice
when viewed with a browser. Use the provided images.
Images:
add-to-cart.gif,
Books.gif,
BooksSelected.gif,
CDs.gif,
CDsSelected.gif,
OnlineStore.gif,
Strip.gif.
- Project, Part 4 (P4): Dynamic HTML Pages.
Deliverables: BookList.jsp, CDList.jsp, screenshots,
JSP code attached, JSP code e-mailed also. This is a group assignment.
Description: Modify your HTML code from the previous assignment to make it jsp.
Your program should use the DBConnection class distributed in assignment 2 and display all books
and CDs from ITEM table in the provided Access database MIS120_Project2.mdb.
Help: Use the step-by-step instructions in MIS120p4.doc.
Use the code in CartItem1.java,
ShoppingCartBean1.java,
DBConnection2.java(updated),
BookList2.jsp(updated), and
Shopping_Cart2.jsp(updated), to build a working shopping cart example,
following the instructions in JSP.ppt. These programs make the following assumptions:
(i) You have created an /images directory inside your Appache Tomacat 4.0/webapps/examples/jsp, and you have
all the related images in there, (ii) you have created a c:/javap4 directory and you have saved in there
the database file MIS120_Project2.mdb and the properties
file db.properties.
- Project, Parts 5,6:
The final version of the Project is running on the
Instructor's
Server.
The code consists of the Java files:
CartItem.java,
ShoppingCartBean.java, and
DBConnection.java,
and the jsp files:
BookList.jsp,
CDList.jsp,
Shopping_Cart.jsp,
Confirmation.jsp, and
Payment.jsp.
Project Workshop
The instructions below are for a special Project Workshop where you
will create your own server and install the jsp shopping cart application
discussed in the MIS 120 class.
- This workshop assumes that you are working on computer that has Java
(JDK/SDK) and Apache Tomcat 4 already installed. You may download
a copy of the Tomcat installation executable from the following link:
jakarta-tomcat-4.0.1.exe. Please
note that this executable is only for classroom use and should be uninstalled
immediately after the end of this workshop.
Tomcat is available for free download from Jakarta's Website.
- Create a c:\JavaApps directory and download in there the database file
MIS120_Project2.mdb and the
properties file db.properties. Open
db.properties using Notepad and set DBPath = C:/JavaApps/MIS120_Project2.mdb.
- Download all the Java files in the c:\JavaApps directory,
in order to compile them:
CartItem1.java,
ShoppingCartBean1.java,
DBConnection2.java.
Open DBConnection2.java using Notepad and change the line that defines
properties_dir. Set properties_dir = "C:/JavaApps". Compile the java files
and transfer the class files into Tomcat's C:\Program Files\Apache Tomcat
4.0\webapps\examples\WEB-INF\classes.
- Download all the JSP files into Tomcat's jsp directory,
C:\Program Files\Apache Tomcat 4.0\webapps\examples\jsp:
BookList3.jsp,
CDList3.jsp,
Shopping_Cart2.jsp,
Confirmation2.jsp, and
Payment2.jsp.
- Create a /images subdirectory under Tomcat's jsp directory and place
over there all the image files:
add-to-cart.gif,
Books.gif,
BooksSelected.gif,
CDs.gif,
CDsSelected.gif,
OnlineStore.gif,
Strip.gif,
ablrule.gif,
book1.gif,
book2.jpg,
book3.jpg,
book4.jpg,
book5.jpg,
book6.jpg,
book7.gif,
book8.jpg,
cd1.gif, cd2.jpg,
cd3.jpg, cd4.jpg,
cd5.jpg, cd6.jpg,
cd7.jpg.
- At the DOS prompt, run ipconfig, to get to know your computer's
IP adress. Then, verify that your online shopping cart application
is up by pointing your browser to the Web address:
http://...(IP address)...:8080/examples/jsp/BookList3.jsp.
The shopping cart should also work at
http://localhost:8080/examples/jsp/BookList3.jsp.
Programming Assignments
- Programming Assignment 1 (final wording): Write a program for automatic text translation from
a foreign language to english. The dictionary file should have colon-separated pairs of words
like french:english. Read the file into a hash table which stores the foreign word
as the key. Read the input text line by line. Tokenize each line, lookup each word,
and create the output line. Write each line out to an output text file. Your program should
accept the filename of the foreign text, the dictionary, and the translation filename as
arguments of the command line. Structure your program using two different classes, a "Translate"
class and a "Dictionary" class. The Dictionary class should implement a getMeaning, a setMeaning,
and a loadDictionary method. Leave setMeaning blank for future implementation. Translate class should
just have a main method calling the Dictionary class methods.
Turn in a report, including a discussion of your program, printouts of the translated texts,
a class diagram showing the two classes, and a discussion of ways you would go about improving
your code so that it produces a better translation.
Use french0.txt and spanish0.txt
as the foreign text. Use fr_en_dict.txt as the french-to-english
dictionary, and sp_en_dict.txt as the spanish-to-english
dictionary. Please note that you should right-click on these links and save them, not
open them with the browser and do copy-and-paste, as they contain non-english characters.
Help: Use greek1.txt as the foreign text,
gr_en_dict.txt as the dictionary, and run
Translate1.java. It will produce the translation in a file
called out.txt. Examine the source code and try to come up with improvements. Look at
the code in Translate2.java and use it as a template.
Finally, look at the code in StringOps.java which
shows how to manipulate strings.
Solution: The solution for Assignment 1 is provided here in a file called
Translate.java.
- Programming Assignment 2 (final posting): Write an Image Browser program, which can
be executed either as an applet or as an application (the same program). The image browser
should look like the figure in this A2.doc word document. First create a
c:\hw2 directory on your computer. Then place this a2.PROPERTIES
file over there. This is a file that your program should read and see where your images are
located. Download the image files
provided below and place them in a directory called c:\hw2\images, so that there is
compatibility with the current contents of the a2.PROPERTIES file. Continue writting Java code
to implement the image browser. Your program should list all filenames of images included
in the \images directory, inside a listbox. The image of the selected file
should appear on the screen, as long as a "Show Image" radio button is selected.
When a "Hide Image" radio button is selected instead, the selected filename's image should
not appear on the screen. A pushbutton called "Exit" should cause your program to stop.
Images:
book1.gif, book2.jpg,
book3.jpg, book4.jpg,
book5.jpg, book6.jpg,
book7.gif, book8.jpg,
cd1.gif, cd2.jpg,
cd3.jpg, cd4.jpg,
cd5.jpg, cd6.jpg,
cd7.jpg.
Deliverable: Turn in a 2-page report with a brief introduction,
the desugn template in A2.doc, a "Use-case" diagram, and a screen shot with your own
application/applet running and browsing image files. Attach your code at the end as an Appendix.
Due: Thursday, March 14.
Bonus: 2 extra points if your GUI has the windows look-and-feel.
Help: Run ImageBrowser1.java.
It will create a scrolling list of all files contained in a c:hw2/images directory
(which you have to create on your own computer and place the provided image files over there)
and will even show you the images. Run AppletDemo.java to see
how a program can be an application and an applet. Refer to
ImageBrowser2.java as a programming template for your code.
Finally, have a look at ImageBrowser3.java for an
example layout arrangement of the various GUI components. In order to view all the programs
provided here as applets, you need to have a simple HTML document similar to
ImageBrowser3.html. Note that, while ImageBrowser3.html
works fine with SDK's appletviewer, it will not work with most Web browsers. The problem is
that your Web browser may not have the swing library. Updated versions of Netscape Navigator
and Internet Explorer will solve this problem by accommodating swing.
References: If you want additional flexibility in the way you arrange your
GUI components, you can learn about
Absolute positioning
of Swing components using insets by reading the related Java Tutorial. You can learn about
BoxLayout
by reading another related Java Tutorial.