Lab 3 (100 pts)
Due Monday, April 29 at 11:59pm on Canvas

Pair Programming Required or No Credit!

  • Both partners fill in, sign and date the pair programming contract and BOTH partners submit this file.
  • Only one partner submits the lab assignment on Canvas. Please make sure both your names are on ALL the files.
  • Both partners follow the rules for pair programming.

Part 1: Implementing Your Stack and Queue (65 pts)
  • Begin by implementing the Stack and Queue classes as defined in the lesson notes
  • For the Queue class instructions, see Queue Lesson (Lesson 5)
  • For the Stack class instructions, see Stack Lesson (Lesson 6)
  • Note that you must implement all methods whose signatures are provided. No credit for writing any additional methods for these two classes or for altering the class definitions or method signatures, in any way, aside from implementing the required methods
  • Make sure to test all of your methods to ensure that they are working properly in separate test files, named QueueTest.java and StackTest.java (where you should call each method at least two times inside of main as soon as you write it).
  • When you have finished writing the classes, test your methods further by writing JUnit test classes (3 assertEquals statement per class) for each of the following methods:
    • Queue Class:
      • enqueue
      • dequeue
      • getFront
      • getLength
      • isEmpty
      • equals
    • Stack Class:
      • push
      • pop
      • peek
      • getLength
      • isEmpty
      • equals
  • For the purposes of the JUnit tests, please put your Stack tests in a different folder from your Queue tests of you may have trouble with duplicate file names.
  • Once you are satisfied that your methods are working properly (passing all JUnit tests and the tests you wrote in QueueTest.java and StackTest.java), move on to part 2 below.


Part 2: HTML Parser (35 pts)

  • Write a Java class named HTML Parser that can read a file of HTML and determines whether the all start tags have a matching end tag.
  • Your solution must use a Stack and/or a Queue from this lab to store all or a portion of the tags in the input file or you will not receive credit for this part of the assignment.
    • You are not allowed to use any additional data structures such as an array or list in this program or any other stacks or queues other than the ones you wrote for part 1 of this lab.
  • Optional: Before you begin, read this article about why HTML is not considered a programming language
  • Before you begin: Install an html editor for Eclipse following this tutorial
  • Next, create a new java file called HTMLParser.java and save it in a folder along with your Stack.java and Queue.java from Part 1 of this Lab.
  • Make sure to put the names of both partners at the top in a Javadoc comment
  • Your HTMLParser program should prompt the user for the name of an input file.
    • It should report back if it cannot find a file of that name and allow the user to try again as many times as required to run the file.
    • The user should be able to enter the name of any file on their computer
  • Next, it should check whether all start tags have a matching end tag, by storing some or all tags in a Queue and/or a Stack
  • Below are a list of tags your program should recognize in both upper and lower case:
    • <a></a>
    • <b></b>
    • <body></body>
    • <center></center>
    • <h1></h1>
    • <h2></h2>
    • <h3></h3>
    • <h4></h4>
    • <head></head>
    • <html></html>
    • <i></i>
    • <table></table>
    • <td></td>
    • <tr></tr>
    • <title></title>
  • Any additional tags should be ignored
  • Your program should give one of two console outputs:
    • All tags match. Nice work! OR
    • No matching tag for <tag name>
      Please revise your html and try again.
  • Please see the sample output below.
  • Hint: Make full use of the String API methods to help you complete this assignment!

SAMPLE OUTPUT

Welcome to the HTML parser!

Enter the name of your file: simple.html
All tags match. Nice work!




MATCHING INPUT FILE SIMPLE.HTML

<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
</HEAD>
</HTML>


SAMPLE OUTPUT

Welcome to the HTML parser!

Enter the name of your file: web
I cannot find that file. Please try again.

Enter the name of your file: web.t
I cannot find that file. Please try again.

Enter the name of your file: web.tx
I cannot find that file. Please try again.

Enter the name of your file: web.txt
I cannot find that file. Please try again.

Enter the name of your file: web.html
No matching tag for <h3>
Please revise your html and try again.


MATCHING INPUT FILE WEB.HTML

<html>
<head>
<title>Your Title Here </title>
</head>
<body BGCOLOR="FFFFFF">
<center> <IMG SRC="clouds.jpg" ALIGN="BOTTOM"></center>
<hr>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<H1>This is a Header </H1>
<H2>This is a Medium Header </H2>
Send me mail at <a href="mailto:support@yourcompany.com">
support@yourcompany.com </a>
<H3>This is a smaller header - below is a table</H4>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
<p>This is a new paragraph!
<p><b>This is a new paragraph!</b>
<br><b><i>This is a new sentence without a paragraph break, in bold italics. </i> </b>
<hr>
</body>
</html>

SAMPLE OUTPUT

Welcome to the HTML parser!

Enter the name of your file: webpge.html
I cannot find that file. Please try again.

Enter the name of your file: webpag.html
I cannot find that file. Please try again.

Enter the name of your file: webpage.html
All tags match. Nice work!



MATCHING INPUT FILE WEBPAGE.HTML

<HTML>
<HEAD>
<TITLE>Your Title Here </TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<CENTER> <IMG SRC="clouds.jpg" ALIGN="BOTTOM"></CENTER>
<HR>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<H1>This is a Header </H1>
<H2>This is a Medium Header </H2>
Send me mail at <a href="mailto:support@yourcompany.com">
support@yourcompany.com </a>
<H3>This is a smaller header - below is a table</H3>
<TABLE>
<TR>
<TD>1</TD>
<TD>2</TD>
<TD>3</TD>
</TR>
<TR>
<TD>A</TD>
<TD>B</TD>
<TD>C</TD>
</TR>
</TABLE>
<P>This is a new paragraph!
<P><B>This is a new paragraph!</B>
<BR><B><I>This is a new sentence without a paragraph break, in bold italics. </I> </B>
<HR>
</BODY>
</HTML>


Specifications for Submission:

  • Submit your Queue.java, Stack.java, and HTMLParser.java to Canvas, as well as QueueTest.java, StackTest.java and the required unit tests (please see above).
  • Required: ubmit your pair programming contract to Canvas (both partners) (-5pts for no contract).
  • Please submit each file separately (no zip files or other compressed file type -5 pts).
  • Please remove all package statements before submitting (-5 pts).

How You Will Be Graded:

  • 2.5 points per correct Queue and Stack method
  • 8 points for the QueueTest.java and StackTest.java files where each method is called at least twice.
  • 12 points for the required 12 JUnit tests (assertEquals called three times per class)
  • 35 points for a fully functional HTMLParser.java class