OMGNinja
April 27th, 2010, 10:45 AM
Ok so I have the gas mileage calculator working relly nice in fact all the error handeling is working and i get the values form the text boxes but when I am trying to print out the results from the input it displays nothing prints out whats wrong with this?
here is the try catch block;
try{
if (command == OKCmd){
gInput = Integer.parseInt(gas.getString());
bMInput = Integer.parseInt(bm.getString());
eMInput = Integer.parseInt(em.getString());
boolean ok = true;
//error checking
//see if gas or ending mileage is 0
if(gInput == 0)
{
ok = false;
form.append("Gallons is 0");
}
if(eMInput == 0)
{
ok = false;
form.append("End Millage is 0");
}
//see if begning miles are larger than ending miles
if(bMInput >= eMInput)
{
ok = false;
form.append("End mileage less than begin mileage 12");
}
//see if any value is negative
if(gInput < 0)
{
ok = false;
form.append("Gallons is negative");
}
if(bMInput < 0)
{
ok = false;
form.append("Begning Miles is negative");
}
if(eMInput < 0)
{
ok = false;
form.append("Ending Miles is negative");
}
//gas mileage = (em - bm)/ gas;
if(ok = true){
form.append("The Amount of Gas used is " + (eMInput - bMInput) / gInput);
}
}
}catch(Exception ex){
}
here is the whole thing if that helps;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
public class Gas extends MIDlet implements CommandListener {
//gas mileage = (em - bm)/ gas;
TextField gas; //gas in gallons
TextField bm; //begingin mileage
TextField em; //ending mileage
private int gInput;
private int bMInput;
private int eMInput;
private Form form;
private Command quit;
private Command OKCmd;
public Gas(){
gas = new TextField("Gas in Gallons:", "", 10, TextField.ANY);
bm = new TextField("Begining Mileage :", "", 10, TextField.ANY);
em = new TextField("Ending Mileage :", "", 10, TextField.ANY);
form = new Form("Gas Milages");
form.setCommandListener(this);
quit = new Command("Quit", Command.SCREEN, 1);
form.addCommand(quit);
OKCmd = new Command("OK", Command.SCREEN, 1);
form.addCommand(OKCmd);
form.append(gas);
form.append(bm);
form.append(em);
}
protected void startApp() throws MIDletStateChangeException{
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp(){
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException{
}
// Handle Events generated by Commands
public void commandAction(Command command, Displayable displayable){
try{
if (command == OKCmd){
gInput = Integer.parseInt(gas.getString());
bMInput = Integer.parseInt(bm.getString());
eMInput = Integer.parseInt(em.getString());
boolean ok = true;
//error checking
//see if gas or ending mileage is 0
if(gInput == 0)
{
ok = false;
form.append("Gallons is 0");
}
if(eMInput == 0)
{
ok = false;
form.append("End Millage is 0");
}
//see if begning miles are larger than ending miles
if(bMInput >= eMInput)
{
ok = false;
form.append("End mileage less than begin mileage 12");
}
//see if any value is negative
if(gInput < 0)
{
ok = false;
form.append("Gallons is negative");
}
if(bMInput < 0)
{
ok = false;
form.append("Begning Miles is negative");
}
if(eMInput < 0)
{
ok = false;
form.append("Ending Miles is negative");
}
//gas mileage = (em - bm)/ gas;
if(ok = true){
form.append("The Amount of Gas used is " + (eMInput - bMInput) / gInput);
}
}
}catch(Exception ex){
}
try
{
if (command == quit)
{
destroyApp(true);
notifyDestroyed();
}
}
catch (MIDletStateChangeException me){
}
}
}
here is the try catch block;
try{
if (command == OKCmd){
gInput = Integer.parseInt(gas.getString());
bMInput = Integer.parseInt(bm.getString());
eMInput = Integer.parseInt(em.getString());
boolean ok = true;
//error checking
//see if gas or ending mileage is 0
if(gInput == 0)
{
ok = false;
form.append("Gallons is 0");
}
if(eMInput == 0)
{
ok = false;
form.append("End Millage is 0");
}
//see if begning miles are larger than ending miles
if(bMInput >= eMInput)
{
ok = false;
form.append("End mileage less than begin mileage 12");
}
//see if any value is negative
if(gInput < 0)
{
ok = false;
form.append("Gallons is negative");
}
if(bMInput < 0)
{
ok = false;
form.append("Begning Miles is negative");
}
if(eMInput < 0)
{
ok = false;
form.append("Ending Miles is negative");
}
//gas mileage = (em - bm)/ gas;
if(ok = true){
form.append("The Amount of Gas used is " + (eMInput - bMInput) / gInput);
}
}
}catch(Exception ex){
}
here is the whole thing if that helps;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
public class Gas extends MIDlet implements CommandListener {
//gas mileage = (em - bm)/ gas;
TextField gas; //gas in gallons
TextField bm; //begingin mileage
TextField em; //ending mileage
private int gInput;
private int bMInput;
private int eMInput;
private Form form;
private Command quit;
private Command OKCmd;
public Gas(){
gas = new TextField("Gas in Gallons:", "", 10, TextField.ANY);
bm = new TextField("Begining Mileage :", "", 10, TextField.ANY);
em = new TextField("Ending Mileage :", "", 10, TextField.ANY);
form = new Form("Gas Milages");
form.setCommandListener(this);
quit = new Command("Quit", Command.SCREEN, 1);
form.addCommand(quit);
OKCmd = new Command("OK", Command.SCREEN, 1);
form.addCommand(OKCmd);
form.append(gas);
form.append(bm);
form.append(em);
}
protected void startApp() throws MIDletStateChangeException{
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp(){
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException{
}
// Handle Events generated by Commands
public void commandAction(Command command, Displayable displayable){
try{
if (command == OKCmd){
gInput = Integer.parseInt(gas.getString());
bMInput = Integer.parseInt(bm.getString());
eMInput = Integer.parseInt(em.getString());
boolean ok = true;
//error checking
//see if gas or ending mileage is 0
if(gInput == 0)
{
ok = false;
form.append("Gallons is 0");
}
if(eMInput == 0)
{
ok = false;
form.append("End Millage is 0");
}
//see if begning miles are larger than ending miles
if(bMInput >= eMInput)
{
ok = false;
form.append("End mileage less than begin mileage 12");
}
//see if any value is negative
if(gInput < 0)
{
ok = false;
form.append("Gallons is negative");
}
if(bMInput < 0)
{
ok = false;
form.append("Begning Miles is negative");
}
if(eMInput < 0)
{
ok = false;
form.append("Ending Miles is negative");
}
//gas mileage = (em - bm)/ gas;
if(ok = true){
form.append("The Amount of Gas used is " + (eMInput - bMInput) / gInput);
}
}
}catch(Exception ex){
}
try
{
if (command == quit)
{
destroyApp(true);
notifyDestroyed();
}
}
catch (MIDletStateChangeException me){
}
}
}