Public void validateHTML This method should make the instanc
Public void validateHTML()
This method should make the instance store the corrected version of the HTML when it is finished. To fix the HTML you will analyze the tags in stored in the HTMLManager using a Stack. The basic idea of the algorithm is to process the page tag by tag. For each tag, you will check to see if it has a matching tag later in the page in the correct place. Since self-closing tags don’t have to match anything, whenever you see one, you can simply add it directly to the result. For opening tags, we assume that the writer of the HTML page intended to actually include the tag; so, like with the self-closing tag, we add it to the result. However, we need to keep track of if we have found its match; so, it should also be added to a Stack. If we find a closing tag, we must figure out if it is in the right place or not. In particular:
If the opening tag at the top of the stack matches the closing tag we found, then it matches, and you should update the state accordingly. (Hint: You probably want to edit the stack and the output.)
If the opening tag at the top of the stack does not match the closing tag we found, then the writer of the HTML page made a mistake. To fix the mistake, you should add a new closing tag that matches the opening one at the top of the stack (so that it remains balanced). You should keep on fixing mistakes until the next tags match.
If, at any point, you find a closing tag that has no matching open tag, just discard it.
Note that every tag in the page that was ever opened must at some point be closed!
For example, the html “<b>hello</i>” is invalid, and the algorithm would fix it to be “<b>hello</b>”, because there is no open i tag. Also, if the algorithm were given the invalid html “<b><i>this is invalid</b></i>”, it would fix it to be “<b><i>this is invalid</i></b>”.
-If I don\'t get a solution that\'s fine, I need pointers. Should I be using a while loop instead of a for loop? How many if statements should I have? I already wrote most of the code for this but I don\'t know if it\'s right.
Solution
public void addEmployee(int input, String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double wage) {
switch (input) {
case 1: {
HourlyEmployee employee = new HourlyEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println(\"Duplicate Not Added\");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println(\"Cannot add more Employees\");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 2: {
SalaryEmployee employee = new SalaryEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println(\"Duplicate Not Added\");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println(\"Cannot add more Employees\");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 3: {
CommissionEmployee employee = new CommissionEmployee(firstName,
lastName, middleInitial, gender, employeeNum, fulltime,
wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println(\"Duplicate Not Added\");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println(\"Cannot add more Employees\");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
default:
System.out.println(\"Invalid Employee Type, None Added\");
break;
}
}
// Removes an Employee located at the given index from the Employee array.
public void removeEmployee(int index) {
employees[index] = null;
}
// Lists all the current Employees. Outputs there are none if there are
// none.
public void listAll() {
if (currentEmployees == 0)
System.out.println(\"none\");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null)
System.out.println(employees[i].toString());
}
}
}
// Lists all the current HourlyEmployees. Outputs there are none if there
// are none.
public void listHourly() {
if (currentEmployees == 0)
System.out.println(\"none\");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof HourlyEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current SalaryEmployees. Outputs there are none if there
// are none.
public void listSalary() {
if (currentEmployees == 0)
System.out.println(\"none\");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof SalaryEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current CommissionEmployees. Outputs there are none if
// there are none.
public void listCommission() {
if (currentEmployees == 0)
System.out.println(\"none\");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof CommissionEmployee)
System.out.println(employees[i].toString());
}
}
}
}
public void resetWeek() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].resetWeek();
}
}
}
public double calculatePayout() {
double payOut = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
payOut += employees[i].calculateWeeklyPay();
}
}
return payOut;
}
public int getIndex(int employeeNum) {
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
return i;
}
}
return -1;
}
public void annualRaises() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].annualRaise();
}
}
}
public double holidayBonuses() {
double holiBonus = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
holiBonus += employees[i].holidayBonus();
}
}
return holiBonus;
}
// Increase the hours worked of the Employee at the given index by the given
// double amount.
public void increaseHours(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof HourlyEmployee) {
HourlyEmployee employee = (HourlyEmployee) employees[index];
employee.increaseHours(amount);
}
}
// Increase the sales of the Employee at the given index by the given double
// amount.
public void increaseSales(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof CommissionEmployee) {
CommissionEmployee employee = (CommissionEmployee) employees[index];
employee.increaseSales(amount);
}
}
}



