java - Why wont my calculations show in my app? -
i trying make simple ballistic app calculates bullet drop , time target. have in place need it, when test , wait results doesn't seems calculations have in there. suggestions me?
package com.example.koryhershock.testapp; import android.app.activity; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class mainactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.content_main); button btn = (button)findviewbyid(r.id.button1); final edittext et1 = (edittext)findviewbyid(r.id.muzzlevelocity); final edittext et2 = (edittext)findviewbyid(r.id.targetrange); final textview time = (textview)findviewbyid(r.id.textview1); final textview bulletdrop = (textview)findviewbyid(r.id.textview2); btn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { int x = new integer(et1.gettext().tostring()); int y = new integer(et2.gettext().tostring()); double timetotarget = x / y; double grav = 4.9; double timesquared = timetotarget * timetotarget; double drop = grav * timesquared; time.settext("time target: " + timetotarget + " seconds"); bulletdrop.settext("bullet drop: " + drop + " meters"); } }); } }
ok, may problem here: double timetotarget = x / y; because x , y integer. example if x 150 , y equals 100 result of your's calculatian equals 1. try use next calculation: double timetotarget = (double)x / (double)y;
Comments
Post a Comment