Question

use java Develop a design for the problem – that is determine a set of methods...

use java

Develop a design for the problem – that is determine a set of methods (specify the method header, the purpose of each parameter and the return type and a short explanation of what the method does) which together will solve the problem. Each method must have one clearly defined task. Break methods into several methods if they are too complicated. This requires you to think about how you want to approach the problem. (You will benefit from following the approach discussed in class for the balanced expressions.) You have to turn this in early.

Write a class HTMLTest which implements a method called checkHTML with the heading publicString checkHTML(String expression) which determines whether the given string is a well- formed HTML expression. The String parameter is the HTML expression to be checked. The method returns a String as described below. Your implementation must use a stack.

The string returned by checkHTML includes status information and processing information.
Status information: The status information is one of the following (exactly as given here; no leading or trailing blanks):

              Success.
              Error: Closing tag does not match opening tag.
              Error: Closing tag encountered and stack empty.
              Error: Opening tag(s) left of stack.

Processing information: The processing information consist of the following 4 integers, separated by one space

: add a date (and time) when it is completed
: be realistic – don’t expect yourself to work wonders
: should specify something to be done not something to be avoided : make the steps fit your work style, your personality, your thinking : be specific – so you know where you are in your plan.

the assignment. The second step might be understanding the approach

  1. (i) total number of items process,

  2. (ii) the number of opening tags processed

  3. (iii) the number of closing tags processed (including the current one if it causes and error)

  4. (iv) the number of non-tags (items which are not white space and are neither an opening or

    closing tag).

4. Write
a. How did you deal with the tags? Did you strip the delimiters (<, >, /) immediately? Were they

a report about your solution. It must address the following questions. (rubrics and format posted)

part of what was pushed on the stack? How does your design address the statement “Tags are not

case sensitive”?

  1. What are the similarities and differences between your algorithm and the balanced parentheses

    algorithm?

  2. How did you ensure that the correct processing information is available for display at the end?

  3. Did you implement the original design you submitted? If not, what are the differences? Explain

    why you needed to make the change and your current design. What did you learn from this

    which might be useful in the future?

Homework Answers

Answer #1

Hi, Please find the solution and rate the answer. Comments inline.

import java.time.LocalDateTime;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Main main = new Main();
        System.out.println();
        System.out.println();
        System.out.println(main.checkHTML("<body>this is <h1>nice</head>"));
    }


    public String checkHTML(String expression){
        String finalExp = expression.replace("\n","");
        Stack<String> stack = new Stack<>();
        String statusString="";
        int len = finalExp.length(),i=0;
        while(i<len){
            if(finalExp.charAt(i)=='<'){
                if(finalExp.charAt(i+1)=='/'){
                    i++;//to cross '<'
                    while(finalExp.charAt(i++)!='>');
//                    i++;//to cross '>'
                    try {
                        stack.pop();//to pop tag
                    } catch (Exception e) {
                        statusString+="No closing tag\n";
                        return statusString;
                    }

                    continue;
                }
                StringBuilder sb = new StringBuilder();
                sb.append(finalExp.charAt(i));
                while(finalExp.charAt(i++)!='>'){
                    sb.append(finalExp.charAt(i));
                }
                i++;//to cross '>'
                stack.push(sb.toString());
            }else{
               while(finalExp.charAt(i++)!='<');//ignore text
                System.out.println();i--;
            }


        }
        if(stack.isEmpty()){
            statusString+="Well formed HTML:"+ LocalDateTime.now();;
        }else{
            statusString+="Not Well Formed:"+ LocalDateTime.now();

        }
        return statusString;
    }
}

Sample out:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Stack2540Array import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY...
Stack2540Array import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY = 128; int top ; String [] stack ; public Stack2540Array () { stack = new String [ CAPACITY ]; top = -1; } 1 3.1 Implement the stack ADT using array 3 TASKS public int size () { return top + 1; } public boolean isEmpty () { return (top == -1); } public String top () { if ( top == -1)...
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These...
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These same mechanisms can be used as a part of writing a simple compiler. Write class InfixToPostfixConverter co convert an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers (to make things easier) such as (6 + 2) • 5 - 8 / 4 to a postfix expression. The postfix version (no parentheses are needed) of this infix expression is 6...
1. Which of the following statements is FALSE? a. A transformer operation changes the object (e.g....
1. Which of the following statements is FALSE? a. A transformer operation changes the object (e.g. list.add(element) changes the list by adding an element) b. An observer operation may also modify the object (e.g. list.isFull( ) may increase the size of the list if no more elements can be added) c. An observer operation returns information about an object (e.g. list.size() returns the number of elements in the list) d. A transformer operation may or may not return a value....
For this part, you will write a PostfixCalculator class that has methods for processing each possible...
For this part, you will write a PostfixCalculator class that has methods for processing each possible input. You will write a Tester class that reads a line of input from the user, with each symbol separated by a space, and prints out the numeric value of the top of the stack. If the user specifies an incomplete expression, print out the top of the stack and print out a message saying that the stack contains more than one item. If...
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. It doesn't need an HTML form, all the arguments are put in through the method. The class must check for a correct operator (+,*,-,/), and a...
java CLASS DESIGN GUIDELINES 1. Cohesion • [✓] A class should describe a single entity, and...
java CLASS DESIGN GUIDELINES 1. Cohesion • [✓] A class should describe a single entity, and all the class operations should logically fit together to support a coherent purpose. • [✓] A single entity with many responsibilities can be broken into several classes to separate the responsibilities. 2. Consistency • [✓] Follow standard Java programming style and naming conventions. Choose informative names for classes, data fields, and methods. A popular style is to place the data declaration before the constructor...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
For Java For this assignment you will develop two classes called ATM and Customer that simulate...
For Java For this assignment you will develop two classes called ATM and Customer that simulate an imaginary automated teller machine (ATM). In the assignment, you should also develop a UML class diagram for the ATM class and a jUnit test case. In the program, we assume that an ATM initially keeps $100.00 cash for customer transactions. Additionally, we assume that there are a total of ten customers combined for the Union Bank and BOA banks. This is a list...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b,...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....