public class Tag
extends Object
| Constructor and Description |
|---|
Tag() |
| Modifier and Type | Method and Description |
|---|---|
private static String |
entity(String str,
String tag)
An HTML tag name can change a lot, but since the format is shared,
we will focus on the principles of abstraction and DRY (Don’t Repeat Yourself),
to write a helper method.
|
static String |
h1(String str)
Returns header 1 formatted html tags.
|
static String |
h2(String str)
Returns header 2 formatted html tags.
|
static String |
h3(String str)
Returns header 3 formatted html tags.
|
static String |
htmlClosing()
Simple closing tags for an html document
|
static String |
htmlOpening()
Simple opening tags for any html document.
|
static void |
main(String[] args)
You must write tests for this program, and we will check that the following
tests have been implemented - at a minimum.
|
static String |
tableClose()
Simple closing tag of a table.
|
static String |
tableOpen()
Simple opening tag of a table.
|
static String |
td(String str)
Builds an html formatted table column element
<td>. |
static String |
th(String str)
Builds an html formatted table header element
<th>. |
static String |
tr(String str)
Builds an html formatted String for table row.
|
private static String entity(String str,
String tag)
<TAGNAME>text</TAGNAME>
Use String.format to return a String that matches the format above!
Here are some examples of entity in use
entity("Ada", "b"); // returns <b>Ada</b>
entity("Stem", "H1"); // returns <H1>Stem</H1>
entity("invalid", "madeUPname"); // returns <madeUPname>invalid</madeUPname>
str - The text value inside of the tagtag - the tag namepublic static String h1(String str)
<h1>Hello</h1>str - the text to apply the heading topublic static String h2(String str)
str - the text to apply the heading topublic static String h3(String str)
str - the text to apply the heading topublic static String tr(String str)
It does not take into account the row is valid, just simply
add the <tr> element around the text. So the following is valid
tr("myString"); // returns <tr>myString</tr>
tr(td("col1") + td("col2") + td("col")); // returns <tr><td>col1</td><td>col2</td><td>col3</td></tr>
str - the text that goes between the tagtd(String),
th(String)public static String td(String str)
<td>.str - the text that goes between the tagtr(String),
th(String)public static String th(String str)
<th>.str - the text that goes between the tagtr(String),
td(String)public static String tableOpen()
<table>public static String tableClose()
</table>public static String htmlOpening()
<html><head></head><body> public static String htmlClosing()
</body></html>public static void main(String[] args)
TEST: entity should create new tags - <b>STEM DEMO</b>
TEST: entity should create new tags - <custom>STEM DEMO</custom>
TEST: H1 should add <h1> - <h1>STEM DEMO</h1>
TEST: H2 should add <h2> - <h2>STEM DEMO</h2>
TEST: H3 should add <h3> - <h3>STEM DEMO</h3>
TEST: htmlOpening - <html><head></head><body>
TEST: htmlClosing - </body></html>
args - not needed, but included for completeness