Question

In: Computer Science

Write a complete Java program to create three types of counters as follows: The first counter...

Write a complete Java program to create three types of counters as follows:

  1. The first counter increases its value by one.
  2. The second counter increases its value by two.
  3. The third counter increases its value by three.

Please follow these notes:

  1. Create one class for all counter types. The name of the class is Three_type_counter.
  2. Define a constructor method that initial values for all counters to 7 when the class object created.
  3. Create method for each counter as: count1, count2 and count3. Each method has to increase each counter value by one, two and three respectively.
  4. In the main program:
    1. Create new object with name “obj_counter”.
    2. Call the three methods for each counter at one time.
    3. Print out the values for all counters.(support your answer by screenshot)

Solutions

Expert Solution


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);
   }
}


Related Solutions

jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread prints all capital letters 'A' to'Z'. The other thread prints all odd numbers from 1 to 21.
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT