Need help setting up a Finite State Machine in BlueJ

Hey all, I joined these forums to hopefully help me catch up with my Java skills. I haven't programmed in Java for almost a year, and the class I'm in now does little for review so I'm rusty to say the least. The assignment we were given recently is to create a Finite State Machine resembling a gumball machine. This are basically the requirements given:
The operation of the gumball machine is simple. It takes a quarter to get a gumball dispensed. The customer needs to deposit a quarter and turn the crank, and a gumball will be dispensed if the machine contains one or more gumballs.
Design steps:
There are a number of states: No_Quarter, Has_Quarter, Gumball_Sold, Out_of_Gumballs
Create an instance variable to hold the current state and define values for each of the states.
All the actions that can happen in the system are: insert_quarter, ejects_quarter, turns_crank, dispense_gumball, and refill_gumballs. The action dispense_gumball is an internal action the machine invokes when it reaches the Gumball_Sold state.
Create a class that acts as the state machine. For each action, create a method that uses conditional statements to determine what behavior is appropriate in each state.
Write a test program to test the GumballMachine class. You consider not just normal operations i.e. insert a quarter, turn the crank; but also operations such as insert a quarter, eject the quarter, turn the crank. Or what if you turn the crank twice after insert one quarter. Or what if you insert two quarters in a row.
Now trust me, I'm not asking for someone to come here with a hunk of code and say, ok use this, and it's done. What I'm here for is hopefully someone can walk me through the right thought process of how to implement the states, and where/how to include the actions to go along with the states. We're to use BlueJ to write the code, and I'm still pretty unfamiliar with its arrow system that tells Test Programs to use the linked class(es).
Thanks for any help in advance, and for what it's worth, speedy responses are especially appreciated!

Did you upload everything to your server?  Did you perform the compatibility check?
FormCaptcha’s requirements:
PHP 4.0 or later.
GD Library for PHP, version 2.0 or greater (it's installed on most web servers but it may not be enabled).
The page that processes the form must have .PHP extension.
Tip: If you want to be sure that your web server supports this captcha tool, then you can download and test our free captcha compatibility check. This is a script that checks if your web server can generate captcha images and perform the captcha validation.
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media  Specialists 
http://alt-web.com/

Similar Messages

  • I have defined a finite state machine: pb with button : they need to be click twice

    I have defined a finite state machine and also defined a call to a C dll enabling to kill processus  since in my state machine I have to sequence several exe and being able to interupt them (This is the goal of mu manageProc dll)
    for the moment I make my integration test with the notepad.exe process
    the create and kill seems to work
    but I have problem wth my finite state machine I need to click twice on the differnts button for a given state to be really effective
    I have also used glabal variable and an event controller ( without that I was unable to get ffedback oo buuton click
    So my question are
    Is my problem due to the use of a shift register
    Please tell me if you need other file to understand my problem
    Regards
    Thibaut
    Attachments:
    Spectro State MAchine .vi ‏77 KB

    Thibaut,
    You should put the event structure into its own parallel while loop rather than sharing the loop with the state machine. Typically the terminals of the controls will be placed inside the event case where they are read. At least inside the loop.
    Run your VI with execution highlighting on (the light bulb on the diagram toolbar). This will show you how dataflow works.
    You probably do not need most of your global variables. Appropriate use of shift registers and wires would eliminate them.
    Lynn

  • Need help setting up and configuring rsync

    Hello
    I need help setting up, or rather configuring rsync to sync data between my brand new iMac and my Macbook Air.
    Here is what I would like to:
    - I want all of the files on both machines to be an exact mirror or copy of each other. Basically I have an iMac for at home, and then a Macbook Air for the road.
    - The main folder on both Macs is called 'Sara' and I want the contents (mainly the 'movies' folder, 'music' folder, 'documents' folder and 'pictures' folder) to immediately sync up with each other when both of them are on my home network.
    - this means if I'm working on a file at home on my Macbook, it will immediately write to the same directory on my iMac and vice versa (if I'm working on file(s) on my iMac, it will immediately save the contents to my Macbook). This way, if I'm working on last minute project my iMac, and then have to head out the door to the airport, the file is immediately saved to my Macbook (no usb for USB transfer).
    - hopefully this makes sense??
    Any help is greatly appreciated!
    Thanks

    It's a lofty but unrealistic goal.  Rsync does not run automatically.  There is no realistic method of instantaneously synching two computers over the internet or even on a LAN.
    I would suggest you might try using Synk Pro which, in theory, can keep two devices in sync when they are both on the same network (and both have shared and mounted drives.)
    If you must do this with rsync then I suggest a Google search for rsync tutorials.

  • Need help Setting up Multiple Static Ip , 1 for each port of the fios router

    Need help Setting up multiple Static Ip on my fios router
    I have been trying to figure out how to set up multiple ip in my fios router.
    However I kind of managed how to set up multiple static ip However the way I want it is for each port of my router to have an external ip signed to it. ( like 4 different modem in 1 )
    Verizon gave me 5 static ip but they can not help me how to set it up.
    Have anyone here done more then one static ip on different ports? I assume that the process will be the after the second static ip.

    You want to set up Static Nat. You will not assign the IP to a port, but rather to a local machine. Figure out what machines you want your IP's to go to. Under the firewall section you will see static nat. Pick the machine you want and enter one of the IP's you were assigned.

  • Finite state machines

    hi
    this is a bit of a stab in the dark but does anyone have experience in implementing evolving finite state machines in java. im trying to build a system of creatures who are controlled by an fsm and who compete for a limited resource. i want to control their physiology with the fsm and have them evolve more complicated competetive strategies. i just want someone to throw some ideas at and ask some questions. can anyone help?
    julian.

    sounds interesting. i've heard a lot about finite state machines but i've never understood what exacly is an finite state machine. we german call it "endlicher automat". is it the same as an turing machine? i have never studied computer science so i have no idea what this terms really mean.

  • Finite State Machine

    hello dear coders. I'm a software engineering student and i have an assignment to create an Elevator Simulator using various programming patterns.
    One of them is the an advance form of the State Pattern from Gang of Fours, the Finite State Machine.
    On assignment delivery i have to justify every choice i made in implementing the patterns. I have my understanding of the FSM ( finite state machine) but i don't know if it's even near the correct form.
    I'll post the classes I've made for a elevator simulator, and i would appreciate if you give me your opinion and state what i could improve and why.
    I'll post also the possible state changes for the simulator requested by teacher.
    States : [http://img201.imageshack.us/img201/6150/stateskz6.th.jpg]
    Since they are in portuguese i'll give you the translation:
    Porta Fechada = Door Closed
    Porta Aberta = Door Open
    Ascendente = Going up
    Descendente = Going down
    Parado = Stopped ( or idle )
    class : StateMachine
    * @author bruno
    public class StateMachine {
        private AbstractState state;
        private AbstractState globalState;
        private AbstractState previousState;
        public StateMachine(AbstractState state, AbstractState globalState, AbstractState previousState) {
            this.state = state;
            this.globalState = globalState;
            this.previousState = previousState;
        public StateMachine() {
            this.state = new StateStopped();
            this.globalState = new StateGoingUp();
            this.previousState = new StateGoingUp();
        public void update() {
            if (state instanceof StateDoorClosed) {
                if (previousState instanceof StateGoingUp || previousState instanceof StateGoingDown) {
                    this.changeState(this.getState().open());
                } else if (previousState instanceof StateDoorOpen || previousState instanceof StateDoorClosed) {
                    this.changeState(this.getState().execute());
            } else if (state instanceof StateStopped && !(globalState instanceof StateStopped)) {
                if (globalState instanceof StateGoingUp) {
                    this.changeState(this.getState().up());
                } else {
                    this.changeState(this.getState().down());
            } else {
                this.changeState(this.getState().execute());
        public AbstractState getState() {
            return state;
        public AbstractState getGlobalstate() {
            return globalState;
        public void setState(AbstractState state) {
            this.state = state;
        public void setGlobalState(AbstractState globalState) {
            this.globalState = globalState;
        public AbstractState getPreviousState() {
            return previousState;
        public void setPreviousState(AbstractState previousState) {
            this.previousState = previousState;
        public void changeState(AbstractState newState) {
            this.setPreviousState(state);
            this.setState(newState);
    }class : AbstractState
    * @author bruno
    public abstract class AbstractState {
        protected AbstractState state;
        public abstract AbstractState execute();
        public abstract AbstractState up();
        public abstract AbstractState down();
        public abstract AbstractState open();
        public abstract AbstractState close();
        public AbstractState getState() {
            return state;
        public AbstractState(AbstractState state) {
            this.state = state;
        public AbstractState() {
            this.state = this;
        public void setState(AbstractState state) {
            this.state = state;
    }I omitted the concrete State Classes because of length, if you would like me to post them as-well please, don't hesitate to ask.
    Sorry for the bad English and for the length of the post.
    THANK YOU IN ADVANCE!

    >
    Two things with this code:
    public void update() {
    if (state instanceof StateDoorClosed) {
    if (previousState instanceof StateGoingUp || previousState instanceof StateGoingDown) {
    this.changeState(this.getState().open());
    } else if (previousState instanceof StateDoorOpen || previousState instanceof StateDoorClosed) {
    this.changeState(this.getState().execute());
    } else if (state instanceof StateStopped && !(globalState instanceof StateStopped)) {
    if (globalState instanceof StateGoingUp) {
    this.changeState(this.getState().up());
    } else {
    this.changeState(this.getState().down());
    } else {
    this.changeState(this.getState().execute());
    }Firstly, that doesn't look like a finite state machine. In a FSM the next state depends on the current state and the input it receives, whereas your machine it depends on the previous state and the global state, and no input.
    Secondly, almost always if you're using instanceof to change behaviour, you're doing something wrong. It's useful for testing data you've received from a general purpose channel, such as some serialisation mechanisms or an implementation of string formatting, but it shouldn't be in the core of classes where you've designed both sides of the contract.
    Usually you implement either a general purpose method to return the next state from a state given its input, or (as you have done) provide several methods to cope with the different inputs and return the next state. So the core execution logic would be for a general transition method.
      get input from outside
      state = state.transition(input)or for specific methods:
      get input from outside
      switch input
        case open: state = state.open()
        case close: state = state.close()The diagram you posted is too small to read, but it doesn't seem to have any inputs marked on the transitions, which makes the whole thing indeterminate, unless the inputs for each transition are recorded elsewhere.
    Your AbstractState has a reference to another state - why ? It should either have one state for each transition out of it, or none (for example, if you make each state instance an nested class of the machine, or use an enum for the states, they don't need anything other than a transition() method, and no fields)

  • HOW TO?: Need help setting up 3 different iCloud accounts for my kids (so each has own iMessanger)using same Apple ID (mine) ....they don't have their own separate email addresses to work from...how do I do this?

    Need help setting up 3 different iCloud accounts for my kids (so each has own iMessanger)using same Apple ID (mine) ....they don't have their own separate email addresses to work from...how do I do this?

    Any devices connected to the same icloud account can sync all the data on that account.  For this reason an icloud account is really for a single user.
    On a mac, if each user has their own account, then the itunes for that mac account should be set up to connect to that user's icloud account (System preferences>icloud).

  • Need help setting up TV equiptment

    I have been very ill and I need help setting up my TV, DVR, Receiver, Surround sound systems. I'm afraid if I try to work on all the equiptment, I'll drop my HDTV or other componets because I'm still weak. Can anyone help me? I've called a few places and they want $100.00 to set it up. Give me a break! I know about inputs and outputs and other cables, I just don't have the strength to move the equiptment around. I am willing to pay. Please call me at 813-{edited for privacy}. Thanks, Teresa {edited for privacy}

    blondeinneed wrote:
    I have been very ill and I need help setting up my TV, DVR, Receiver, Surround sound systems. I'm afraid if I try to work on all the equiptment, I'll drop my HDTV or other componets because I'm still weak. Can anyone help me? I've called a few places and they want $100.00 to set it up. Give me a break! I know about inputs and outputs and other cables, I just don't have the strength to move the equiptment around. I am willing to pay. Please call me at 813-{edited for privacy}. Thanks, Teresa {edited for privacy}
    Teresa,
    I think the best way for someone to volunteer to help you would be for them to send you a Private Message (PM) here on the forums. You should see a small envelope in the upper right corner of the screen, when it changes color you will know you have a PM to view.
    I would be happy to help, but since I am in North Texas I don't think that is a viable option Sorry....
    Justin
    FiOS TV, Internet, and phone user
    QIP7232, QIP7100-P2, IMG 1.9A
    Keller, TX 76248

  • I need help setting up an apple id for my sons phone. It seems his email address has been taken and/or we cant get the password.

    I need help setting up an apple id for my son's phone. It seems his email address has been taken and/or we cant get the password.

    Two different things
    If you forgot the password
    If you forgot your Apple ID password - Apple Support
    If the email ID you want to use is in use by someone else - then you may need a new one
    The iCloud ID's are usually unique and may be of help if you set one up

  • Need help setting up FCE 4   PLEASE

    OK, I'm NOT a professional, just need help setting up.
    Just purchased FCE 4. Need to set up my Sony HDR SR11. I've already recorded most of my stuff in HD SP. Can someone Please help me set up?
    thanks

    Thanks for the info.
    I updated and did a search in my manual for Log and transfer which didn't go to anything I can figure out. Sorry, I don't have time to read 1152 pages.
    Can anyone just tell me how to get this going? There should be a simple set up correct?

  • My email is not working in lightroom. Need help setting that up.

    Need help setting up my email in lightroom. For some reason it's not connecting.

    Try posting in the Lightroom forum.  People there are more tuned in to the detail working of the application:
    http://forums.adobe.com/community/lightroom?view=discussions

  • Finite state machine using jsf ?

    I am building an online payment module and would like to implement it using a finite state machine. I am hoping that someone may give us advice on how to build it with jsf.
    Firstly, I am just beginning with jsf.
    Here is the example: Let's say that in the module there are 7 possible states that the user may be in, each represented by a jsp. I cannot decide where to manage state transitions. One option is to change states in the backer bean of every state, but that is dispersing transition logic across all my backer beans. The other option I can see is to have one single actionListener and have all action events pass through the 'processAction' method, keeping all the state management logic in one place.
    Please comment on either of these two approaches...or any alternatives :)
    Thanks in advance !
    Mark

    Sounds like a state machine in combination with a decorator on the ViewHandler might do the trick.
    Off the top of my head I'd suggest creating a managed bean in session scope that keeps track of the state in the user's session (the state machine). Check the bean from the ViewHandler decorator when a page is requested and direct the user to the correct page if they are trying to navigate to a page that conflicts with what is allowed for their current state.
    Your actionlisteners or action methods could change the user's state in the session as they process their actions.
    http://forum.java.sun.com/thread.jsp?forum=427&thread=502322
    The above thread discusses the use of a decorator to control navigation for authentication purposes, but it should be adaptable to this use.
    Is that plausable or am I smoking crack? :-)
    -jeff howard

  • I have a Steinberg MI4 and a Roland Fantom X7, and am trying to use my Fantom in Logic to record audio. Need help setting it all up using MIDI cables. Please help !

    I have a Steinberg MI4 and a Roland Fantom X7, and am trying to use my Fantom in Logic to record audio. Need help setting it all up using MIDI cables. Please help !

    Encryption wouldn't matter except for Wifi.
    While 10.2 might help, there's not much you can do on the Internet these days with less than 10.4.11
    Tiger Requirements...
    To use Mac OS X 10.4 Tiger, your Macintosh needs:
        * A PowerPC G3, G4, or G5 processor
        * Built-in FireWire
        * At least 256 MB of RAM (I recommend 1GB minimum)
        * DVD drive (DVD-ROM), Combo (CD-RW/DVD-ROM) or SuperDrive (DVD-R) for installation
        * At least 3 GB of free disk space; 4 GB if you install the XCode 2 Developer Tools  (I recommend 20GB minimum)
    http://support.apple.com/kb/HT1514
    http://www.ebay.com/sch/i.html?_nkw=mac+os+x+tiger+retail+10.4
    See Tom's, (Texas Mac Man), great info on where/how to find/get Tiger...
    https://discussions.apple.com/message/15305521#15305521
    Or Ali Brown's great info on where/how to find/get Tiger...
    http://discussions.apple.com/thread.jspa?messageID=10381710#10381710
    As far as Memory, that's sort of easy, find your eMac here...
    http://eshop.macsales.com/MyOWC/Models.cfm?Family=emac&sType=Memory
    As far as Hard Drive, it's not easy to replace the Internal drive, I'd maybe suggest an external Firewire drive to boot from...
    http://eshop.macsales.com/item/Other%20World%20Computing/MAU4S7500G16/

  • Need help setting up outlook mail on ipad2

    downloaded the outlook app, need help setting it up.

    Is it actually called Outlook, or is it called Outlook Mail Pro or Outlook Mail Complete or something like that? Those apps are actually by separate companies (ie, not Microsoft), and I don't personally have experience with them, but here are links to their support sites which should have the information you need (or an email address you can write to):
    Outlook Mail Pro: http://support.codebeforedawn.com/customer/portal/topics/38871-outlook-mail-pro
    Outlook Mail Complete: http://www.ikonicapps.com/outlook/
    hope that helps...
    Matt

  • Deperately need help setting up external midi devices

    I need help setting up external midi devices.....Motu828...Midi express...RolandXV3080....Motif rack.......HELP

    Theres not really much to setup. Assuming your synths are connected to the MIDI Express already..
    In Logic, make a new MIDI track. On the left hand side in the track inspector, among the parameters you'll see an option for MIDI Port and Channel. Just pick which port the track is going to, set the channel and device id and play (And be glad you never had to deal with setting up the old Environment window in Logic 5 and below).
    If you really wanna get into it and have all your MIDI ports named after the synth thats connected to it, open up Audio Midi Setup, create a device icon for each synth you have and draw the cables from each device to whatever port its connected to on the midi interface's icon.
    Then in Logic everytime you pick your MIDI port on your track, instead of MIDI Port 1, MIDI Port 2, etc.,
    it would be labelled XV-3080, Motif Rack, and so on.. I dont think theres anyway to do this within Logic itself (you can change the labels on your audio ins and outs, but not MIDI as far as I can recall)..
    If youre talking about having access to patch names and whatnot like Digital Performer and Cubase let you do, Logic doesnt use the xml patch lists everyone else does. The above steps are pretty much all there is to be done as far as MIDI.
    Heres my Audio Midi Setup window for reference.
    Now when I select MIDI Port 1 in Logic its named MWXT, port 2 is SR-16, etc..

Maybe you are looking for

  • 11.5.10.2

    Hi All, i want the detalis of the columns in Fnd_concurrent_processes . Thanks in advance.

  • HT6030 New messages still do not work after installing this update.

    Opening a new message, opens the new message window, however, it will not select a recipient and the window stops responding.

  • Error importing roles

    Hello there, I am trying to import Roles in CUP for Portal system and I have the following error ''ERROR Error occurred while importing roles. com.virsa.ae.configuration.ConfigurationException: java.rmi.RemoteException: Service call exception; nested

  • Question about the diff listeners in ADF

    Hi, I am using Jdev 11.1.2.3.0 I am getting confused with the diff listeners in adf. Please suggest me some good books for the below mentioned listener. setPropertyLister() SetActionListener() setPropertyActionListener() clientListener() ( what are c

  • W701 Lenovo SSD won't start, intermittent problem

    specs: I think of W701 as the model number, but Lenovo considers it to be 4323CTO It used to have a Lenovo 128 GB SSD as the C drive, with a 360 GB HD for the secondary drive. Now I've replaced the original SSD with a Samsung 512 GB SSD. Running Wind