Hi Im currently having trouble with making constructors for
Hi Im currently having trouble with making constructors for a java program. I am a total newbie and need help big time!! If anyone could help with the following program it would be greatly appreicaited.
public class CounterPlus {
private int counter;
public void count(){
counter = counter + 1;
}
public int getValue(){
return counter;
}
public 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, of course, need a new instance variable to support this new
action.//
}
public int getLimit(){
//which returns the current value of the limit//
}
public 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). //
}
public void count(int increment){
//which an overloaded version of count. This version causes the
counter to increase by the amount of the parameter//
}
public CounterPlus(){
// which is a constructor that takes no arguments. It sets the default limit to
5.//
}
public CounterPlus(int limit){
// which is a constructor that takes one argument. It sets the limit to
the value specified by the parameter//
}
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(){
++counter;
int total = counter;
}
}
The following is a program that should be able to execute the previous program. So basically building the actually constructors is where i need the most help!! And thanks for help!!
/**
* This class tests the CounterPlus class.
*
* @author
* Course:
* Created:
* Source File: CounterPlusTest.java
*/
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(3);
testCounterPlus(counter);
}
}
Solution
help for this
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