Bruce Eckel - Thinking in Java - VendingMachine

Hello,
I am working through TIJ right now and have reached the Chapter with Enumerations. I try to do all of the exercises but I seem to be stuck at Exercise 10 (Vending Machine).
He basically shows the state design pattern and gives a Vending Machine as an example. The states are represented by an inner enumeration class and these in turn access static private variables of the Vending Machine. Because of this construction there can only be one VendingMachine. (Actually everything is static, so there is no instance of VendingMachine at all).
In the respective exercise he says use an EnumMap to have multiple instances of VendingMachine. (the exercise is on page 1047 of the Fourth Edition).
I have been thinking about this for a couple of hours now and I can't figure out the way he wants me to go. I would really appreciate a hint or two from someone who has the book. Unfortunately there is no Solution Guide available to the forth Ediiton so far.
Thank you very much.
Volkmar

fearme69,
(Never trust anyone who says "Trust me". Trust me on that.)
That sounds like an interesting problem, but, like quickmick, I don't really understand what you're trying to do, or which "bit" your stuck on.
Yeah, Post the exercise question (or maybe find a link to it), and post whatever you've tried.
Actually everything is static, so there is no
instance of VendingMachine at all. In the
respective exercise he says use an EnumMap to
have multiple instances of VendingMachine.and I just read the intro section of the EnumMAP Tiger API, and had a quick look at this EnumMap example
When you say "everything is static" I presume you mean that all class variables & methods are static... but that the class is not abstract... so it can actaully be instantiated, but it doesn't make a ship load of sense to do so...
Hmmm... Except look at the example above... it's not actually instantiating an AntStatus (or any constant values therein), so maybe you just do it the obvious way... suck it and see.
Other than that just forget it and move on... write it off to the fact that Bruce can afford a better class of drugs than us mere peasants.
keith.

Similar Messages

  • Thinking in Java  Bruce Eckel

    I am learning Java by the book Thinking in Java Bruce Eckel.There are solutions after every chapter.I need solutions of the tasks from third chapter and so on.If someone has it please let me know.

    So, in other words, you want help in stealing[i]
    the answers?
    Well, one should not steal. But I think it's very lame
    of a book to sell the answers to questions written in
    the book. Shame on the author :)
    /Kaj
    Its probably to encourage you to buy the book!

  • Static import from SE5 (Ex 16 on p. 91 in Thinking in Java Edn 4 by Eckel)

    The following line of code is underlined:
    import static net.mindview.util.Print.*;with this error displayed:
    static import declarations are not supported in -source 1.4
    (try -source 1.5 to enable static import declarations).
    My Path variable contains these:
    C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jre1.6.0\bin;D:\java\TIJ4\code
    D:\java\TIJ4\code is the root folder for net.mindview.util.Print.
    JRE1.6 and JDK1.6 are installed.
    I also have:
    i.e. a dot, in my CLASSPATH variable.
    This is from the 4th edn of Thinking in Java by Bruce Eckel. If you are or have been through this stuff I would really appreciate it if we could meet on Skype every now and then to talk about issues like the one described above.
    Thanks for your help,
    b

    Now same code is underlined:
    import static net.mindview.util.Print.*;but with this error message:
    package net.mindview.util does not exist
    However it is mapped like this:
    D:\java\TIJ4\code\net\mindview etc..
    So, I have put this in to the Path variable:
    D:\java\TIJ4\code because it is the root folder of net.mindview.util.
    Is there something else I should do? Is is ok to have a non C directory in the Path variable?
    Thanks for any help,
    B

  • Exercise 8, Ch Access Control from Thinking  in Java

    I am learning java using Bruce Eckel book "Thinking in Java" 4th edition and I got stuck on one exercise:
    .. create a class called ConnectionManager that manages a fixed array of Connection objects. The client programmer must not be able to explicitely cteate Connection objects, but can only get them via a static method in ConnectionManager. When the ConnectionManager runs out of objects, it returns a null reference."
    So, as I understand client programmer should be able to use Connection object meaning the class is public, but cannot create one. Creating Connection objects is granted only to ConnectionManager. How to permit creating objects only to an object of certain type?
    serezha.

    Hi Peter,
    the point to look at is the Product Availability Matrix under service.sap.com/pam
    There max NW 7.0 EHP1 is supported for the java platform.
    Only thing you could do is to open an OSS message to clarify if and when it will be supported.
    Best,
    Frank

  • Was Bruce Eckel wrong with that?

    <Thinking in Java> chapter 6 :
    "Even if you have a lot of classes in a program, only the main( ) for the class invoked on the command line will be called. (As long as main( ) is public, it doesn?t matter whether the class that it?s part of is public.) "
    But it seems it is not the case. When you invoke a class from command line, it seems it must be a public class.
    Was Bruce Eckel wrong with that?

    This worksclass MainTest {
         public static void main(String [] args) {
              System.out.println("Access modifier for the class is package");
    }Since no access modifier is specified, the class has 'package' access.

  • Class constructor is actually "static" method, as Bruce Eckel says?

    <Thinking in java> chapter 7 :
    Even though constructors are not polymorphic (they?re actually static methods, but the static declaration is implicit), it?s important ...
    Are constructors actually static methods? I do not think so. static method can only manipulate static members, but constructor can also deal with non-static members. In other words, constructor always associate with a object, while static method always associate with a class.
    Why Mr. Eckel says that constructors are static?

    From the JLS ?8.8.3
    A constructor is always invoked with respect to an object, so it makes no sense for a constructor to be static, so no they are not.
    Are constructors actually static methods?Constructor declarations are not members. Members are defined as the set fields, methods, nested classes and interfaces(JLS ?8). So they are not methods.

  • HT1338 i think my java is not working properly what do i do

    i think my java is not working properly what do i do

    Java 7 updated  for 10.7-10.8
    Released Feb 1, 2013,  fixes 50+ security flaws
    http://www.esecurityplanet.com/patches/oracle-responds-to-java-security-flaws-wi th-50-fixes.html
    Download and install
    https://www.java.com/en/download/faq/java_mac.xml
    For Java versions 6 and below OS X 10.5-10.6 machines
    Apple supplies their own version of Java. For Mac OS X 10.6 and below, use the Software Update feature available under the Apple menu to check that you have the most up-to-date version of Java 6 for your Mac.
    https://www.java.com/en/download/faq/java_6.xml
    Java SE 6 End of Public Updates
    After February 2013, Oracle will no longer post updates of Java SE 6 to its public download sites. We highly recommend downloading and installing Java 7.
    If your considering upgrading OS X from 10.6.8 to 10.8 via AppStore to run Java 7
    Be forewarned no PowerPC based programs or driver software will run any longer.
    Check here BEFORE you upgrade OS X!
    http://roaringapps.com/apps:table
    Alternatives if you must run Java 7
    If Apple disabled Java 6 in 10.6, and you can't upgrade OS X to 10.8, then your pretty much done with Java in OS X because Oracle won't issue updates for Java 6 anymore.
    However you can install Windows 7 and continue to use Java 7+ there until support for Windows 7 ends in 2020.
    Windows in BootCamp or Virtual Machine?
    If your on 10.6, I very highly recommend the free Virtualbox for the virtual machine software as it gets updates, VMFusion and Parallels have moved on with only 10.7+

  • Help with 'Thinking in Java' excercise

    Have been working through the excelent Thinking in Java book (free download from www.bruceeckel.com) but cant understand one of the excercises from chapter 6. The question is:-
    " Create two classes, A and B, with default constructors (empty argument lists) that announce themselves. Inherit a new class called C from A, and create a member of class B inside C. Do not create a constructor for C. Create an object of class C and observe the results."
    I'me OK with all this apart from the "and create a member of class B inside C", I dont understand what this means. Is member the same as object, in whitch case douse it mean create a object of class B in C?
    Ben

    Sounds like a private data member:
    public class A
        public static void main(String [] args)
            C c = new C();
        public A() { System.out.println("Created an A");
    class B
        public B() { System.out.println("Created a B");
    class C extends A
        private B b;

  • Thinking in Java

    I am wondering if there is anyplace where i can download code which is good OOP oriented, and that can help me in my transition to thinking in Java. I understand what objects are, just need a bit of help in turning it into code. A program perhaps that is a little larger than what is usually found in the tutorials.
    thanks,
    tony

    Lokk at Code Samples & Applications and BluePrints links on the left side of java.sun.com

  • Every thing is object?(thinking in java)

    every thing is object.(thinking in java)
    then int and float?
    Does java is a complete OO language

    Hi!
    it is nice question..
    int, float, double, char, ...all are data types as they are in C++.But in Java one can also find wrapper classes(Objects) for these all data types like Integer, Float, Double, etc..so by this one can treat "java as Fully Object Oriented Programming...isn't it.??

  • What do you think of Java 2 Micro Edition?

    Hi,
    I would like to know, if anyone used the J2ME, and if so, what do you think of it. I am thinking of designing a middleware for mobile devices such as PDA, and I would like to know your thoughts on it.
    Thanks
    Neil

    I haven't used it yet, I am reading about it. I am not sure if you have seen this link:
    http://java.sun.com/products/cldc/
    Good Luck.

  • Help java vendingMachine code runs doesn't work Why please help

    import java.util.*;
    public class Vend
         double costALL = 40.00;
         int invALL = 3;
         String nameALL = "ALLURE OF DARKNESS";
         double costJUD = 90.75;
         int invJUD = 2;
         String nameJUD = "JUDGMENT DRAGON ";
         double costCHA = 75.50;
         int invCHA = 3;
         String nameCHA = "CHARGE OF THE LIGHT BIRGADE";
         double costCRU = 399.99;
         int invCRU = 1;
         String nameCRU = "CRUSH CARD)";
         double costGORZ = 245.29;
         int invGORZ = 1;
         String nameGORZ = "GORZ THE EMISSARY OF DARKNESS";
         double costDAD = 220.00;
         int invDAD = 2;
         String nameDAD = "DARK ARMED DRAGON";
         double savedDeckpts = 100.00;
         double input = 0.00;
         double change = 0;
         int choice = 0;
         public static void main(String[] args)
              Vend machine = new Vend();
         public Vend()
              System.out.println(" Hello Duelist, my name is Yusie Fudo.This is the one and only Specific Rare Yu-Gi-Oh! card vending.Each card in this vending machine is sealed in a special card container.These cards are up to date with the currnet ban list and pack release's.");
              System.out.println(" in order to get cards, you will be asked to pay using your Deck Points, which are stored on your Acadmey Duel Disc");
              System.out.println("Please insert Deck Points equal to the card(s) you would like to purchase or just insert 1,703.87 Deck points");
              Scanner input = new Scanner(System.in);
              double insert = input.nextDouble();
              savedDeckpts = savedDeckpts + insert;
              change = insert - change;
              while(choice != 7 && insert > 0)
                   System.out.println(" You still have " + change + " Deck Points");
                   System.out.println("Press 1 if you would like the card ALLURE OF DARKNESS from the PhanTom of DarkNess booster pack(40.00 Dp)");
                   System.out.println("Press 2 if you would like the card JUDGMENT DRAGON from the Light Of DesTruction booster pack(90.75 Dp)");
                   System.out.println("Press 3 if you would like the card CHARGE OF THE LIGHT BIRGADE from The DuelistGeneSis booster pack(75.50 Dp)");
                   System.out.println("Press 4 if you would like the card CRUSH CARD from the limited edition GoLD series booster pack(399.99 Dp)");
                   System.out.println("Press 5 if you would like the card GORZ THE EMISSARY OF DARKNESS from the Dark LeGends booster pack(245.29 Dp)");
                   System.out.println("Press 6 if you would like the card DARK ARMED DRAGON from the PhanTom of DarkNess booster pack(220.00 Dp)");
                   System.out.println("Press 7 if you would like to have your Deck points added back to your Duel Disc");
                   System.out.println("Press 8 if you would like to check how many cards are left in the machine");
                   System.out.println("(*note you need exodius the ulitimate forbbiden one's card code inorder to use option 8)");
                   choice = input.nextInt();
                   if(choice == 1 && choice <= 8 && choice >= 1 && insert >= 40.00)
                        System.out.println("Congrats Duelist you have chosen to buy the card ALLURE OF DARKNESS from the PhanTom of DarkNess booster pack");
                        invALL = invALL - 1;
                        change = change - costALL;      
                   else if(insert < 40.00 && choice == 1)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                        if(choice == 2 && choice <= 8 && choice >= 1 && insert >= 90.75)
                        System.out.println("Congrats Duelist you have chosen to buy the card JUDGMENT DRAGON from the Light Of DesTruction booster pack");
                        invJUD = invJUD - 1;
                        change = change - costJUD;      
                   else if(insert < 40.00 && choice == 2)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                        if(choice == 3 && choice <= 8 && choice >= 1 && insert >= 75.50)
                        System.out.println("Congrats Duelist you have chosen to buy the card CHARGE OF THE LIGHT BIRGADE from The DuelistGeneSis booster pack");
                        invCHA = invCHA - 1;
                        change = change - costCHA;      
                   else if(insert < 40.00 && choice == 3)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                        if(choice == 4 && choice <= 8 && choice >= 1 && insert >= 399.99)
                        System.out.println("Congrats Duelist you have chosen to buy the card CRUSH CARD from the limited edition GoLD series booster pack");
                        invCRU = invCRU - 1;
                        change = change - costCRU;      
                   else if(insert < 40.00 && choice == 4)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                        if(choice == 5 && choice <= 8 && choice >= 1 && insert >= 245.29)
                        System.out.println("Congrats Duelist you have chosen to buy the card GORZ THE EMISSARY OF DARKNESS from the Dark LeGends booster pack");
                        invGORZ = invGORZ - 1;
                        change = change - costGORZ;      
                   else if(insert < 40.00 && choice == 5)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                        if(choice == 6 && choice <= 8 && choice >= 1 && insert >= 220.00)
                        System.out.println("Congrats Duelist you have chosen to buy the DARK ARMED DRAGON from the PhanTom of DarkNess booster pack");
                        invDAD = invDAD - 1;
                        change = change - costDAD;      
                   else if(insert < 40.00 && choice == 6)
                        System.out.println("not correct amount of Deck Points.Please chose another card(s)");
                   if(choice == 7 && choice <= 8 && choice >= 1 )
                        System.out.println(" You have chosen to have your Deck Points added back to your Duel Disc");
                        System.out.println("You have revceived " + change + " Deck Points back");
                        change = change * 0;
                   if(choice == 8 && choice <= 8 && choice >= 1)
                        System.out.println("You have selected to see how many of what cards are left");
                        password();
              public void password()
              System.out.println("Please input ExodiusCardCode at this time");
              Scanner pass = new Scanner(System.in);
              String password = pass.next();
              if(password.equals("blackout"))
                   System.out.println("There are " + invALL + "ALLURE OF DARKNESS ");
                   System.out.println("There are " + invJUD + "JUDGMENT DRAGON ");
                   System.out.println("There are " + invCHA + "CHARGE OF THE LIGHT BIRGADE ");
                   System.out.println("There are " + invCRU + "CRUSH CARD ");
                   System.out.println("There are " + invGORZ + "GORZ THE EMISSARY OF DARKNESS ");
                   System.out.println("There are " + invDAD + "DARK ARMED DRAGON ");
                   System.out.println("The machine has DP" + savedDeckpts + " Inside");
    }

    hi my name is exodiamaster3.14 my code runs but when it runs it tells me
    System.out.println(" Hello Duelist, my name is Yusie Fudo.This is the one and only Specific Rare Yu-Gi-Oh! card vending.Each card in this vending machine is sealed in a special card container.These cards are up to date with the currnet ban list and pack release's.");
              System.out.println(" in order to get cards, you will be asked to pay using your Deck Points, which are stored on your Acadmey Duel Disc");
              System.out.println("Please insert Deck Points equal to the card(s) you would like to purchase or just insert 1,703.87 Deck points");
    say i type in 500 it then gives me all my choices of what to buy. when you press 1-6 it just repeats it self on what you can chose.it does subtract the money but won't show that you bought it. and when you chose option 8 it does not show what is left in the machine. this is my problem please help b/c i am very stuck. thanks again.

  • What do you think of Java applets?

    What do you recommend for Java applets?

    georgemc wrote:
    DrLaszloJamf wrote:
    sabre150 wrote:
    What do you recommend for Java applets?A dustbin.
    http://forum.java.sun.com/thread.jspa?threadID=764962&start=0&tstart=0
    <drum-roll/>
    <cymbal-crash/>throws ThreadResurrectionExceptionWoops. It takes me a long time to set up my drum kit?
    Actually, I was looking at the OP's Recent Message list to see if his most recent post was related to an earlier one.

  • Any one who has read chap15 of Thinking in JAVA,2nd Ed. please take a look.

    I'm testing the RMI example in chap15.When I run the PerfectTime class I always get an error message(xuke is my computer's name,and I've already conncetted to the ISP and started the registry server and produced the stub&skeleton classes as the book said):
    java.security.AccessControlException: access denied (java.net.SocketPermission xuke resolve)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:267)
         at java.security.AccessController.checkPermission(AccessController.java:394)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:540)
         at java.lang.SecurityManager.checkConnect(SecurityManager.java:1037)
         at java.net.InetAddress.getAllByName0(InetAddress.java:554)
         at java.net.InetAddress.getAllByName0(InetAddress.java:535)
         at java.net.InetAddress.getByName(InetAddress.java:444)
         at java.net.Socket.<init>(Socket.java:95)
         at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:20)
         at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:115)
         at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:494)
         at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
         at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:169)
         at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
         at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
         at java.rmi.Naming.bind(Naming.java:106)
         at PerfectTime.main(PerfectTime.java:31)
    Exception in thread "main" Process terminated with exit code 1

    Use a policy file, in which you grant acees permissions, when starting your applicaiton:
    grant {
    permission java.net.SocketPermission "*:1024-65535", "connect,resolve";
    permission java.net.SocketPermission "*:80-65535", "connect,accept";
    Here you have more details:
    http://java.sun.com/docs/books/tutorial/rmi/running.html

  • How many of you think that Java 3............

    will be made so that it can still remain portable, but if the creator wants it, they can compile the .class file into a .exe, or something like that? I want to know because I want to create stand alone applications, so after I learn java if I should switch to C++.

    You could also just give people the JRE along with your java as current installable Java programs do.
    There are also many topics in the forums which discuss programs which can make an .exe from Java. The question has been asked so many times, that you will probably find many results on a search.
    I do agree that a simple thing from Sun would be good. If they could make some type of official installer that you could give to people which would look for the JRE and install one if not there along with your program so you could distribute it to people who are not too familiar with installing Java.

Maybe you are looking for

  • Problem in Grouping the Fields of a Report

    I want to make a report in which a particular field (say A) of a table (T1) is the field on which report is to be grouped above if a field B in T1 has value 'a' then I wish to print certain other fields with the field A when value of field B has valu

  • Apple LaserWriter 16/600 PS with Win 7 (64bit): Looking for driver software

    Hello, can anybody tell me where to find the driver software for the Apple LaserWriter 16/600 PS connected to my Windows PC running Windows 7 (64Bit). With Win XP there was no problem at all, the printer got connected via plug and play, whereas with

  • Iphone 4S - photoshop elements 9.0 is not recognizing my iphone as a camera

    iphone 4S - photoshop elements 9.0 is not recognizing my iphone as a camera - therefore I cannot download pictures from my iphone. Anyone have any ideas? I've done everything according to the apple website, including uninstalling and reinstalling itu

  • Crystal Reports 5 and Password

    Post Author: Avelina CA Forum: Crystal Reports Hello, I have an application wrote in VB with Access 2.0. In some pc's where I install it when I try to use a CR5 report ask me for the user id and password database, when I never have use password in th

  • PrE9 - Dvd scene buttons not saving image (from MPG)

    Hi All, New user to PrE9, I've used Premiere 6 pretty extensively in the past and just bought PrE9. Using PrE9 on Windows 7 Ultimate (64-bit).  All latests drivers/patches/etc. are installed. I've tried creating a Dvd made up of some videos I have la