Count until zero - android

I am beginner and trying to write some calculations with App Inventor 2.
I am trying to write a code to calculate Net present value.
The formula of NPV = - investment + CF/(1+i)power up by years of investment, which means if years of investment are > 1 the second part of formula will repeat until it reached the number of years.
I successfully code the formula for one year that works correct, but have problem with the "repeating" the second part powered by number of years.
I tried to declare years as variable to use it as powering number but think something is wrong with it.
In my opinion I need to split the powering number somewhere to memory and then increase it by 1 until the required number. However have no clue how to do it.
Can anyone help?
Screenshot of the blocks

Following the calculation from the NPB Calculator,
this is converted into blocks the following
Note: for a better clarity and to avoid such long calculation blocks as in your screenshot, I used External Inputs instead of Inline Inputs, which is the default. You can switch that from the context menu after doing a right mouse click onto one of the calculation blocks.
EDIT: screenshot updated for changing cashflows using a list.See also
How to work with Lists by Saj and
How to work with Lists and Lists of lists (pdf) by appinventor.org

Related

Kotlin , code enters if statemant even when condition is false

I'm really confused here ... looks like a really silly mistake but I don't know what's happening. Here's little snippet of my code :
if (tempDeltaDeviation > standardDeltaDeviation) {
Log.e(TAG, "handleMessage: plus $tempDeltaDeviation : $standardDeltaDeviation")
scaleUpAnimation(deltaAnimStep, "Delta", binding.deltaImg)
}
Really basic stuff, right ? Well checking the logs I can see :
handleMessage: plus 1.57756888292539E14 : 7.8364593205657E13
Dunno but last time I was checking 1 was much smaller than 7 so why app enters if statement ?
1.57756888292539E14 is in fact larger than 7.8364593205657E13.
These numbers are represented in scientific notation which is used to work with very small or very large numbers. 1.57756888292539E14 means: 1.57756888292539 * 10^14. By increasing the number after E by one we actually increase the resulting number 10 times. By increasing it by 6, we increase the resulting number million times (10^6 = 1000000).
Making things simple, your numbers are really:
157756888292539 (1.57756888292539 * 100000000000000)
78364593205657 (7.8364593205657 * 10000000000000)
As you can see, the first number is actually bigger.

Generate only not generated random numbers in a certain range android studio? [duplicate]

This question already has answers here:
How to generate a random permutation in Java?
(3 answers)
Closed 1 year ago.
Hi in my Android application I need to generate all numbers(not together but when I call the function say generateAnyRandom()) in a certain range.
For example, say my range is 1 to 1000 and when I call generateAnyRandom() it should give a random number within the range. In this way, if again I call the function it should give me another random number which must be different from the existing one. And more importantly, I will call the function maximum of 1000 times as the range is 1 to 1000 and it should give me always a number that was not generated yet. That means I want to generate all the numbers from 1 to 1000 not in one shot but only when I call it.
Please help. It is a critical question for me?
This is a known problem.
Put the numbers 1..1000 into some container; an array, list, or whatever.
Shuffle the contents of the container into random order.
Retrieve the numbers from the shuffled container in order.
As you correctly point out, this will only work 1000 times before the container is exhausted. You should pick a type of container that allows you to easily perform a random shuffle. Check the various built-in functions for the different container types.

Q: SQLite calculation on android

I am currently working on android application that can track income/outcome of a budget. In one of my database is named Transaction consist of:
Amount
Type (income/outcome)
Date
since this is my first application I'm not really confident with my code, especially in the database. And now I'm making a trigger that can calculate percentage of outcome in a month. Can you check it,if my code is right or not, or not efficient. Here is tiny part of my Trigger code.
In my code I want to calculate percentage of total outcome from the first of a month until the current date .
"CREATE TRIGGER Calc"+
"AFTER INSERT"+
"ON" +transaction+
"FOR EACH ROW" +
"WHEN (SELET * FROM amount.transaction
WHERE (strftime ('%d','now') - strftime('%d','start of month'))
HAVING SUM(amount.transaction WHERE type.transaction IS "outcome") /SUM(amount.transaction WHERE type.transaction IS "income") * 0.01 )"
is it select * from amount.transaction needed? so the code can be much simpler?
0.01 there is 100%
sorry its so messed up since I'm just start in making android and I'm not really well with database. If you have any suggestion please tell me.
Thanks before
I agree with commentors, I don't think you need to use triggers ahead of on-the-fly SELECT statements.
You do need to know that quotations " are literal and when concatenating strings, you need to manually add spaces.

Android app calculate until 2^28

Hello everyone i'm trying to figure up why does my calculate app cannot work with numbers bigger then 2^28.
The next num after the biggest is the smallest. Now I understand that the problem is with the definition of my variables but its an integer and at c++ integer variables are 8 bits numbrer that allows me to calculate 2^32.. so how do I get ridd of this bug?
Hey I solved the problem. If you want to do an app that calculates extreme numbers change the variables you use to "double" variable that can calc numbers until 2^64

First Android app: pictures not refreshing

im very new to Java and Android Programming and am currently trying to write my first Android App.
The App shows 3 Dices, and depending on what combination the dices Show, the App says "yes" "no" or "ultra yes".
My Problem is, when hitting the Button to Re-Roll, sometimes the Pictures of single Dices do not get Updated and then the Answer is wrong (i hope it is somehow clear what i mean)
In this Screenshots you can see what i mean. The first Picture everything is correct (2 dices showing the same numbers means a "No"). Then i hit the Reroll button again and somehow the Pictures didn't get updated.. This occures Randomly, sometimes it works correct 10+ times.
http://image-upload.de/image/gbYhNq/ce3ef664bd.png
http://image-upload.de/image/j8jSTv/97ed7d0f7e.png
The Code of the APP:
http://pastebin.com/360DwFcg
thanks in Advance from a newbie ;)
Your random dice number generation is wrong. It creates a random number from one to seven.
This is probably a long shot, but since your answer is "ultra yes", then all three dice are the same value. So maybe you just got a lucky 7, 7, 7, in which case no images are updated. Just change your random generation to
(int) (Math.random() * 6 + 1)

Categories

Resources