Assignment No.7

  1. (Adapted from Textbook Chapter 6 Exercise 12) Write a method called stripHtmlTags that accepts a Scanner presenting an input file containing an HTML web page as its parameter, then reads that file and prints the file's text with all HTML tags removed. A tag is any text between the characters < and >. No tags appear across multiple lines and no tags overlap with other tags. For example, consider the following text:

    <html>
    <head>
    <title>My web page</title>
    </head>
    <body>
    <p>There are many pictures of my cat here,
    as well as my <b>very cool</b> blog page,
    which contains <font color="red">awesome
    stuff about my trup to vegas.</p>

    here's my cat now:<img src="cat.jpg">

    </body>
    </html>

    If the file contained these lines, your program should output the folllwing text:



    My web page


    There are many pictures of my cat here,
    as well as my very cool blog page,
    which contains awesome
    stuff about my trup to vegas.

    here's my cat now:




  2. (Adapted from Textbook Chapter 6 Exercise 4) Write a method called countCoins that accepts a Scanner representing an input file whose data is a series of pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be “pennies” (1 cent each), “nickels” (5 cent each), “dimes” (10 cent each), or “quarters” (25 cent each), case-insensitively. Add up the cash values of all the coins and print the total money. For example, if the input file contains the following text:

    3 pennies 2 quarters 1 Pennies 23 NickELS 4 DIMES

    For the input above, your method should produce the following output:

    Total money: $2.09

Go back to the assignment list page.