3.6k views
1 vote
construct a finite-state machine that models a newspaper vending machine that has a door that can be opened only after either three dimes (and any number of other coins) or a quarter and a nickel (and any number of other coins) have been inserted. once the door can be opened, the customer opens it and takes a paper, closing the door. no change is ever returned no matter how much extra money has been inserted. the next customer starts with no credit.

1 Answer

4 votes

Final answer:

To construct a finite-state machine for a newspaper vending machine, follow these steps: Define the states and transitions, including conditions for opening the door. Start with the initial state S0, and transition to states S1, S2, and S3 based on the insertion of coins. Transition back to S0 after opening the door.

Step-by-step explanation:

To construct a finite-state machine that models a newspaper vending machine, we can start by defining the states and transitions that represent the different scenarios. Let's denote the states as S0, S1, S2, and S3. The transitions will represent the insertion of coins and the conditions for opening the door. Here is the step-by-step explanation:

Start with the initial state S0, representing no credit.

When a dime is inserted, transition to state S1.

When another dime is inserted, transition to state S2.

When a third dime is inserted, transition to state S3 (door can be opened).

Alternatively, when a quarter and a nickel are inserted, transition directly from S0 to S3 (door can be opened).

Once the door is opened, transition back to S0 (next customer starts with no credit).

User Jeff Mergler
by
7.8k points