Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add the following methods to the public interface: - void setLimit(int newLimit)

ID: 3556721 • Letter: A

Question

Add the following methods to the public interface:

-   void setLimit(int newLimit), which sets the maximum number that the counter can display. If count is called, and the change would cause the counter to exceed the limit, issue a message in the form: "Limit of 6 exceeded", where the number (6, in this case) indicates the current limit.You will, ofcourse, need a new instance variable to support this new action.


-   int getLimit(), which returns the current value of the counter.

-   void undo() which causes the counter value to be reduced by one (unless the undo would cause the counter value to go negative, in which case, it does nothing).

-   void count(int increment) which an overloaded version of count. This version causes the counter to increase by the amount of the parameter.

-   CounterPlus() which is a constructor that takes no arguments. It sets the default limit to 5.

-   CounterPlus(int limit) which is a constructor that takes one argument. It sets the limit to the value specified by the parameter.

Here is what I got so far:


public class CounterPlus {


   private int value;
   private int Number;
       public void count(){
           value = value + 1;
   }
   public int getValue(){
       return value;
   }
   public static void main(String[] args){
       CounterPlus tally = new CounterPlus();
       tally.count();
       tally.count();
       int result = tally.getValue();
       System.out.println("Value: " + result);
       tally.count();
       tally.count();
       tally.reset();
       result = tally.getValue();
       System.out.println("value: " + result);
   }
   public void reset(){
      
       ++value;
       int total = value;
      
   }
   public void setLimit(int newLimit){
    }
   int getLimit(){
       return value;
   }
   public void undo(){
       value = value -1;
   }
   public void count(int increment){
       ++value;
   }
   public int CounterPlus(){
       return value;
    }
   public int CounterPlus(int limit){
       return value;
    }
}

This is the program that will be use to test the previous code, both files got to be in the same folder.

public class CounterPlusTest {public static void testCounterPlus(CounterPlus counter) {
   for(int i = 1; i <= 8; ++i) {
       if (i == 7) {int newLimit = 2 * counter.getLimit();
           counter.setLimit(newLimit);
           System.out.printf("Setting new limit to %d ", newLimit);
           }
       counter.count();
       System.out.printf("After count %d, counter is %d ", i,counter.getValue());
       }
   counter.undo();
   counter.undo();
   counter.count();
   System.out.printf("After 2 undo's and one count, counter is %d ", counter.getValue());
   counter.reset();
   counter.count(5);
   counter.count(5);
   System.out.printf("After reset and two counts by 5, counter is %d ", counter.getValue());
   }
public static void main(String[] args) {
   CounterPlus counter =new CounterPlus();
   testCounterPlus(counter);
   System.out.println("-------------------");
   counter = new CounterPlus();
   testCounterPlus (counter);
   }
}

Explanation / Answer

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Part 1: Use WebBrowser control to load web page

        WebBrowser1.Navigate("http://www.website.com/login.aspx")

        System.Threading.Thread.Sleep(2000) ' Delay 2 seconds to render login page

        ' Part 2: Automatically input username and password

        Dim theElementCollection As HtmlElementCollection

        theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")

        For Each curElement As HtmlElement In theElementCollection

            Dim controlName As String = curElement.GetAttribute("name").ToString

            If controlName = "UserNameTextBox" Then

                curElement.SetAttribute("Value", "Username text here")

            ElseIf controlName = "PasswordTextBox" Then

                curElement.SetAttribute("Value", "Password text here")

'In addition,you can get element value like this:

                'MessageBox.Show(curElement.GetAttribute("Value"))

            End If

        Next

        ' Part 3: Automatically clck that Login button

        theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")

        For Each curElement As HtmlElement In theElementCollection

            If curElement.GetAttribute("value").Equals("Login") Then

                curElement.InvokeMember("click")

                ' javascript has a click method for we need to invoke on button and hyperlink elements.

            End If

        Next

    End Sub

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote