Question

In: Computer Science

• P8.2 Simulate a tally counter that can be used to admit a limited number of...

• P8.2 Simulate a tally counter that can be used to admit a limited number of people. First, the limit is set with a call public void setLimit(int maximum) If the count button was clicked more often than the limit, simulate an alarm by printing out a message “Limit exceeded”.

Solutions

Expert Solution

Counter class:

public class P8_2 {
private int value = 0;
private int maximum;

public int getValue() {
return value;
}

public void count() {
if (value + 1 > maximum) {
System.out.println("Limit exceeded");
} else {
value = value + 1;
}
}

public void reset() {
value = 0;
}

public void undo() {
value -= 1;
}

public void setLimit(int maximum) {
this.maximum = maximum;
}
}

main java class:(must import counter class i.e. P8_2)


public class Main
{
    public static void main(String[] args) {
       P8_2 counter = new P8_2();
       counter.setLimit(7);

       counter.count();
       counter.count();
       counter.count();
       counter.count();
       counter.count();
       counter.count();
       counter.count();
       counter.count();//prints Limit exceeded as count called more than 7
       counter.count();
         
   
    }
}


Related Solutions

What is an NX (no-execute) bit, and how can it be used to counter buffer overflow...
What is an NX (no-execute) bit, and how can it be used to counter buffer overflow attacks?
With free entry: a)there is a known and limited number of potential suppliers that can produce...
With free entry: a)there is a known and limited number of potential suppliers that can produce a good in the long run. b)there is an unlimited number of firms that can produce a good in the long run. c)the long run market supply curve is vertical at the market quantity. d)the long run market demand curve is horizontal at the market price.
TLC can be used to confirm the components of over-the-counter analgesics. Assuming that you have pure...
TLC can be used to confirm the components of over-the-counter analgesics. Assuming that you have pure standard samples of caffeine, ibuprofen, acetaminophen, and aspirin, how would you determine if a new analgesic contains any of those four components? Provide information on how you would prepare the samples for analysis and how you would set up the TLC experiments.
How can a performance integrated budget be used to counter the archaic practice of across-the-board budget...
How can a performance integrated budget be used to counter the archaic practice of across-the-board budget cuts?
Flip all 3 coins 10 times. Each flip place a tally mark next to the number...
Flip all 3 coins 10 times. Each flip place a tally mark next to the number of heads in the following table Experiment 1 Number of Heads TallyMark 0 1 1 4 2 5 3 0 Total Tosses 10 Experiment 2 Number of Heads TallyMark 0 7 1 17 2 16 3 10 Total Tosses 50 Experiment 3 Number of Heads TallyMark 0 16 1 41 2 27 3 16 Total Tosses 100 For each of the tables on the...
Design the circuit that gives the total number of your school number as an asynchronous counter....
Design the circuit that gives the total number of your school number as an asynchronous counter. If 4 + 6 + 0 + 4 + 1 + 8 + 0 + 4 + 0 = 27, Mode 28 counter will be designed. FF with negative edge triggering will be used. You will definitely show the clock pulse, input and output connections of the FFs you will use. Otherwise, you will not get points because the counter will not work or...
There are a number of strategies that can be used to retain or increase cash on...
There are a number of strategies that can be used to retain or increase cash on hand. Some legal and some illegal. Illegally you can retain or increase cash by not reporting how much cash you actually made. However, that would land you in jail. Legally, one way to retain cash is to pay for items on credit therefore leaving cash to be used for more pressing matters. To increase cash one strategy is to pay your bills on time...
Using Cascaded counter with use minimum number of blocks, design the following 1- MOD336 counter 2-...
Using Cascaded counter with use minimum number of blocks, design the following 1- MOD336 counter 2- MOD250 counter 3- MOD180 counter 4- MOD 360 counter
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code of 4-bit modulo-9 counter in ModelSim, and capture the screenshot of your simulated waveform. Assume clock period Tclk=100ns, initially, the counter is reset to Q3Q2Q1Q0=0000 you need to simulate a complete counting cycle plus one more additional clock period after it is reset to “0000” state.
How to simulate BER vs SNR in matlab with increasing the number of users?
How to simulate BER vs SNR in matlab with increasing the number of users?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT