/** * A DonutServer knows one behaviour: calcDonutBudgetInteractively. * * Skills emphasized: (a) decomposing problems into sub-functions, * (b) using println and Scanner class; (c) integer arithmetic. * * USE ONLY int FOR THIS PROGRAM -- NO double ALLOWED! (point (c)) * * @author Ian Barland * @version 2006.Sep.08 */ class DonutServer { // Any named-constants should go here (using 'final', and name in ALL_CAPS). /** * Ask about donuts desired, compute the price, * put that information into a String message, * and then display the message and return it. * * @return A nicely-worded message about the price of the requested number of donuts. */ String calcDonutBudgetInteractively() { System.out.println( "Delicious SugarBomb donuts are " + "..." ); int numDonuts = promptForInt( "How many would you like?" ); String consumerInfo = 999 + " donuts cost " + // Replace each 999 w/ 999 + " dollars and " + // some expression (they 999 + " cents."; // can incl. arithmetic). /* We use `consumerInfo' twice: we print it out interactively, * and we return it so other programs can use the info as needed * (to incorporate into a web page, or outgoing email, or a log file ...) */ System.out.println( consumerInfo ); // Note: println doesn't return a value. return consumerInfo; } /** * Given `msg', print it to the screen, get a response from the user, * and then return that response. * * @param msg The message to prompt to the console-screen. * @return The value read from the keyboard. */ int promptForInt( String msg ) { /* ... Print 'msg' to the screen. ... */ java.util.Scanner scan = new java.util.Scanner( System.in ); /* Now, ask a `scan' to read an int, and then just return that int. */ return 999; // Replace the stub 999 with something read by 'scan'. } }