In: Computer Science
Write a complete Java program to create three types of counters as follows:
Please follow these notes:
public class Three_type_counter {
public int firstCounter;
public int secondCounter;
public int thirdCounter;
// constructor of the class
public Three_type_counter()
{
firstCounter=7;
secondCounter=7;
thirdCounter=7;
}
// increment by one
public void Count1()
{
firstCounter++;
secondCounter++;
thirdCounter++;
return;
}
// increment by two
public void Count2()
{
firstCounter=firstCounter+2;
secondCounter=secondCounter+2;
thirdCounter=thirdCounter+2;
return;
}
// increment by three
public void Count3()
{
firstCounter=firstCounter+3;
secondCounter=secondCounter+3;
thirdCounter=thirdCounter+3;
return;
}
// main function
public static void main(String args[])
{
Three_type_counter obj_counter=new
Three_type_counter();
obj_counter.Count1();
obj_counter.Count2();
obj_counter.Count3();
System.out.println(obj_counter.firstCounter);
System.out.println(obj_counter.secondCounter);
System.out.println(obj_counter.thirdCounter);
}
}