Now I know I might not receive the help I'm looking for because Cemetech isn't about Android coding, but I know at least Kllrnohj works for Google so I thought I'd throw this question at ya Cemetech.

I'm creating a VERY simple application for android, for a game (Ogame).
Now I may add on to this application, but for now this is all I want it to do;

Code:

- The user Inputs their level,
     - If the user inputs < 5000...
          - It multiplies the number by 5 to get the max
          - It multiplies the number by .2 to get the min
     - If the user inputs 5000 < X < 24999
          - It multiplies the number by .2 to get the min
     - If the user inputs >25000
          - It just displays "You can attack anyone > 5000"

My question is; how do you use variables (Such as input = X) and then from there us that X in equations to create an output?
What you're asking seems to be a generic question about Java, and it isn't Android-specific.

To use a variable in Java, first decide the type of variable you want to create (int, double, char, String, boolean, etc.) You can declare variables in Java like this:

Code:
int Num1;
double Num2=3.4;
char Character='B';

This code declares Num1, an integer with no value, Num2, a double with a value of 3.4, and Character, a char with a value of 'B'. To use that variable, you can plug it into any expression and it will evaluate using your variable. For example:

Code:
//using variables from before
System.out.println("Value of a is "+a+" and value of b is "+b);
double c=b*2+1; //Multiply b by 2 and add 1

If statements (and if-else and if-else if-else) use boolean variables and expressions. Here is some code that checks if a number is less than 5:

Code:
int Number = 3;
if (Number<5) //Boolean expression
  System.out.println("Number is less than 5");
joshie75 wrote:

Code:

- The user Inputs their level,
     - If the user inputs < 5000...
          - It multiplies the number by 5 to get the max
          - It multiplies the number by .2 to get the min
     - If the user inputs 5000 < X < 24999
          - It multiplies the number by .2 to get the min
     - If the user inputs >25000
          - It just displays "You can attack anyone > 5000"


For some possible Java code that essentially does this, using standard, non-android specific routines:


Code:
int userlevel = (new Scanner(System.in)).nextInt(), min, max;
if(userlevel<5000) {
   max = userlevel*5;
   min = (int) 0.2*userlevel;
} else if(userlevel<25000) {
      min = (int) 0.2*userlevel;
} else { System.out.println("You can attack anyone > 5000"); }


And as Souvik said, this has nothing to do with Android-related questions yet, as you are essentially asking standard Java questions -- which is fine, once you build a foundation with these and then get comfortable with the Android API you can go on to build the latest and greatest Ogame-like game Smile
I'm not creating a game, just a simple app to tell you which levels you can attack in a game Smile Thanks though guys, I was thinking too much android, too little java, you guys rock Smile

EDIT!!: Okay, so I have the calculation parts down pat, but uhh...
How in the world do I take the input from the edittext and turn it into a variable?

If needed I can post my main.xml and my .java file so far.
I'm not an Android expert, but it seems like you would use the getText() method from the EditText class.
souvik1997 wrote:
I'm not an Android expert, but it seems like you would use the getText() method from the EditText class.

I think you're right
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement