commit 33777ee43fe5c43c53643241aba2d7673a1bc4ef Author: Erik C. Thauvin Date: Fri Oct 1 01:19:12 2004 +0000 Initial import. diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..f7b02b6 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.cvsignore b/.cvsignore new file mode 100755 index 0000000..6327664 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,3 @@ +build +verified +deployed \ No newline at end of file diff --git a/.eclipseme b/.eclipseme new file mode 100755 index 0000000..9a667a8 --- /dev/null +++ b/.eclipseme @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.project b/.project new file mode 100755 index 0000000..1d9a6a4 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + TipME + + + + + + org.eclipse.jdt.core.javabuilder + + + + + eclipseme.core.preverifier + + + + + + org.eclipse.jdt.core.javanature + eclipseme.core.nature + + diff --git a/TipME.jad b/TipME.jad new file mode 100755 index 0000000..2f4bdc6 --- /dev/null +++ b/TipME.jad @@ -0,0 +1,10 @@ +MIDlet-1: TipME,/tipme.png,net.thauvin.j2me.tipme.TipME +MIDlet-Jar-URL: TipME.jar +MIDlet-Icon: /tipme.png +MicroEdition-Configuration: CLDC-1.0 +MIDlet-Version: 0.1.0 +MIDlet-Vendor: Erik C. Thauvin +MIDlet-Name: TipME +MIDlet-Description: TipME +MIDlet-Info-URL: http://www.thauvin.net/erik/j2me/ +MicroEdition-Profile: MIDP-2.0 diff --git a/build.xml b/build.xml new file mode 100755 index 0000000..b0bf93a --- /dev/null +++ b/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmd.bat b/cmd.bat new file mode 100755 index 0000000..1b04a7b --- /dev/null +++ b/cmd.bat @@ -0,0 +1,2 @@ +@echo off +cmd.exe \ No newline at end of file diff --git a/res/tipme.png b/res/tipme.png new file mode 100755 index 0000000..e2be0d5 Binary files /dev/null and b/res/tipme.png differ diff --git a/src/net/thauvin/j2me/tipme/MainScreen.java b/src/net/thauvin/j2me/tipme/MainScreen.java new file mode 100755 index 0000000..aeefa84 --- /dev/null +++ b/src/net/thauvin/j2me/tipme/MainScreen.java @@ -0,0 +1,95 @@ +/* + * @(#)MainScreen.java + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + * + */ +package net.thauvin.j2me.tipme; + +import javax.microedition.lcdui.ChoiceGroup; +import javax.microedition.lcdui.Form; +import javax.microedition.lcdui.TextField; + + +/** + * The MainScreen class implements a form used to gather the data needed to calculate the tip. + * + * @author Erik C. Thauvin + * @version $Revision$, $Date$ + * + * @created September 16, 2004 + * @since 1.0 + */ +public class MainScreen extends Form +{ + /** + * The tip rate popup. + */ + protected /* final */ ChoiceGroup tipPopup; + + /** + * The tax total field. + */ + protected /* final */ TextField taxFld; + + /** + * The bill total field. + */ + protected /* final */ TextField totalFld; + + /** + * Creates a new MainScreen object. + * + * @param midlet The MIDlet instance. + */ + public MainScreen(TipME midlet) + { + super(midlet.appName); + + taxFld = new TextField("Tax Amount: ", midlet.taxAmount, 10, TextField.DECIMAL); + totalFld = new TextField("Bill Amount: ", midlet.totalAmount, 10, TextField.DECIMAL); + tipPopup = + new ChoiceGroup("Tip %:", ChoiceGroup.POPUP, new String[] { "5", "10", "15", "20", "25", "30" }, null); + tipPopup.setSelectedIndex(2, true); + append(taxFld); + append(totalFld); + append(tipPopup); + + addCommand(midlet.aboutCommand); + addCommand(midlet.clearCommand); + addCommand(midlet.exitCommand); + addCommand(midlet.calcCommand); + + setCommandListener(midlet); + } +} diff --git a/src/net/thauvin/j2me/tipme/ResultScreen.java b/src/net/thauvin/j2me/tipme/ResultScreen.java new file mode 100755 index 0000000..05a6afd --- /dev/null +++ b/src/net/thauvin/j2me/tipme/ResultScreen.java @@ -0,0 +1,93 @@ +/* + * @(#)ResultScreen.java + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + * + */ +package net.thauvin.j2me.tipme; + +import javax.microedition.lcdui.Form; +import javax.microedition.lcdui.StringItem; + + +/** + * The ResultScreen class inplements the form used to display the results. + * + * @author Erik C. Thauvin + * @version $Revision$, $Date$ + * + * @created September 16, 2004 + * @since 1.0 + */ +public class ResultScreen extends Form +{ + /** + * The subtotal item. + */ + protected /* final */ StringItem subtotalItem = new StringItem("Subtotal:", "\n"); + + /** + * The tax item. + */ + protected /* final */ StringItem taxItem = new StringItem("Tax:", "\n"); + + /** + * The tip item. + */ + protected /* final */ StringItem tipItem = new StringItem("Tip:", "\n"); + + /** + * The total item. + */ + protected /* final */ StringItem totalItem = new StringItem("Total:", ""); + + /** + * Creates a new ResultForm object. + * + * @param midlet The MIDlet instance. + */ + public ResultScreen(TipME midlet) + { + super(midlet.appName); + + append(subtotalItem); + append(taxItem); + append(tipItem); + append(totalItem); + + addCommand(midlet.exitCommand); + addCommand(midlet.backCommand); + + setCommandListener(midlet); + } +} diff --git a/src/net/thauvin/j2me/tipme/TipME.java b/src/net/thauvin/j2me/tipme/TipME.java new file mode 100755 index 0000000..f43a695 --- /dev/null +++ b/src/net/thauvin/j2me/tipme/TipME.java @@ -0,0 +1,336 @@ +/* + * @(#)TipME.java + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + * + */ +package net.thauvin.j2me.tipme; + +import javax.microedition.lcdui.*; +import javax.microedition.midlet.MIDlet; +import javax.microedition.midlet.MIDletStateChangeException; + + +/** + * The TipME class implements a simple Tip calculator. + * + * @author Erik C. Thauvin + * @version $Revision$, $Date$ + * + * @created September 16, 2004 + * @since 1.0 + */ +public class TipME extends MIDlet implements CommandListener +{ + /** + * The application name. + */ + protected /* final */ String appName = "TipME"; + + /** + * The application version. + */ + protected /* final */ String appVersion = "0.1"; + + /** + * The About command. + */ + protected /* final */ Command aboutCommand = new Command("About", Command.SCREEN, 4); + + /** + * The Back command. + */ + protected /* final */ Command backCommand = new Command("Back", Command.BACK, 2); + + /** + * The Calculate command. + */ + protected /* final */ Command calcCommand = new Command("Calculate", Command.SCREEN, 2); + + /** + * The Clear command. + */ + protected /* final */ Command clearCommand = new Command("Clear", Command.SCREEN, 3); + + /** + * The Exit command. + */ + protected /* final */ Command exitCommand = new Command("Exit", Command.EXIT, 2); + + /** + * The tax amount. + */ + protected String taxAmount; + + /** + * The tip rate. + */ + protected String tipRate; + + /** + * The total amount. + */ + protected String totalAmount; + private Display display; + + /** + * DOCUMENT ME! + */ + private /* final */ MainScreen mainScreen; + + /** + * DOCUMENT ME! + */ + private /* final */ ResultScreen resultScreen; + private int billTotal = 0; + private int subTotal = 0; + private int taxTotal = 0; + private int tipTotal = 0; + + /** + * Creates a new TipME object. + */ + public TipME() + { + super(); + + mainScreen = new MainScreen(this); + resultScreen = new ResultScreen(this); + } + + /** + * Performs a command. + * + * @param c The command action. + * @param d The diplayable screen. + */ + public void commandAction(Command c, Displayable d) + { + if (c == exitCommand) + { + exit(); + } + else if (c == clearCommand) + { + mainScreen.taxFld.setString(""); + mainScreen.totalFld.setString(""); + display.setCurrentItem(mainScreen.taxFld); + } + else if (c == aboutCommand) + { + /* final */ Alert about = + new Alert("About " + appName, + appName + ' ' + appVersion + "\nCopyright 2004\nErik C. Thauvin\nerik@thauvin.net", null, + AlertType.INFO); + about.setTimeout(Alert.FOREVER); + display.setCurrent(about, d); + } + else if (c == calcCommand) + { + totalAmount = mainScreen.totalFld.getString(); + taxAmount = mainScreen.taxFld.getString(); + tipRate = mainScreen.tipPopup.getString(mainScreen.tipPopup.getSelectedIndex()); + + if ((totalAmount.length() == 0) || (totalAmount.charAt(0) == '0')) + { + error("Please specify a valid bill amount.", d); + } + else + { + calcTip(); + resultScreen.subtotalItem.setText(getSubTotalAmount() + '\n'); + resultScreen.taxItem.setText(getTaxAmount() + '\n'); + resultScreen.tipItem.setText(getTipAmount() + " (" + tipRate + "%)\n"); + resultScreen.totalItem.setText(getBillAmount()); + display.setCurrent(resultScreen); + display.setCurrentItem(resultScreen.tipItem); + } + } + else if (c == backCommand) + { + display.setCurrent(mainScreen); + display.setCurrentItem(mainScreen.tipPopup); + } + } + + /** + * Returns to total bill amount after tip. + * + * @return The bill amount. + */ + protected String getBillAmount() + { + return parseStr(billTotal); + } + + /** + * Returns the subtotal amount after calculation. + * + * @return The subtotal amount. + */ + protected String getSubTotalAmount() + { + return parseStr(subTotal); + } + + /** + * Returns the tax amount after calculation. + * + * @return the tax amount. + */ + protected String getTaxAmount() + { + if (taxTotal > 0) + { + return parseStr(taxTotal); + } + + return "0.00"; + } + + /** + * Returns the tip amount after calculation. + * + * @return The tip amount. + */ + protected String getTipAmount() + { + return parseStr(tipTotal); + } + + /** + * @see javax.microedition.midlet.MIDlet#destroyApp(boolean) + */ + protected void destroyApp(boolean b) + throws MIDletStateChangeException + { + notifyDestroyed(); + } + + /** + * @see javax.microedition.midlet.MIDlet#pauseApp() + */ + protected void pauseApp() + { + ; + } + + /** + * @see javax.microedition.midlet.MIDlet#startApp() + */ + protected void startApp() + throws MIDletStateChangeException + { + display = Display.getDisplay(this); + display.setCurrent(mainScreen); + } + + // Calulates the tip. + private void calcTip() + { + taxTotal = parseInt(taxAmount); + subTotal = parseInt(totalAmount) - taxTotal; + tipTotal = (subTotal * Integer.parseInt(tipRate)) / 100; + billTotal = subTotal + tipTotal + taxTotal; + + if ((billTotal % 100) < 50) + { + while ((billTotal % 100) != 0) + { + tipTotal--; + billTotal = subTotal + tipTotal + taxTotal; + } + } + else + { + while ((billTotal % 100) != 0) + { + tipTotal++; + billTotal = subTotal + tipTotal + taxTotal; + } + } + } + + // Displays an error dialog. + private void error(String msg, Displayable d) + { + /* final */ Alert error = new Alert("Error", msg, null, AlertType.ERROR); + error.setTimeout(Alert.FOREVER); + display.setCurrent(error, d); + } + + // Exits the application. + private void exit() + { + try + { + destroyApp(false); + } + catch (MIDletStateChangeException e) + { + ; // Do nothing + } + } + + // Parses a given string to an int, the decimal point is removed. + private int parseInt(String s) + { + /* final */ int dec = s.lastIndexOf('.'); + int len = s.length(); + + if (dec == -1) + { + return Integer.parseInt(s + "00"); + } + else if (dec == (len - 1)) + { + return Integer.parseInt(s.substring(0, dec) + "00"); + } + else if (dec == (len - 2)) + { + return Integer.parseInt(s.substring(0, dec) + s.substring(dec + 1) + '0'); + } + else + { + return Integer.parseInt(s.substring(0, dec) + s.substring(dec + 1, dec + 3)); + } + } + + // Parse the given into to a string, the decimal point is added. + private String parseStr(int i) + { + /* final */ String s = String.valueOf(i); + + return s.substring(0, s.length() - 2) + '.' + s.substring(s.length() - 2); + } +} diff --git a/tipme.gif b/tipme.gif new file mode 100755 index 0000000..97cde43 Binary files /dev/null and b/tipme.gif differ diff --git a/tipme.wml b/tipme.wml new file mode 100755 index 0000000..dab6113 --- /dev/null +++ b/tipme.wml @@ -0,0 +1,16 @@ + + + + + +

+ TipME 0.1 (5Kb)
+ Download Jad
+ Download Jar
+

+
+