1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sertanlavr [38]
3 years ago
5

Write the definition of a class Counter containing:

Computers and Technology
1 answer:
Dmitriy789 [7]3 years ago
4 0

Answer:

Answer is in java language.

Explanation:

Java Code

a) Creating instance variable

public class Counter {

   int counter;

   int limit;

}

Code Explanation

create a public class and declare variables inside the class block. By doing this, it will create instance variable of that class.

b) Constructor

public Counter(int first, int second){

       this.counter=first;

       this.limit=second;

   }

Code Explanation

Constructor are method having no return type and having exact name as Class name. Constructor are used to initialize the class instance before calling any other method.

c) Increment Method

public void increment(){

       if(this.counter<this.limit){

           counter++;

       }

   }

Code Explanation

void tells the compiler that there is nothing to return from current method. If block is checking the condition that if counter is less then the limit then increment the counter by 1.

d) Decrements Method

public void decrement(){

       if(this.counter>0){

           this.counter--;

       }

   }

Code Explanation

Decrement method will check if counter value is greater then 0 then decrement counter value by 1 in if block.

e) getValue method

public int getValue(){

       return this.counter;

   }

Code Explanation

getValue method will take no parameter as input and return the current counter value by using return statement.

Full Code Example

public class Counter {

   int counter;

   int limit;

   public Counter(int first, int second){

       this.counter=first;

       this.limit=second;

   }

   public void increment(){

       if(this.counter<this.limit){

           counter++;

       }

   }

   public void decrement(){

       if(this.counter>0){

           this.counter--;

       }

   }

public int getValue(){

       return this.counter;

   }

}

You might be interested in
An attacker gained remote access to a user's computer by exploiting a vulnerability in a piece of software on the device. The at
Anni [7]

"A Buffer overflow" vulnerability exploit resulted from the attacker's actions.

Whenever a software or an application writes too much data into a buffer, causing neighboring storage regions to have been corrupted as a consequence, this could be determined as Buffer overflow.

⇒ There are two kinds of Buffer overflow attacks such as:

  • <u>Stack-based</u> - It will become more popular to use such memory, as well as that's only available during implementation of any code.
  • <u>Heap-based</u> - Those attacks seem to be more difficult to execute because they entail overflowing overall storage capacity allotted for a program further than the space needed for something like the program's present activities.

Thus we can say that the correct answer is a Buffer overflow.

Learn more about Buffer overflow here:

brainly.com/question/4952591

6 0
3 years ago
When a cardholder successfully contests a charge, the acquiring bank must retrieve the money it placed in the merchant account i
lions [1.4K]

Answer:

Charge back.

Explanation:

A chargeback is a charge that is returned to a payment card after a customer successfully disputes an item on their account transactions report. Simply put, it is the reversal of a credit card payment that comes directly from the bank.

Most commonly the payer is a consumer.

A chargeback may occur on bank accounts or credit cards. They can be granted to a cardholder for a variety of reasons. A chargeback can be considered a refund since it returns specified funds taken from an account through a prior purchase. Chargebacks are focused on charges that have been fully processed and settled. Chargebacks can often take several days for full settlement as they must be reversed through an electronic process involving multiple entities.

The chargeback is ordered by the bank that issued the consumer's payment card.

6 0
3 years ago
What type of security software prevents, detects, and removes malware that tries to collect personal information or change compu
Lesechka [4]
Antivirus? I think is the correct answer
4 0
3 years ago
Kelly completes a bachelor's degree in animation from a top school in New York. She would now like to look for a job that will p
nikdorinn [45]
I believe she would have a best chance in a media production house, animation is a form of media and would be best put to use there.
8 0
3 years ago
Read 2 more answers
Consider the following code segment, which is intended to set the Boolean variable inRange to true if the integer value num is g
Natasha_Volkova [10]

Answer:

Option d  num = 50, min = 50, max = 50

Explanation:

Given the code segment:

  1. boolean isBigger;
  2. boolean isSmaller;
  3. boolean inRange;
  4. if (num < max)
  5.        {
  6.            isSmaller = true;
  7.        }
  8.        else {
  9.            isSmaller = false;
  10.        }
  11.        if (num > min)
  12.        {
  13.            isBigger = true;
  14.        }
  15.        else {
  16.            isBigger = false;
  17.        }
  18.        if (isBigger == isSmaller) {
  19.            inRange = true;
  20.        } else {
  21.            inRange = false;
  22.        }

If we have num = 50, min = 50 , max = 50,  the condition num < max will be evaluated to false and therefore isSmaller is set to false.

The condition num > min will be evaluated to false as well and therefore isBigger is set to false.

Since isSmaller and isBigger are both false and therefore isBigger == isSmaller will be evaluated to true and set the inRange = true. This has violated the statement that if the integer value num is greater than min value and less than max value, then only set inRange to true. This is because num = 50 is neither greater than min nor less than max, it is supposedly not in range according to the original intention of the code design.

8 0
3 years ago
Other questions:
  • Create a string called alphabet containing 'abcdefghijklmnopqrstuvwxyz', then perform the following separate slice operations to
    14·1 answer
  • How many iterations for each for-loop where max = 10 and incr = 3 a. for (int i = 0; i &lt; max; i++) b. for (int i = 0; i &lt;
    13·1 answer
  • Your friend Rebecca called because she is working on a budget and needs help with the AutoSum feature. She thinks AutoSum will b
    8·1 answer
  • Is a computer an input output or storage
    14·1 answer
  • What is the widest area network?
    15·1 answer
  • 11. You tried to turn on your desktop computer, but your desktop computer would not even turn on. You pressed the power button,
    8·1 answer
  • Why is computer called and information processing machine​
    6·1 answer
  • 19. WHICH KEY ALLOWS YOU TO DELETE AND TYPE OVER TEXTS? *
    5·2 answers
  • Different between I time and E time​
    12·1 answer
  • How do I fix when it hits the second session it skips scanf..
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!